/** * Public function that creates a single instance */ public static function getInstance() { if (!isset(self::$_instance)) { self::$_instance = new self(); } return self::$_instance; }
/** * Show page for printing all attached cards with selected text. */ private function print_card() { $id = fix_id($_REQUEST['transaction']); $manager = ShopTransactionsManager::getInstance(); $item_manager = ShopItemManager::getInstance(); $transaction_item_manager = ShopTransactionItemsManager::getInstance(); // get transaction with specified id $transaction = $manager->getSingleItem(array('id'), array('id' => $id)); // ensure transaction is a valid one if (!is_object($transaction)) { return; } // get items associated with transaction $transaction_items = $transaction_item_manager->getItems(array('item', 'description'), array('transaction' => $transaction->id)); if (count($transaction_items) == 0) { return; } $id_list = array(); $description_list = array(); foreach ($transaction_items as $item) { $id_list[] = $item->item; $description_list[$item->item] = $item->description; } // get unique id and gallery $shop_items = $item_manager->getItems(array('id', 'uid', 'gallery'), array('id' => $id_list)); if (count($shop_items) == 0) { return; } // prepare final list and only include items that are actually known cards $items = array(); foreach ($shop_items as $item) { if (!array_key_exists($item->uid, $this->text_position)) { continue; } $position = $this->text_position[$item->uid]; $description = unserialize($description_list[$item->id]); $data = array('text' => $description['text'], 'top' => $position[0] . '%', 'left' => $position[1] . '%', 'bottom' => $position[2] . '%', 'right' => $position[3] . '%', 'image' => gallery::getGroupImageById($item->gallery)); $items[] = $data; } // prepare template $template = new TemplateHandler('print_card.xml', $this->path . 'templates/'); if (count($items) > 0) { foreach ($items as $item) { $template->setLocalParams($item); $template->restoreXML(); $template->parse(); } } }
/** * Handle drawing list of items in transaction */ public function tag_TransactionItemList($tag_params, $children) { $manager = ShopTransactionItemsManager::getInstance(); $item_manager = ShopItemManager::getInstance(); $transaction_manager = ShopTransactionsManager::getInstance(); $currency_manager = ShopCurrenciesManager::getInstance(); $id = null; if (isset($tag_params['id'])) { // get id from tag params $id = fix_id($tag_params['id']); } else { if (isset($_REQUEST['id'])) { // get id from request params $id = fix_id($_REQUEST['id']); } } // if we don't have transaction Id, get out if (is_null($id)) { return; } $currency_id = $transaction_manager->getItemValue('currency', array('id' => $id)); $currency = $currency_manager->getItemValue('currency', array('id' => $currency_id)); // get items from database $items = array(); $raw_items = $manager->getItems($manager->getFieldNames(), array('transaction' => $id)); if (count($raw_items) > 0) { foreach ($raw_items as $item) { $items[$item->item] = array('id' => $item->id, 'price' => $item->price, 'tax' => $item->tax, 'amount' => $item->amount, 'description' => $item->description, 'uid' => '', 'name' => '', 'gallery' => '', 'manufacturer' => '', 'author' => '', 'views' => '', 'weight' => '', 'votes_up' => '', 'votes_down' => '', 'timestamp' => '', 'priority' => '', 'visible' => '', 'deleted' => '', 'total' => ($item->price + $item->price * ($item->tax / 100)) * $item->amount, 'currency' => $currency); } } // get the rest of item details from database $id_list = array_keys($items); $raw_items = $item_manager->getItems($item_manager->getFieldNames(), array('id' => $id_list)); if (count($raw_items) > 0) { foreach ($raw_items as $item) { $id = $item->id; $items[$id]['uid'] = $item->uid; $items[$id]['name'] = $item->name; $items[$id]['gallery'] = $item->gallery; $items[$id]['manufacturer'] = $item->manufacturer; $items[$id]['author'] = $item->author; $items[$id]['views'] = $item->views; $items[$id]['weight'] = $item->weight; $items[$id]['votes_up'] = $item->votes_up; $items[$id]['votes_down'] = $item->votes_down; $items[$id]['timestamp'] = $item->timestamp; $items[$id]['priority'] = $item->priority; $items[$id]['visible'] = $item->visible; $items[$id]['deleted'] = $item->deleted; } } if (count($items) > 0) { $template = $this->_parent->loadTemplate($tag_params, 'transaction_details_item.xml'); foreach ($items as $id => $params) { $template->setLocalParams($params); $template->restoreXML(); $template->parse(); } } }
/** * 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; }