예제 #1
0
 /**
  * Public function that creates a single instance
  */
 public static function getInstance()
 {
     if (!isset(self::$_instance)) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
예제 #2
0
 /**
  * Show details for specified transaction
  */
 private function showTransactionDetails()
 {
     $manager = ShopTransactionsManager::getInstance();
     $buyer_manager = ShopBuyersManager::getInstance();
     $address_manager = ShopDeliveryAddressManager::getInstance();
     $id = fix_id($_REQUEST['id']);
     $transaction = $manager->getSingleItem($manager->getFieldNames(), array('id' => $id));
     $buyer = $buyer_manager->getSingleItem($buyer_manager->getFieldNames(), array('id' => $transaction->buyer));
     $address = $address_manager->getSingleItem($address_manager->getFieldNames(), array('id' => $transaction->address));
     $full_address = "{$address->name}\n\n{$address->street}\n";
     $full_address .= "{$address->zip} {$address->city}\n";
     if (empty($address->state)) {
         $full_address .= $address->country;
     } else {
         $full_address .= "{$address->state}, {$address->country}";
     }
     $params = array('id' => $transaction->id, 'uid' => $transaction->uid, 'type' => $transaction->type, 'type_string' => '', 'status' => $transaction->status, 'currency' => $transaction->currency, 'handling' => $transaction->handling, 'shipping' => $transaction->shipping, 'timestamp' => $transaction->timestamp, 'delivery_method' => $transaction->delivery_method, 'remark' => $transaction->remark, 'total' => $transaction->total, 'first_name' => $buyer->first_name, 'last_name' => $buyer->last_name, 'email' => $buyer->email, 'address_name' => $address->name, 'address_street' => $address->street, 'address_city' => $address->city, 'address_zip' => $address->zip, 'address_state' => $address->state, 'address_country' => $address->country, 'full_address' => $full_address);
     $template = new TemplateHandler('transaction_details.xml', $this->path . 'templates/');
     // register tag handler
     $template->registerTagHandler('_item_list', $this, 'tag_TransactionItemList');
     $template->registerTagHandler('_transaction_status', $this, 'tag_TransactionStatus');
     $template->restoreXML();
     $template->setLocalParams($params);
     $template->parse();
 }
예제 #3
0
 /**
  * Handle transaction status change.
  *
  * @param object transaction
  */
 public function on_transaction_completed($transaction)
 {
     global $language;
     // get managers
     $buyer_manager = ShopBuyersManager::getInstance();
     $address_manager = ShopDeliveryAddressManager::getInstance();
     $transaction_items_manager = ShopTransactionItemsManager::getInstance();
     $item_manager = ShopItemManager::getInstance();
     // get transaction data
     $buyer = Transaction::get_buyer($transaction);
     $address = Transaction::get_address($transaction);
     $transaction_items = $transaction_items_manager->getItems($transaction_items_manager->getFieldNames(), array('transaction' => $transaction->id));
     $date_time = date('Y-m-d', strtotime($transaction->delivery_type));
     // prepare data
     $title = $buyer->first_name . ' ' . $buyer->last_name . ' - ' . $transaction->uid;
     if ($transaction->delivery_type == 'pickup') {
         $location = '';
         $color = 9;
     } else {
         $location = $address->street . ' ' . $address->street2 . ', ' . $address->zip . ' ' . $address->city . ', ' . $address->country;
         $color = 10;
     }
     $id_list = array();
     $name_by_id = array();
     $description = '';
     if (count($transaction_items) > 0) {
         foreach ($transaction_items as $item) {
             $id_list[] = $item->item;
         }
         $items = $item_manager->getItems(array('id', 'name'), array('id' => $id_list));
         foreach ($items as $item) {
             $name_by_id[$item->id] = $item->name;
         }
         foreach ($transaction_items as $item) {
             $description .= $name_by_id[$item->item][$language] . ' - ' . $item->amount . "\n";
         }
     }
     $post_data = array('start' => $date_time, 'end' => $date_time, 'title' => $title, 'location' => $location, 'description' => $description, 'color' => $color);
     $post_data = json_encode($post_data);
     $url = 'https://zapier.com/hooks/catch/133542/uti08e';
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_HTTPGET, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     $response = curl_exec($ch);
 }
예제 #4
0
파일: shop.php 프로젝트: tareqy/Caracal
 /**
  * Send email for transaction using specified template.
  *
  * @param object $transaction
  * @param string $template
  * @return boolean
  */
 private function sendTransactionMail($transaction, $template)
 {
     global $language;
     $result = false;
     // require contact form
     if (!class_exists('contact_form')) {
         return $result;
     }
     $email_address = null;
     $contact_form = contact_form::getInstance();
     // template replacement data
     $fields = array('transaction_id' => $transaction->id, 'transaction_uid' => $transaction->uid, 'status' => $transaction->status, 'handling' => $transaction->handling, 'shipping' => $transaction->shipping, 'total' => $transaction->total, 'weight' => $transaction->weight, 'payment_method' => $transaction->payment_method, 'delivery_method' => $transaction->delivery_method, 'remark' => $transaction->remark, 'token' => $transaction->token, 'timestamp' => $transaction->timestamp);
     $timestamp = strtotime($transaction->timestamp);
     $fields['date'] = date($this->getLanguageConstant('format_date_short'), $timestamp);
     $fields['time'] = date($this->getLanguageConstant('format_time_short'), $timestamp);
     // get currency
     $currency_manager = ShopCurrenciesManager::getInstance();
     $currency = $currency_manager->getSingleItem($currency_manager->getFieldNames(), array('id' => $transaction->currency));
     if (is_object($currency)) {
         $fields['currency'] = $currency->currency;
     }
     // add buyer information
     $buyer_manager = ShopBuyersManager::getInstance();
     $buyer = $buyer_manager->getSingleItem($buyer_manager->getFieldNames(), array('id' => $transaction->buyer));
     if (is_object($buyer)) {
         $fields['buyer_first_name'] = $buyer->first_name;
         $fields['buyer_last_name'] = $buyer->last_name;
         $fields['buyer_email'] = $buyer->email;
         $fields['buyer_uid'] = $buyer->uid;
         $email_address = $buyer->email;
     }
     // add system user information
     $user_manager = UserManager::getInstance();
     $user = $user_manager->getSingleItem($user_manager->getFieldNames(), array('id' => $transaction->system_user));
     if (is_object($user)) {
         $fields['user_name'] = $user->username;
         $fields['user_fullname'] = $user->fullname;
         $fields['user_email'] = $user->email;
         if (is_null($email_address) || empty($email_address)) {
             $email_address = $user->email;
         } else {
             if ($email_address != $user->email) {
                 $email_address = $email_address . ',' . $user->email;
             }
         }
     }
     // add buyer address
     $address_manager = ShopDeliveryAddressManager::getInstance();
     $address = $address_manager->getSingleItem($address_manager->getFieldNames(), array('id' => $transaction->address));
     if (is_object($address)) {
         $fields['address_name'] = $address->name;
         $fields['address_street'] = $address->street;
         $fields['address_street2'] = $address->street2;
         $fields['address_phone'] = $address->phone;
         $fields['address_city'] = $address->city;
         $fields['address_zip'] = $address->zip;
         $fields['address_state'] = $address->state;
         $fields['address_country'] = $address->country;
     }
     // create item table
     switch ($transaction->type) {
         case TransactionType::SHOPPING_CART:
             $item_manager = ShopTransactionItemsManager::getInstance();
             $items = $item_manager->getItems($item_manager->getFieldNames(), array('transaction' => $transaction->id));
             if (count($items) > 0) {
                 // create items table
                 $text_table = str_pad($this->getLanguageConstant('column_name'), 40);
                 $text_table .= str_pad($this->getLanguageConstant('column_price'), 8);
                 $text_table .= str_pad($this->getLanguageConstant('column_amount'), 6);
                 $text_table .= str_pad($this->getLanguageConstant('column_item_total'), 8);
                 $text_table .= "\n" . str_repeat('-', 40 + 8 + 6 + 8) . "\n";
                 $html_table = '<table border="0" cellspacing="5" cellpadding="0">';
                 $html_table .= '<thead><tr>';
                 $html_table .= '<td>' . $this->getLanguageConstant('column_name') . '</td>';
                 $html_table .= '<td>' . $this->getLanguageConstant('column_price') . '</td>';
                 $html_table .= '<td>' . $this->getLanguageConstant('column_amount') . '</td>';
                 $html_table .= '<td>' . $this->getLanguageConstant('column_item_total') . '</td>';
                 $html_table .= '</td></thead><tbody>';
                 foreach ($items as $item) {
                     // append item name with description
                     if (empty($data['description'])) {
                         $line = $item->name[$language] . ' (' . $item->description . ')';
                     } else {
                         $line = $item->name[$language];
                     }
                     $line = utf8_wordwrap($line, 40, "\n", true);
                     $line = mb_split("\n", $line);
                     // append other columns
                     $line[0] = $line[0] . str_pad($item->price, 8, ' ', STR_PAD_LEFT);
                     $line[0] = $line[0] . str_pad($item->amount, 6, ' ', STR_PAD_LEFT);
                     $line[0] = $line[0] . str_pad($item->total, 8, ' ', STR_PAD_LEFT);
                     // add this item to text table
                     $text_table .= implode("\n", $line) . "\n\n";
                     // form html row
                     $row = '<tr><td>' . $item->name[$language];
                     if (!empty($item->description)) {
                         $row .= ' <small>' . $item->description . '</small>';
                     }
                     $row .= '</td><td>' . $item->price . '</td>';
                     $row .= '<td>' . $item->amount . '</td>';
                     $row .= '<td>' . $item->total . '</td></tr>';
                     // update subtotal
                     $subtotal += $item->total;
                 }
                 // close text table
                 $text_table .= str_repeat('-', 40 + 8 + 6 + 8) . "\n";
                 $html_table .= '</tbody>';
                 // create totals
                 $text_table .= str_pad($this->getLanguageConstant('column_subtotal'), 15);
                 $text_table .= str_pad($subtotal, 10, ' ', STR_PAD_LEFT) . "\n";
                 $text_table .= str_pad($this->getLanguageConstant('column_shipping'), 15);
                 $text_table .= str_pad($transaction->shipping, 10, ' ', STR_PAD_LEFT) . "\n";
                 $text_table .= str_pad($this->getLanguageConstant('column_handling'), 15);
                 $text_table .= str_pad($transaction->handling, 10, ' ', STR_PAD_LEFT) . "\n";
                 $text_table .= str_repeat('-', 25);
                 $text_table .= str_pad($this->getLanguageConstant('column_total'), 15);
                 $text_table .= str_pad($transaction->total, 10, ' ', STR_PAD_LEFT) . "\n";
                 $html_table .= '<tfoot>';
                 $html_table .= '<tr><td colspan="2"></td><td>' . $this->getLanguageConstant('column_subtotal') . '</td>';
                 $html_table .= '<td>' . $subtotal . '</td></tr>';
                 $html_table .= '<tr><td colspan="2"></td><td>' . $this->getLanguageConstant('column_shipping') . '</td>';
                 $html_table .= '<td>' . $transaction->shipping . '</td></tr>';
                 $html_table .= '<tr><td colspan="2"></td><td>' . $this->getLanguageConstant('column_handling') . '</td>';
                 $html_table .= '<td>' . $transaction->handling . '</td></tr>';
                 $html_table .= '<tr><td colspan="2"></td><td><b>' . $this->getLanguageConstant('column_total') . '</b></td>';
                 $html_table .= '<td><b>' . $transaction->total . '</b></td></tr>';
                 $html_table .= '</tfoot>';
                 // close table
                 $html_table .= '</table>';
                 // add field
                 $fields['item_table'] = $text_table;
             }
             break;
         case TransactionType::SUBSCRIPTION:
             $plan_manager = ShopTransactionPlansManager::getInstance();
             $plan = $plan_manager->getSingleItem($plan_manager->getFieldNames(), array('transaction' => $transaction->id));
             // get payment method
             $plan_data = null;
             if (isset($this->payment_methods[$transaction->payment_method])) {
                 $payment_method = $this->payment_methods[$transaction->payment_method];
                 $plans = $payment_method->get_recurring_plans();
                 if (isset($plans[$plan->plan_name])) {
                     $plan_data = $plans[$plan->plan_name];
                 }
             }
             // populate fields with plan params
             if (is_object($plan) && !is_null($plan_data)) {
                 $fields['plan_text_id'] = $plan->plan_name;
                 $fields['plan_name'] = $plan_data['name'][$language];
             }
             break;
     }
     // we require email address for sending
     if (is_null($email_address) || empty($email_address)) {
         return $result;
     }
     // get mailer
     $mailer = $contact_form->getMailer();
     $sender = $contact_form->getSender();
     $template = $contact_form->getTemplate($template);
     // start creating message
     $mailer->start_message();
     $mailer->set_subject($template['subject']);
     $mailer->set_sender($sender['address'], $sender['name']);
     $mailer->add_recipient($email_address);
     $mailer->set_body($template['plain_body'], $template['html_body']);
     $mailer->set_variables($fields);
     // send email
     $mailer->send();
     return $result;
 }