コード例 #1
0
 /**
  * @param array $data
  * @return int
  */
 public function addCustomer($data)
 {
     $key_sql = '';
     if ($this->dcrypt->active) {
         $data = $this->dcrypt->encrypt_data($data, 'customers');
         $key_sql = ", key_id = '" . (int) $data['key_id'] . "'";
     }
     if (!(int) $data['customer_group_id']) {
         $data['customer_group_id'] = (int) $this->config->get('config_customer_group_id');
     }
     if (!isset($data['status'])) {
         if ($this->config->get('config_customer_email_activation')) {
             // if need to activate via email  - disable status
             $data['status'] = 0;
         } else {
             $data['status'] = 1;
         }
     }
     if (isset($data['approved'])) {
         $data['approved'] = (int) $data['approved'];
     } else {
         if (!$this->config->get('config_customer_approval')) {
             $data['approved'] = 1;
         }
     }
     // delete subscription accounts for given email
     $subscriber = $this->db->query("SELECT customer_id\n\t\t\t\t\t\t\t\t\t\tFROM " . $this->db->table("customers") . "\n\t\t\t\t\t\t\t\t\t\tWHERE LOWER(`email`) = LOWER('" . $this->db->escape($data['email']) . "')\n\t\t\t\t\t\t\t\t\t\t\tAND customer_group_id IN (SELECT customer_group_id\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  FROM " . $this->db->table('customer_groups') . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  WHERE `name` = 'Newsletter Subscribers')");
     foreach ($subscriber->rows as $row) {
         $this->db->query("DELETE FROM " . $this->db->table("customers") . " WHERE customer_id = '" . (int) $row['customer_id'] . "'");
         $this->db->query("DELETE FROM " . $this->db->table("addresses") . " WHERE customer_id = '" . (int) $row['customer_id'] . "'");
     }
     $sql = "INSERT INTO " . $this->db->table("customers") . "\n\t\t\t  SET\tstore_id = '" . (int) $this->config->get('config_store_id') . "',\n\t\t\t\t\tloginname = '" . $this->db->escape($data['loginname']) . "',\n\t\t\t\t\tfirstname = '" . $this->db->escape($data['firstname']) . "',\n\t\t\t\t\tlastname = '" . $this->db->escape($data['lastname']) . "',\n\t\t\t\t\temail = '" . $this->db->escape($data['email']) . "',\n\t\t\t\t\ttelephone = '" . $this->db->escape($data['telephone']) . "',\n\t\t\t\t\tfax = '" . $this->db->escape($data['fax']) . "',\n\t\t\t\t\tpassword = '******'password'])) . "',\n\t\t\t\t\tnewsletter = '" . (int) $data['newsletter'] . "',\n\t\t\t\t\tcustomer_group_id = '" . (int) $data['customer_group_id'] . "',\n\t\t\t\t\tapproved = '" . (int) $data['approved'] . "',\n\t\t\t\t\tstatus = '" . (int) $data['status'] . "'" . $key_sql . ",\n\t\t\t\t\tip = '" . $this->db->escape($data['ip']) . "',\n\t\t\t\t\tdate_added = NOW()";
     $this->db->query($sql);
     $customer_id = $this->db->getLastId();
     $key_sql = '';
     if ($this->dcrypt->active) {
         $data = $this->dcrypt->encrypt_data($data, 'addresses');
         $key_sql = ", key_id = '" . (int) $data['key_id'] . "'";
     }
     $this->db->query("INSERT INTO " . $this->db->table("addresses") . " \n      \t\t\t\t\t  SET \tcustomer_id = '" . (int) $customer_id . "', \n      \t\t\t\t\t  \t\tfirstname = '" . $this->db->escape($data['firstname']) . "', \n      \t\t\t\t\t  \t\tlastname = '" . $this->db->escape($data['lastname']) . "', \n      \t\t\t\t\t  \t\tcompany = '" . $this->db->escape($data['company']) . "', \n      \t\t\t\t\t  \t\taddress_1 = '" . $this->db->escape($data['address_1']) . "', \n      \t\t\t\t\t  \t\taddress_2 = '" . $this->db->escape($data['address_2']) . "', \n      \t\t\t\t\t  \t\tcity = '" . $this->db->escape($data['city']) . "', \n      \t\t\t\t\t  \t\tpostcode = '" . $this->db->escape($data['postcode']) . "', \n      \t\t\t\t\t  \t\tcountry_id = '" . (int) $data['country_id'] . "'" . $key_sql . ",\n      \t\t\t\t\t  \t\tzone_id = '" . (int) $data['zone_id'] . "'");
     $address_id = $this->db->getLastId();
     $this->db->query("UPDATE " . $this->db->table("customers") . " SET address_id = '" . (int) $address_id . "' WHERE customer_id = '" . (int) $customer_id . "'");
     if (!$data['approved']) {
         $language = new ALanguage($this->registry);
         $language->load('account/create');
         //notify administrator of pending customer approval
         $msg_text = sprintf($language->get('text_pending_customer_approval'), $data['firstname'] . ' ' . $data['lastname'], $customer_id);
         $msg = new AMessage();
         $msg->saveNotice($language->get('text_new_customer'), $msg_text);
     }
     return $customer_id;
 }
コード例 #2
0
ファイル: review.php プロジェクト: siddht1/abantecart-src
 /**
  * @param int $product_id
  * @param array $data
  * @return int
  */
 public function addReview($product_id, $data)
 {
     $this->db->query("INSERT INTO " . $this->db->table("reviews") . " \n\t\t\t\t\t\t  SET author = '" . $this->db->escape($data['name']) . "',\n\t\t\t\t\t\t      customer_id = '" . (int) $this->customer->getId() . "',\n\t\t\t\t\t\t      product_id = '" . (int) $product_id . "',\n\t\t\t\t\t\t      text = '" . $this->db->escape(strip_tags($data['text'])) . "',\n\t\t\t\t\t\t      rating = '" . (int) $data['rating'] . "',\n\t\t\t\t\t\t      date_added = NOW()");
     $review_id = $this->db->getLastId();
     //notify administrator of pending review approval
     $language = new ALanguage($this->registry);
     $language->load('product/product');
     $msg_text = sprintf($language->get('text_pending_review_approval'), $product_id, $review_id);
     $msg = new AMessage();
     $msg->saveNotice($language->get('text_new_review'), $msg_text);
     $this->cache->remove('product');
     return $review_id;
 }
コード例 #3
0
 public function __construct()
 {
     $this->registry = Registry::getInstance();
     $cache_files = glob(DIR_CACHE . '*/*', GLOB_NOSORT);
     if (!is_array($cache_files) || !is_writeable(DIR_CACHE)) {
         $log = $this->registry->get('log');
         if (!is_object($log) || !method_exists($log, 'write')) {
             $error_text = 'Error: Unable to access or write to cache directory ' . DIR_CACHE;
             $log = new ALog(DIR_SYSTEM . 'logs/error.txt');
             $this->registry->set('log', $log);
         }
         $log->write($error_text);
         //try to add message for admin (check if for install-process too)
         $db = $this->registry->get('db');
         if (is_object($db) && method_exists($db, 'query')) {
             $error_text .= ' Cache feature was disabled. Check permissions on directory and enable setting back.';
             $m = new AMessage();
             $m->saveError('AbanteCart Warning', $error_text);
             //also disable caching in config
             $sql = "UPDATE " . $db->table('settings') . "\n\t\t\t\t\t\tSET `value` = '0'\n\t\t\t\t\t\tWHERE `key` = 'config_cache_enable'";
             $db->query($sql);
         }
     } else {
         foreach ($cache_files as $file) {
             //first of all check if file expired. delete it if needed
             $file_time = filemtime($file);
             if (time() - $file_time > $this->expire) {
                 if (file_exists($file)) {
                     $this->_remove($file);
                     continue;
                 }
             }
             //build cache map as array {cache_file_name_without_timestamp=>expire_time}
             $ch_base = substr($file, 0, -11);
             $this->cache_map[$ch_base] = $file_time + $this->expire;
         }
     }
 }
コード例 #4
0
 public function send()
 {
     if ($this->config->get('default_authorizenet_aim_mode') == 'live') {
         $url = 'https://secure.authorize.net/gateway/transact.dll';
     } elseif ($this->config->get('default_authorizenet_aim_mode') == 'test') {
         $url = 'https://test.authorize.net/gateway/transact.dll';
     }
     if ($this->config->get('store_credit_cards_status')) {
         if (has_value($this->session->data['stored_credit_card'])) {
             foreach ($this->session->data['stored_credit_card'] as $key => $val) {
                 $this->request->post[$key] = $val;
             }
             unset($this->session->data['stored_credit_card']);
         }
         if ($this->request->post['credit_card_save']) {
             $data = array('card_nickname' => $this->request->post['cc_nickname'], 'card_owner' => $this->request->post['cc_owner'], 'card_number' => $this->request->post['cc_number'], 'cc_start_date_month' => isset($this->request->post['cc_start_date_month']) ? $this->request->post['cc_start_date_month'] : date('m'), 'cc_start_date_year' => isset($this->request->post['cc_start_date_year']) ? $this->request->post['cc_start_date_year'] : date('Y'), 'cc_expire_date_month' => $this->request->post['cc_expire_date_month'], 'cc_expire_date_year' => $this->request->post['cc_expire_date_year']);
             $this->loadModel('extension/store_credit_cards');
             $this->model_extension_store_credit_cards->addCard($data);
         }
     }
     $this->load->model('checkout/order');
     $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
     $data = array();
     $data['x_login'] = $this->config->get('default_authorizenet_aim_login');
     $data['x_tran_key'] = $this->config->get('default_authorizenet_aim_key');
     $data['x_version'] = '3.1';
     $data['x_delim_data'] = 'TRUE';
     $data['x_delim_char'] = ',';
     $data['x_encap_char'] = '"';
     $data['x_relay_response'] = 'FALSE';
     $data['x_first_name'] = html_entity_decode($order_info['payment_firstname'], ENT_QUOTES, 'UTF-8');
     $data['x_last_name'] = html_entity_decode($order_info['payment_lastname'], ENT_QUOTES, 'UTF-8');
     $data['x_company'] = html_entity_decode($order_info['payment_company'], ENT_QUOTES, 'UTF-8');
     $data['x_address'] = html_entity_decode($order_info['payment_address_1'], ENT_QUOTES, 'UTF-8');
     $data['x_city'] = html_entity_decode($order_info['payment_city'], ENT_QUOTES, 'UTF-8');
     $data['x_state'] = html_entity_decode($order_info['payment_zone'], ENT_QUOTES, 'UTF-8');
     $data['x_zip'] = html_entity_decode($order_info['payment_postcode'], ENT_QUOTES, 'UTF-8');
     $data['x_country'] = html_entity_decode($order_info['payment_country'], ENT_QUOTES, 'UTF-8');
     $data['x_phone'] = $order_info['telephone'];
     $data['x_customer_ip'] = $this->request->server['REMOTE_ADDR'];
     $data['x_email'] = $order_info['email'];
     $data['x_description'] = html_entity_decode($this->config->get('store_name'), ENT_QUOTES, 'UTF-8');
     $data['x_amount'] = $this->currency->format($order_info['total'], $order_info['currency'], 1.0, FALSE);
     $data['x_currency_code'] = $this->currency->getCode();
     $data['x_method'] = 'CC';
     $data['x_type'] = $this->config->get('default_authorizenet_aim_method') == 'capture' ? 'AUTH_CAPTURE' : 'AUTH_ONLY';
     $data['x_card_num'] = str_replace(' ', '', $this->request->post['cc_number']);
     $data['x_exp_date'] = $this->request->post['cc_expire_date_month'] . $this->request->post['cc_expire_date_year'];
     $data['x_card_code'] = $this->request->post['cc_cvv2'];
     $data['x_invoice_num'] = $this->session->data['order_id'];
     if ($this->config->get('default_authorizenet_aim_mode') == 'test') {
         $data['x_test_request'] = 'TRUE';
     }
     $curl = curl_init($url);
     curl_setopt($curl, CURLOPT_PORT, 443);
     curl_setopt($curl, CURLOPT_HEADER, 0);
     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
     curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
     curl_setopt($curl, CURLOPT_POST, 1);
     curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
     $response = curl_exec($curl);
     curl_close($curl);
     $i = 1;
     $response_data = array();
     $results = explode(',', $response);
     foreach ($results as $result) {
         $response_data[$i] = trim($result, '"');
         $i++;
     }
     $json = array();
     //build responce message for records
     $message = '';
     if (has_value($response_data['5'])) {
         $message .= 'Authorization Code: ' . $response_data['5'] . "\n";
     }
     if (has_value($response_data['6'])) {
         $message .= 'AVS Response: ' . $response_data['6'] . "\n";
     }
     if (has_value($response_data['7'])) {
         $message .= 'Transaction ID: ' . $response_data['7'] . "\n";
     }
     if (has_value($response_data['39'])) {
         $message .= 'Card Code Response: ' . $response_data['39'] . "\n";
     }
     if (has_value($response_data['40'])) {
         $message .= 'Cardholder Authentication Verification Response: ' . $response_data['40'] . "\n";
     }
     /*
     	Response Code:
     	Value: The overall status of the transaction
     	format:
     	 1 = Approved
     	 2 = Declined
     	 3 = Error
     	 4 = Held for Review		
     */
     if ($response_data[1] == '1') {
         if (strtoupper($response_data[38]) != strtoupper(md5($this->config->get('default_authorizenet_aim_hash') . $this->config->get('default_authorizenet_aim_login') . $response_data[6] . $this->currency->format($order_info['total'], $order_info['currency'], 1.0, FALSE)))) {
             $this->model_checkout_order->confirm($this->session->data['order_id'], $this->config->get('config_order_status_id'));
             $this->model_checkout_order->update($this->session->data['order_id'], $this->config->get('default_authorizenet_aim_order_status_id'), $message, FALSE);
         }
         $json['success'] = $this->html->getSecureURL('checkout/success');
     } else {
         if ($response_data[1] == '2') {
             $this->loadLanguage('default_authorizenet_aim/default_authorizenet_aim');
             //special case of declined payment. Count declined. If limit is set.
             $this->session->data['decline_count'] = $this->session->data['decline_count'] + 1;
             $decline_limit = $this->config->get('default_authorizenet_aim_decline_limit');
             if (has_value($decline_limit) && $this->session->data['decline_count'] > $decline_limit) {
                 $json['error'] = $this->language->get('warning_suspicious');
                 $this->loadModel('account/customer');
                 $customer_id = $this->customer->getId();
                 $this->model_account_customer->editStatus($customer_id, 0);
                 $link = $this->html->getSecureURL('sale/customer/update', '&s=' . ADMIN_PATH . '&customer_id=' . $customer_id);
                 $msg = new AMessage();
                 //send message with unique title to prevent grouping message
                 $msg->saveNotice($this->language->get('warning_suspicious_to_admin') . '. Customer ID: ' . $customer_id, sprintf($this->language->get('warning_suspicious_to_admin_body'), $link));
             } else {
                 $json['error'] = $this->language->get("warning_declined");
                 //record this decline to history
                 $message = 'Credit card was declined: ' . "<br>" . $message;
                 $this->model_checkout_order->addHistory($this->session->data['order_id'], 0, $message);
             }
         } else {
             if ($response_data[1] == '4') {
                 //special case of sucess payment in review stage. Create order with pending status
                 $new_order_status_id = $this->order_status->getStatusByTextId('pending');
                 $this->model_checkout_order->confirm($this->session->data['order_id'], $new_order_status_id);
                 $this->model_checkout_order->update($this->session->data['order_id'], $new_order_status_id, $message, FALSE);
                 $json['success'] = $this->html->getSecureURL('checkout/success');
             } else {
                 $json['error'] = $response_data[4];
                 //record this incident to history
                 $message = 'Error processing credit card: ' . "<br>" . $json['error'] . "<br>" . $message;
                 $this->model_checkout_order->addHistory($this->session->data['order_id'], 0, $message);
             }
         }
     }
     $this->load->library('json');
     $this->response->setOutput(AJson::encode($json));
 }
コード例 #5
0
ファイル: order.php プロジェクト: Cali-gula/abantecart-src
 /**
  * @param int $order_id
  * @param int $order_status_id
  * @param string $comment
  */
 public function _confirm($order_id, $order_status_id, $comment = '')
 {
     $order_query = $this->db->query("SELECT *,\n\t\t\t\t\t\t\t\t\t\t\t\tl.filename AS filename,\n\t\t\t\t\t\t\t\t\t\t\t\tl.directory AS directory\n\t\t\t\t\t\t\t\t\t\t FROM `" . $this->db->table("orders") . "` o\n\t\t\t\t\t\t\t\t\t\t LEFT JOIN " . $this->db->table("languages") . " l ON (o.language_id = l.language_id)\n\t\t\t\t\t\t\t\t\t\t WHERE o.order_id = '" . (int) $order_id . "'\n\t\t\t\t\t\t\t\t\t\t        AND o.order_status_id = '0'");
     if ($order_query->num_rows) {
         $order_row = $this->dcrypt->decrypt_data($order_query->row, 'orders');
         //if promotions applied - updates total and add row to order_total for promo type
         $update = array();
         $update[] = "order_status_id = '" . (int) $order_status_id . "'";
         $sql = "UPDATE `" . $this->db->table("orders") . "`\n\t\t\t\t    SET " . implode(", ", $update) . "\n\t\t\t\t\tWHERE order_id = '" . (int) $order_id . "'";
         $this->db->query($sql);
         $this->db->query("INSERT INTO " . $this->db->table("order_history") . "\n\t\t\t\t\t\t\t   SET order_id = '" . (int) $order_id . "',\n\t\t\t\t\t\t\t        order_status_id = '" . (int) $order_status_id . "',\n\t\t\t\t\t\t\t        notify = '1',\n\t\t\t\t\t\t\t        comment = '" . $this->db->escape($comment) . "',\n\t\t\t\t\t\t\t        date_added = NOW()");
         $order_row['comment'] = $order_row['comment'] . ' ' . $comment;
         $order_product_query = $this->db->query("SELECT *\n\t\t\t\t\t\t\t\t\t\t\t\t\t FROM " . $this->db->table("order_products") . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t WHERE order_id = '" . (int) $order_id . "'");
         foreach ($order_product_query->rows as $product) {
             $this->db->query("UPDATE " . $this->db->table("products") . "\n\t\t\t\t\t\t\t\t\t  SET quantity = (quantity - " . (int) $product['quantity'] . ")\n\t\t\t\t\t\t\t\t\t  WHERE product_id = '" . (int) $product['product_id'] . "' AND subtract = 1");
             $order_option_query = $this->db->query("SELECT *\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM " . $this->db->table("order_options") . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE order_id = '" . (int) $order_id . "'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND order_product_id = '" . (int) $product['order_product_id'] . "'");
             foreach ($order_option_query->rows as $option) {
                 $this->db->query("UPDATE " . $this->db->table("product_option_values") . "\n\t\t\t\t\t\t\t\t\t  SET quantity = (quantity - " . (int) $product['quantity'] . ")\n\t\t\t\t\t\t\t\t\t  WHERE product_option_value_id = '" . (int) $option['product_option_value_id'] . "'\n\t\t\t\t\t\t\t\t\t        AND subtract = 1");
             }
             $this->cache->delete('product');
         }
         $language = new ALanguage($this->registry, $order_row['code']);
         $language->load($order_row['filename']);
         $language->load('mail/order_confirm');
         $this->load->model('localisation/currency');
         $order_status_query = $this->db->query("SELECT *\n\t\t\t\t\t\t\t\t\t\t\t\t\tFROM " . $this->db->table("order_statuses") . "\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE order_status_id = '" . (int) $order_status_id . "'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND language_id = '" . (int) $order_row['language_id'] . "'");
         $order_product_query = $this->db->query("SELECT *\n\t\t\t\t\t\t\t\t\t\t\t\t\tFROM " . $this->db->table("order_products") . "\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE order_id = '" . (int) $order_id . "'");
         $order_total_query = $this->db->query("SELECT *\n\t\t\t\t\t\t\t\t\t\t\t\t\tFROM " . $this->db->table("order_totals") . "\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE order_id = '" . (int) $order_id . "'\n\t\t\t\t\t\t\t\t\t\t\t\t\tORDER BY sort_order ASC");
         $order_download_query = $this->db->query("SELECT *\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM " . $this->db->table("order_downloads") . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE order_id = '" . (int) $order_id . "'");
         $subject = sprintf($language->get('text_subject'), $order_row['store_name'], $order_id);
         // HTML Mail
         $template = new ATemplate();
         $template->data['title'] = sprintf($language->get('text_subject'), html_entity_decode($order_row['store_name'], ENT_QUOTES, 'UTF-8'), $order_id);
         $template->data['text_greeting'] = sprintf($language->get('text_greeting'), html_entity_decode($order_row['store_name'], ENT_QUOTES, 'UTF-8'));
         $template->data['text_order_detail'] = $language->get('text_order_detail');
         $template->data['text_order_id'] = $language->get('text_order_id');
         $template->data['text_invoice'] = $language->get('text_invoice');
         $template->data['text_date_added'] = $language->get('text_date_added');
         $template->data['text_telephone'] = $language->get('text_telephone');
         $template->data['text_email'] = $language->get('text_email');
         $template->data['text_ip'] = $language->get('text_ip');
         $template->data['text_fax'] = $language->get('text_fax');
         $template->data['text_shipping_address'] = $language->get('text_shipping_address');
         $template->data['text_payment_address'] = $language->get('text_payment_address');
         $template->data['text_shipping_method'] = $language->get('text_shipping_method');
         $template->data['text_payment_method'] = $language->get('text_payment_method');
         $template->data['text_comment'] = $language->get('text_comment');
         $template->data['text_powered_by'] = $language->get('text_powered_by');
         $template->data['text_project_label'] = $language->get('text_powered_by') . ' ' . project_base();
         $template->data['column_product'] = $language->get('column_product');
         $template->data['column_model'] = $language->get('column_model');
         $template->data['column_quantity'] = $language->get('column_quantity');
         $template->data['column_price'] = $language->get('column_price');
         $template->data['column_total'] = $language->get('column_total');
         $template->data['order_id'] = $order_id;
         $template->data['customer_id'] = $order_row['customer_id'];
         $template->data['date_added'] = dateISO2Display($order_row['date_added'], $language->get('date_format_short'));
         $template->data['logo'] = 'cid:' . md5(pathinfo($this->config->get('config_logo'), PATHINFO_FILENAME)) . '.' . pathinfo($this->config->get('config_logo'), PATHINFO_EXTENSION);
         $template->data['store_name'] = $order_row['store_name'];
         $template->data['address'] = nl2br($this->config->get('config_address'));
         $template->data['telephone'] = $this->config->get('config_telephone');
         $template->data['fax'] = $this->config->get('config_fax');
         $template->data['email'] = $this->config->get('store_main_email');
         $template->data['store_url'] = $order_row['store_url'];
         $template->data['invoice'] = $order_row['store_url'] . 'index.php?rt=account/invoice&order_id=' . $order_id;
         $template->data['firstname'] = $order_row['firstname'];
         $template->data['lastname'] = $order_row['lastname'];
         $template->data['shipping_method'] = $order_row['shipping_method'];
         $template->data['payment_method'] = $order_row['payment_method'];
         $template->data['customer_email'] = $order_row['email'];
         $template->data['customer_telephone'] = $order_row['telephone'];
         $template->data['customer_ip'] = $order_row['ip'];
         $template->data['comment'] = trim(nl2br($order_row['comment']));
         //override with the data from the before hooks
         if ($this->data) {
             $template->data = array_merge($template->data, $this->data);
         }
         $this->load->model('localisation/zone');
         $zone_row = $this->model_localisation_zone->getZone($order_row['shipping_zone_id']);
         if ($zone_row) {
             $zone_code = $zone_row['code'];
         } else {
             $zone_code = '';
         }
         $shipping_data = array('firstname' => $order_row['shipping_firstname'], 'lastname' => $order_row['shipping_lastname'], 'company' => $order_row['shipping_company'], 'address_1' => $order_row['shipping_address_1'], 'address_2' => $order_row['shipping_address_2'], 'city' => $order_row['shipping_city'], 'postcode' => $order_row['shipping_postcode'], 'zone' => $order_row['shipping_zone'], 'zone_code' => $zone_code, 'country' => $order_row['shipping_country']);
         $template->data['shipping_address'] = $this->customer->getFormatedAdress($shipping_data, $order_row['shipping_address_format']);
         $zone_row = $this->model_localisation_zone->getZone($order_row['payment_zone_id']);
         if ($zone_row) {
             $zone_code = $zone_row['code'];
         } else {
             $zone_code = '';
         }
         $payment_data = array('firstname' => $order_row['payment_firstname'], 'lastname' => $order_row['payment_lastname'], 'company' => $order_row['payment_company'], 'address_1' => $order_row['payment_address_1'], 'address_2' => $order_row['payment_address_2'], 'city' => $order_row['payment_city'], 'postcode' => $order_row['payment_postcode'], 'zone' => $order_row['payment_zone'], 'zone_code' => $zone_code, 'country' => $order_row['payment_country']);
         $template->data['payment_address'] = $this->customer->getFormatedAdress($payment_data, $order_row['payment_address_format']);
         if (!has_value($this->data['products'])) {
             $this->data['products'] = array();
         }
         foreach ($order_product_query->rows as $product) {
             $option_data = array();
             $order_option_query = $this->db->query("SELECT oo.*, po.element_type\n\t\t\t\t\t\tFROM " . $this->db->table("order_options") . " oo\n\t\t\t\t\t\tLEFT JOIN " . $this->db->table("product_option_values") . " pov\n\t\t\t\t\t\t\tON pov.product_option_value_id = oo.product_option_value_id\n\t\t\t\t\t\tLEFT JOIN " . $this->db->table("product_options") . " po\n\t\t\t\t\t\t\tON po.product_option_id = pov.product_option_id\n\t\t\t\t\t\tWHERE oo.order_id = '" . (int) $order_id . "' AND oo.order_product_id = '" . (int) $product['order_product_id'] . "'");
             foreach ($order_option_query->rows as $option) {
                 if ($option['element_type'] == 'H') {
                     continue;
                 } elseif ($option['element_type'] == 'C' && in_array($option['value'], array(0, 1, ''))) {
                     $option['value'] = '';
                 }
                 $option_data[] = array('name' => $option['name'], 'value' => $option['value']);
             }
             $this->data['products'][] = array('name' => $product['name'], 'model' => $product['model'], 'option' => $option_data, 'quantity' => $product['quantity'], 'price' => $this->currency->format($product['price'], $order_row['currency'], $order_row['value']), 'total' => $this->currency->format($product['total'], $order_row['currency'], $order_row['value']));
         }
         $template->data['products'] = $this->data['products'];
         $template->data['totals'] = $order_total_query->rows;
         $html = $template->fetch('mail/order_confirm.tpl');
         // Text Mail
         $text = sprintf($language->get('text_greeting'), html_entity_decode($order_row['store_name'], ENT_QUOTES, 'UTF-8')) . "\n\n";
         $text .= $language->get('text_order_id') . ' ' . $order_id . "\n";
         $text .= $language->get('text_date_added') . ' ' . dateISO2Display($order_row['date_added'], $language->get('date_format_short')) . "\n";
         $text .= $language->get('text_order_status') . ' ' . $order_status_query->row['name'] . "\n\n";
         $text .= $language->get('text_product') . "\n";
         foreach ($order_product_query->rows as $result) {
             $text .= $result['quantity'] . 'x ' . $result['name'] . ' (' . $result['model'] . ') ' . html_entity_decode($this->currency->format($result['total'], $order_row['currency'], $order_row['value']), ENT_NOQUOTES, 'UTF-8') . "\n";
             $order_option_query = $this->db->query("SELECT * FROM " . $this->db->table("order_options") . " WHERE order_id = '" . (int) $order_id . "' AND order_product_id = '" . $result['order_product_id'] . "'");
             foreach ($order_option_query->rows as $option) {
                 $text .= chr(9) . '-' . $option['name'] . ' ' . $option['value'] . "\n";
             }
         }
         $text .= "\n";
         $text .= $language->get('text_total') . "\n";
         foreach ($order_total_query->rows as $result) {
             $text .= $result['title'] . ' ' . html_entity_decode($result['text'], ENT_NOQUOTES, 'UTF-8') . "\n";
         }
         $order_total = $result['text'];
         $text .= "\n";
         if ($order_row['customer_id']) {
             $text .= $language->get('text_invoice') . "\n";
             $text .= $order_row['store_url'] . 'index.php?rt=account/invoice&order_id=' . $order_id . "\n\n";
         }
         if ($order_download_query->num_rows) {
             $text .= $language->get('text_download') . "\n";
             $text .= $order_row['store_url'] . 'index.php?rt=account/download' . "\n\n";
         }
         if ($order_row['comment'] != '') {
             $comment = $order_row['comment'] . "\n\n" . $comment;
         }
         if ($comment) {
             $text .= $language->get('text_comment') . "\n\n";
             $text .= $comment . "\n\n";
         }
         $text .= $language->get('text_footer');
         $mail = new AMail($this->config);
         $mail->setTo($order_row['email']);
         $mail->setFrom($this->config->get('store_main_email'));
         $mail->setSender($order_row['store_name']);
         $mail->setSubject($subject);
         $mail->setHtml($html);
         $mail->setText(html_entity_decode($text, ENT_QUOTES, 'UTF-8'));
         $mail->addAttachment(DIR_RESOURCE . $this->config->get('config_logo'), md5(pathinfo($this->config->get('config_logo'), PATHINFO_FILENAME)) . '.' . pathinfo($this->config->get('config_logo'), PATHINFO_EXTENSION));
         $mail->send();
         if ($this->config->get('config_alert_mail')) {
             // HTML
             $template->data['text_greeting'] = $language->get('text_received') . "\n\n";
             $template->data['invoice'] = '';
             $template->data['text_invoice'] = '';
             $html = $template->fetch('mail/order_confirm.tpl');
             $subject = sprintf($language->get('text_subject'), html_entity_decode($this->config->get('store_name'), ENT_QUOTES, 'UTF-8'), $order_id . ' (' . $order_total . ')');
             $mail->setSubject($subject);
             $mail->setTo($this->config->get('store_main_email'));
             $mail->setHtml($html);
             $mail->send();
             // Send to additional alert emails
             $emails = explode(',', $this->config->get('config_alert_emails'));
             foreach ($emails as $email) {
                 if (trim($email)) {
                     $mail->setTo($email);
                     $mail->send();
                 }
             }
         }
         $msg_text = sprintf($language->get('text_new_order_text'), $order_row['firstname'] . ' ' . $order_row['lastname']);
         $msg_text .= "<br/><br/>";
         foreach ($template->data['totals'] as $total) {
             $msg_text .= $total['title'] . ' - ' . $total['text'] . "<br/>";
         }
         $msg = new AMessage();
         $msg->saveNotice($language->get('text_new_order') . $order_id, $msg_text);
     }
 }
コード例 #6
0
 public function callback()
 {
     $this->load->library('encryption');
     $encryption = new AEncryption($this->config->get('encryption_key'));
     if (isset($this->request->post['custom'])) {
         $order_id = $encryption->decrypt($this->request->post['custom']);
     } else {
         $order_id = 0;
     }
     $this->load->model('checkout/order');
     $order_info = $this->model_checkout_order->getOrder($order_id);
     $suspect = false;
     $message = '';
     if ($order_info) {
         // check seller email and save message if not equal
         if ($this->request->post['receiver_email'] != $this->config->get('default_pp_standart_email')) {
             $this->load->language('default_pp_standart/default_pp_standart');
             $message .= $this->language->get('text_suspect');
             $params = array('payment_status', 'pending_reason', 'address_zip', 'address_country_code', 'address_name', 'address_country', 'address_city', 'quantity', 'payer_email', 'first_name', 'last_name', 'payment_gross', 'shipping', 'ipn_track_id', 'receiver_email');
             foreach ($params as $p) {
                 if (isset($this->request->post[$p])) {
                     $message .= $p . ": " . $this->request->post[$p] . "<br>\n";
                 }
             }
             $msg = new AMessage();
             $msg->saveNotice(sprintf($this->language->get('text_suspect_subj'), $order_id), $message);
             $suspect = true;
         }
         $request = 'cmd=_notify-validate';
         foreach ($this->request->post as $key => $value) {
             $request .= '&' . $key . '=' . urlencode(stripslashes(html_entity_decode($value, ENT_QUOTES, 'UTF-8')));
         }
         if (extension_loaded('curl')) {
             if (!$this->config->get('default_pp_standart_test')) {
                 $ch = curl_init('https://www.paypal.com/cgi-bin/webscr');
             } else {
                 $ch = curl_init('https://www.sandbox.paypal.com/cgi-bin/webscr');
             }
             curl_setopt($ch, CURLOPT_POST, true);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
             curl_setopt($ch, CURLOPT_HEADER, false);
             curl_setopt($ch, CURLOPT_TIMEOUT, 30);
             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
             $response = curl_exec($ch);
             if ($suspect === true) {
                 // set pending status for all suspected orders
                 $this->model_checkout_order->confirm($order_id, 1, $message);
             } elseif (strcmp($response, 'VERIFIED') == 0 || $this->request->post['payment_status'] == 'Completed') {
                 $this->model_checkout_order->confirm($order_id, $this->config->get('default_pp_standart_order_status_id'));
             } else {
                 $this->model_checkout_order->confirm($order_id, $this->config->get('config_order_status_id'));
             }
             curl_close($ch);
         } else {
             $header = 'POST /cgi-bin/webscr HTTP/1.0' . "\r\n";
             $header .= 'Content-Type: application/x-www-form-urlencoded' . "\r\n";
             $header .= 'Content-Length: ' . mb_strlen($request) . "\r\n";
             $header .= 'Connection: close' . "\r\n\r\n";
             if (!$this->config->get('default_pp_standart_test')) {
                 $fp = fsockopen('www.paypal.com', 80, $errno, $errstr, 30);
             } else {
                 $fp = fsockopen('www.sandbox.paypal.com', 80, $errno, $errstr, 30);
             }
             if ($fp) {
                 fputs($fp, $header . $request);
                 while (!feof($fp)) {
                     $response = fgets($fp, 1024);
                     if (strcmp($response, 'VERIFIED') == 0 || $this->request->post['payment_status'] == 'Completed') {
                         $this->model_checkout_order->confirm($order_id, $this->config->get('default_pp_standart_order_status_id'));
                     } else {
                         $this->model_checkout_order->confirm($order_id, $this->config->get('config_order_status_id'));
                     }
                 }
                 fclose($fp);
             }
         }
         $this->model_checkout_order->updatePaymentMethodData($this->session->data['order_id'], $response);
     }
 }
コード例 #7
0
 public function send()
 {
     if (defined('IS_DEMO') && IS_DEMO) {
         return null;
     }
     if (!$this->to) {
         $error = 'Error: E-Mail to required!';
         $this->log->write($error);
         $this->error[] = $error;
         $this->messages->saveError('Mailer error!', 'Can\'t send emails. Please see log for details and check your mail settings.');
         return false;
     }
     if (!$this->from) {
         $error = 'Error: E-Mail from required!';
         $this->log->write($error);
         $this->error[] = $error;
         $this->messages->saveError('Mailer error!', 'Can\'t send emails. Please see log for details and check your mail settings.');
         return false;
     }
     if (!$this->sender) {
         $error = 'Error: E-Mail sender required!';
         $this->log->write($error);
         $this->error[] = $error;
         $this->messages->saveError('Mailer error!', 'Can\'t send emails. Please see log for details and check your mail settings.');
         return false;
     }
     if (!$this->subject) {
         $error = 'Error: E-Mail subject required!';
         $this->log->write($error);
         $this->error[] = $error;
         $this->messages->saveError('Mailer error!', 'Can\'t send emails. Please see log for details and check your mail settings.');
         return false;
     }
     if (!$this->text && !$this->html) {
         $error = 'Error: E-Mail message required!';
         $this->log->write($error);
         $this->error[] = $error;
         $this->messages->saveError('Mailer error!', 'Can\'t send emails. Please see log for details and check your mail settings.');
         return false;
     }
     if (is_array($this->to)) {
         $to = implode(',', $this->to);
     } else {
         $to = $this->to;
     }
     $boundary = '----=_NextPart_' . md5(rand());
     $header = '';
     if ($this->protocol != 'mail') {
         $header .= 'To: ' . $to . $this->newline;
         $header .= 'Subject: ' . '=?UTF-8?B?' . base64_encode($this->subject) . '?=' . $this->newline;
     }
     $header .= 'Date: ' . date('D, d M Y H:i:s O') . $this->newline;
     $header .= 'From: ' . '=?UTF-8?B?' . base64_encode($this->sender) . '?=' . '<' . $this->from . '>' . $this->newline;
     $header .= 'Reply-To: ' . '=?UTF-8?B?' . base64_encode($this->sender) . '?=' . '<' . $this->from . '>' . $this->newline;
     $header .= 'Return-Path: ' . $this->from . $this->newline;
     $header .= 'X-Mailer: PHP/' . phpversion() . $this->newline;
     $header .= 'MIME-Version: 1.0' . $this->newline;
     $header .= 'Content-Type: multipart/related; boundary="' . $boundary . '"' . $this->newline . $this->newline;
     if (!$this->html) {
         $message = '--' . $boundary . $this->newline;
         $message .= 'Content-Type: text/plain; charset="utf-8"' . $this->newline;
         $message .= 'Content-Transfer-Encoding: 8bit' . $this->newline . $this->newline;
         $message .= $this->text . $this->newline;
     } else {
         $message = '--' . $boundary . $this->newline;
         $message .= 'Content-Type: multipart/alternative; boundary="' . $boundary . '_alt"' . $this->newline . $this->newline;
         $message .= '--' . $boundary . '_alt' . $this->newline;
         $message .= 'Content-Type: text/plain; charset="utf-8"' . $this->newline;
         $message .= 'Content-Transfer-Encoding: 8bit' . $this->newline . $this->newline;
         if ($this->text) {
             $message .= $this->text . $this->newline;
         } else {
             $message .= 'This is a HTML email and your email client software does not support HTML email!' . $this->newline;
         }
         $message .= '--' . $boundary . '_alt' . $this->newline;
         $message .= 'Content-Type: text/html; charset="utf-8"' . $this->newline;
         $message .= 'Content-Transfer-Encoding: base64' . $this->newline . $this->newline;
         $message .= chunk_split(base64_encode($this->html)) . $this->newline;
         $message .= '--' . $boundary . '_alt--' . $this->newline;
     }
     foreach ($this->attachments as $attachment) {
         if (file_exists($attachment['file'])) {
             $handle = fopen($attachment['file'], 'r');
             $content = fread($handle, filesize($attachment['file']));
             fclose($handle);
             $message .= '--' . $boundary . $this->newline;
             $message .= 'Content-Type: application/octet-stream' . $this->newline;
             $message .= 'Content-Transfer-Encoding: base64' . $this->newline;
             $message .= 'Content-Disposition: attachment; filename="' . $attachment['filename'] . '"' . $this->newline;
             $message .= 'Content-ID: <' . basename(urlencode($attachment['filename'])) . '>' . $this->newline;
             $message .= 'X-Attachment-Id: ' . basename(urlencode($attachment['filename'])) . $this->newline . $this->newline;
             $message .= chunk_split(base64_encode($content));
         }
     }
     $message .= '--' . $boundary . '--' . $this->newline;
     if ($this->protocol == 'mail') {
         ini_set('sendmail_from', $this->from);
         if ($this->parameter) {
             mail($to, '=?UTF-8?B?' . base64_encode($this->subject) . '?=', $message, $header, $this->parameter);
         } else {
             mail($to, '=?UTF-8?B?' . base64_encode($this->subject) . '?=', $message, $header);
         }
     } elseif ($this->protocol == 'smtp') {
         $handle = fsockopen($this->hostname, (int) $this->port, $errno, $errstr, (int) $this->timeout);
         if (!$handle) {
             $error = 'Error: ' . $errstr . ' (' . $errno . ')';
             $this->log->write($error);
             $this->error[] = $error;
         } else {
             if (substr(PHP_OS, 0, 3) != 'WIN') {
                 socket_set_timeout($handle, $this->timeout, 0);
             }
             while ($line = fgets($handle, 515)) {
                 if (substr($line, 3, 1) == ' ') {
                     break;
                 }
             }
             if (substr($this->hostname, 0, 3) == 'tls') {
                 fputs($handle, 'STARTTLS' . $this->crlf);
                 $reply = '';
                 while ($line = fgets($handle, 515)) {
                     $reply .= $line;
                     if (substr($line, 3, 1) == ' ') {
                         break;
                     }
                 }
                 if (substr($reply, 0, 3) != 220) {
                     $error = 'Error: STARTTLS not accepted from server!';
                     $this->log->write($error);
                     $this->error[] = $error;
                 }
             }
             if (!empty($this->username) && !empty($this->password)) {
                 fputs($handle, 'EHLO ' . getenv('SERVER_NAME') . $this->crlf);
                 $reply = '';
                 while ($line = fgets($handle, 515)) {
                     $reply .= $line;
                     if (substr($line, 3, 1) == ' ') {
                         break;
                     }
                 }
                 if (substr($reply, 0, 3) != 250) {
                     $error = 'Error: EHLO not accepted from server!';
                     $this->log->write($error);
                     $this->error[] = $error;
                 }
                 fputs($handle, 'AUTH LOGIN' . $this->crlf);
                 $reply = '';
                 while ($line = fgets($handle, 515)) {
                     $reply .= $line;
                     if (substr($line, 3, 1) == ' ') {
                         break;
                     }
                 }
                 if (substr($reply, 0, 3) != 334) {
                     $error = 'Error: AUTH LOGIN not accepted from server!';
                     $this->log->write($error);
                     $this->error[] = $error;
                 }
                 fputs($handle, base64_encode($this->username) . $this->crlf);
                 $reply = '';
                 while ($line = fgets($handle, 515)) {
                     $reply .= $line;
                     if (substr($line, 3, 1) == ' ') {
                         break;
                     }
                 }
                 if (substr($reply, 0, 3) != 334) {
                     $error = 'Error: Username not accepted from server!';
                     $this->log->write($error);
                     $this->error[] = $error;
                 }
                 fputs($handle, base64_encode($this->password) . $this->crlf);
                 $reply = '';
                 while ($line = fgets($handle, 515)) {
                     $reply .= $line;
                     if (substr($line, 3, 1) == ' ') {
                         break;
                     }
                 }
                 if (substr($reply, 0, 3) != 235) {
                     $error = 'Error: Password not accepted from server!';
                     $this->log->write($error);
                     $this->error[] = $error;
                 }
             } else {
                 fputs($handle, 'HELO ' . getenv('SERVER_NAME') . $this->crlf);
                 $reply = '';
                 while ($line = fgets($handle, 515)) {
                     $reply .= $line;
                     if (substr($line, 3, 1) == ' ') {
                         break;
                     }
                 }
                 if (substr($reply, 0, 3) != 250) {
                     $error = 'Error: HELO not accepted from server!';
                     $this->log->write($error);
                     $this->error[] = $error;
                 }
             }
             if ($this->verp) {
                 fputs($handle, 'MAIL FROM: <' . $this->from . '>XVERP' . $this->crlf);
             } else {
                 fputs($handle, 'MAIL FROM: <' . $this->from . '>' . $this->crlf);
             }
             $reply = '';
             while ($line = fgets($handle, 515)) {
                 $reply .= $line;
                 if (substr($line, 3, 1) == ' ') {
                     break;
                 }
             }
             if (substr($reply, 0, 3) != 250) {
                 $error = 'Error: MAIL FROM not accepted from server!';
                 $this->log->write($error);
                 $this->error[] = $error;
             }
             if (!is_array($this->to)) {
                 fputs($handle, 'RCPT TO: <' . $this->to . '>' . $this->crlf);
                 $reply = '';
                 while ($line = fgets($handle, 515)) {
                     $reply .= $line;
                     if (substr($line, 3, 1) == ' ') {
                         break;
                     }
                 }
                 if (substr($reply, 0, 3) != 250 && substr($reply, 0, 3) != 251) {
                     $error = 'Error: RCPT TO not accepted from server!';
                     $this->log->write($error);
                     $this->error[] = $error;
                 }
             } else {
                 foreach ($this->to as $recipient) {
                     fputs($handle, 'RCPT TO: <' . $recipient . '>' . $this->crlf);
                     $reply = '';
                     while ($line = fgets($handle, 515)) {
                         $reply .= $line;
                         if (substr($line, 3, 1) == ' ') {
                             break;
                         }
                     }
                     if (substr($reply, 0, 3) != 250 && substr($reply, 0, 3) != 251) {
                         $error = 'Error: RCPT TO not accepted from server!';
                         $this->log->write($error);
                         $this->error[] = $error;
                     }
                 }
             }
             fputs($handle, 'DATA' . $this->crlf);
             $reply = '';
             while ($line = fgets($handle, 515)) {
                 $reply .= $line;
                 if (substr($line, 3, 1) == ' ') {
                     break;
                 }
             }
             if (substr($reply, 0, 3) != 354) {
                 $error = 'Error: DATA not accepted from server!';
                 $this->log->write($error);
                 $this->error[] = $error;
             }
             fputs($handle, $header . $message . $this->crlf);
             fputs($handle, '.' . $this->crlf);
             $reply = '';
             while ($line = fgets($handle, 515)) {
                 $reply .= $line;
                 if (substr($line, 3, 1) == ' ') {
                     break;
                 }
             }
             if (substr($reply, 0, 3) != 250) {
                 $error = 'Error: DATA not accepted from server!';
                 $this->log->write($error);
                 $this->error[] = $error;
             }
             fputs($handle, 'QUIT' . $this->crlf);
             $reply = '';
             while ($line = fgets($handle, 515)) {
                 $reply .= $line;
                 if (substr($line, 3, 1) == ' ') {
                     break;
                 }
             }
             if (substr($reply, 0, 3) != 221) {
                 $error = 'Error: QUIT not accepted from server!';
                 $this->log->write($error);
                 $this->error[] = $error;
             }
             fclose($handle);
         }
     }
     if ($this->error) {
         $this->messages->saveError('Mailer error!', 'Can\'t send emails. Please see log for details and check your mail settings.');
     }
 }
コード例 #8
0
ファイル: product.php プロジェクト: vglide/abantecart-src
 public function main()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->document->resetBreadcrumbs();
     $this->document->addBreadcrumb(array('href' => $this->html->getURL('index/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE));
     $this->loadModel('tool/seo_url');
     $this->loadModel('catalog/category');
     if (isset($this->request->get['path'])) {
         $path = '';
         foreach (explode('_', $this->request->get['path']) as $path_id) {
             $category_info = $this->model_catalog_category->getCategory($path_id);
             if (!$path) {
                 $path = $path_id;
             } else {
                 $path .= '_' . $path_id;
             }
             if ($category_info) {
                 $this->document->addBreadcrumb(array('href' => $this->html->getSEOURL('product/category', '&path=' . $path, '&encode'), 'text' => $category_info['name'], 'separator' => $this->language->get('text_separator')));
             }
         }
     }
     $this->loadModel('catalog/manufacturer');
     if (isset($this->request->get['manufacturer_id'])) {
         $manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($this->request->get['manufacturer_id']);
         if ($manufacturer_info) {
             $this->document->addBreadcrumb(array('href' => $this->html->getSEOURL('product/manufacturer', '&manufacturer_id=' . $this->request->get['manufacturer_id'], '&encode'), 'text' => $manufacturer_info['name'], 'separator' => $this->language->get('text_separator')));
         }
     }
     if (isset($this->request->get['keyword'])) {
         $url = '';
         if (isset($this->request->get['category_id'])) {
             $url .= '&category_id=' . $this->request->get['category_id'];
         }
         if (isset($this->request->get['description'])) {
             $url .= '&description=' . $this->request->get['description'];
         }
         $this->document->addBreadcrumb(array('href' => $this->html->getURL('product/search', '&keyword=' . $this->request->get['keyword'] . $url, '&encode'), 'text' => $this->language->get('text_search'), 'separator' => $this->language->get('text_separator')));
     }
     $key = array();
     //key of product from cart
     if (has_value($this->request->get['key'])) {
         $key = explode(':', $this->request->get['key']);
         $product_id = (int) $key[0];
     } elseif (has_value($this->request->get['product_id'])) {
         $product_id = (int) $this->request->get['product_id'];
     } else {
         $product_id = 0;
     }
     $urls = array('is_group_option' => $this->html->getURL('r/product/product/is_group_option', '&product_id=' . $product_id, '&encode'));
     $this->view->assign('urls', $urls);
     $this->loadModel('catalog/product');
     $promoton = new APromotion();
     $product_info = $this->model_catalog_product->getProduct($product_id);
     //can not locate product? get out
     if (!$product_info) {
         $this->_product_not_found($product_id);
         return null;
     }
     $url = $this->_build_url();
     $this->view->assign('error', '');
     if (isset($this->session->data['error'])) {
         $this->view->assign('error', $this->session->data['error']);
         unset($this->session->data['error']);
     }
     $this->document->addBreadcrumb(array('href' => $this->html->getSEOURL('product/product', $url . '&product_id=' . $product_id, '&encode'), 'text' => $product_info['name'], 'separator' => $this->language->get('text_separator')));
     $this->document->setTitle($product_info['name']);
     $this->document->setKeywords($product_info['meta_keywords']);
     $this->document->setDescription($product_info['meta_description']);
     $this->document->addLink(array('href' => $this->html->getSEOURL('product/product', '&product_id=' . $product_id, '&encode'), 'rel' => 'canonical'));
     $this->data['heading_title'] = $product_info['name'];
     $this->data['minimum'] = $product_info['minimum'];
     $this->data['text_minimum'] = sprintf($this->language->get('text_minimum'), $product_info['minimum']);
     $this->data['maximum'] = $product_info['maximum'];
     $this->data['text_maximum'] = sprintf($this->language->get('text_maximum'), $product_info['maximum']);
     $this->data['option_resources_url'] = $this->html->getURL('r/product/product/get_option_resources');
     $this->data['calc_total_url'] = $this->html->getURL('r/product/product/calculateTotal');
     $this->data['product_review_url'] = $this->html->getURL('product/review/review', '&product_id=' . $product_id);
     $this->data['product_review_write_url'] = $this->html->getURL('product/review/write', '&product_id=' . $product_id);
     $this->data['product_wishlist_add_url'] = $this->html->getURL('product/wishlist/add', '&product_id=' . $product_id);
     $this->data['product_wishlist_remove_url'] = $this->html->getURL('product/wishlist/remove', '&product_id=' . $product_id);
     $this->data['captcha_url'] = $this->html->getURL('common/captcha');
     $this->loadModel('catalog/review');
     $this->data['tab_review'] = sprintf($this->language->get('tab_review'), $this->model_catalog_review->getTotalReviewsByProductId($product_id));
     if ($this->config->get('enable_reviews')) {
         $average = $this->model_catalog_review->getAverageRating($product_id);
     } else {
         $average = false;
     }
     $this->data['review_status'] = $this->config->get('enable_reviews');
     $this->data['text_stars'] = sprintf($this->language->get('text_stars'), $average);
     $this->data['rating_element'] = HtmlElementFactory::create(array('type' => 'rating', 'name' => 'rating', 'value' => '', 'options' => array(1 => 1, 2, 3, 4, 5), 'pack' => true));
     $this->data['review_name'] = HtmlElementFactory::create(array('type' => 'input', 'name' => 'name'));
     $this->data['review_text'] = HtmlElementFactory::create(array('type' => 'textarea', 'name' => 'text', 'attr' => ' rows="8" cols="50" '));
     $this->data['review_captcha'] = HtmlElementFactory::create(array('type' => 'input', 'name' => 'captcha', 'attr' => ''));
     $this->data['review_button'] = HtmlElementFactory::create(array('type' => 'button', 'name' => 'review_submit', 'text' => $this->language->get('button_submit'), 'style' => 'btn-primary', 'icon' => 'fa fa-comment'));
     $this->data['product_info'] = $product_info;
     $form = new AForm();
     $form->setForm(array('form_name' => 'product'));
     $this->data['form']['form_open'] = $form->getFieldHtml(array('type' => 'form', 'name' => 'product', 'action' => $this->html->getSecureURL('checkout/cart')));
     $product_price = $product_info['price'];
     $discount = $promoton->getProductDiscount($product_id);
     if ($discount) {
         $product_price = $discount;
         $this->data['price_num'] = $this->tax->calculate($discount, $product_info['tax_class_id'], (bool) $this->config->get('config_tax'));
         $this->data['special'] = FALSE;
     } else {
         $this->data['price_num'] = $this->tax->calculate($product_info['price'], $product_info['tax_class_id'], (bool) $this->config->get('config_tax'));
         $special = $promoton->getProductSpecial($product_id);
         if ($special) {
             $product_price = $special;
             $this->data['special_num'] = $this->tax->calculate($special, $product_info['tax_class_id'], (bool) $this->config->get('config_tax'));
         } else {
             $this->data['special'] = FALSE;
         }
     }
     $this->data['price'] = $this->currency->format($this->data['price_num']);
     if (isset($this->data['special_num'])) {
         $this->data['special'] = $this->currency->format($this->data['special_num']);
     }
     $product_discounts = $promoton->getProductDiscounts($product_id);
     $discounts = array();
     foreach ($product_discounts as $discount) {
         $discounts[] = array('quantity' => $discount['quantity'], 'price' => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], (bool) $this->config->get('config_tax'))));
     }
     $this->data['discounts'] = $discounts;
     $this->data['product_price'] = $product_price;
     $this->data['tax_class_id'] = $product_info['tax_class_id'];
     if (!$product_info['call_to_order']) {
         $this->data['form']['minimum'] = $form->getFieldHtml(array('type' => 'input', 'name' => 'quantity', 'value' => $product_info['minimum'] ? (int) $product_info['minimum'] : 1, 'style' => 'short', 'attr' => ' size="3" '));
         $this->data['form']['add_to_cart'] = $form->getFieldHtml(array('type' => 'button', 'name' => 'add_to_cart', 'text' => $this->language->get('button_add_to_cart'), 'style' => 'button1'));
     }
     $this->data['form']['product_id'] = $form->getFieldHtml(array('type' => 'hidden', 'name' => 'product_id', 'value' => $product_id));
     $this->data['form']['redirect'] = $form->getFieldHtml(array('type' => 'hidden', 'name' => 'redirect', 'value' => $this->html->getURL('product/product', $url . '&product_id=' . $product_id, '&encode')));
     $this->data['model'] = $product_info['model'];
     $this->data['manufacturer'] = $product_info['manufacturer'];
     $this->data['manufacturers'] = $this->html->getSEOURL('product/manufacturer', '&manufacturer_id=' . $product_info['manufacturer_id'], '&encode');
     $this->data['description'] = html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8');
     $this->data['product_id'] = $product_id;
     $this->data['average'] = $average;
     $resource = new AResource('image');
     $thumbnail = $resource->getMainThumb('manufacturers', $product_info['manufacturer_id'], (int) $this->config->get('config_image_grid_width'), (int) $this->config->get('config_image_grid_height'), true);
     if (!preg_match('/no_image/', $thumbnail['thumb_url'])) {
         $this->data['manufacturer_icon'] = $thumbnail['thumb_url'];
     }
     // Preapare options and values for display
     $elements_with_options = HtmlElementFactory::getElementsWithOptions();
     $options = array();
     $product_options = $this->model_catalog_product->getProductOptions($product_id);
     //get info from cart if key presents
     $cart_product_info = array();
     if ($key) {
         $cart_product_info = $this->cart->getProduct($this->request->get['key']);
     }
     foreach ($product_options as $option) {
         $values = array();
         $name = $price = '';
         $default_value = $cart_product_info['options'][$option['product_option_id']];
         if ($option['element_type'] == 'R') {
             $default_value = is_array($default_value) ? current($default_value) : (string) $default_value;
         }
         $preset_value = $default_value;
         foreach ($option['option_value'] as $option_value) {
             $default_value = $option_value['default'] && !$default_value ? $option_value['product_option_value_id'] : $default_value;
             // for case when trying to add to cart withot required options. we get option-array back inside _GET
             if (has_value($this->request->get['option'][$option['product_option_id']])) {
                 $default_value = $this->request->get['option'][$option['product_option_id']];
             }
             $name = $option_value['name'];
             //check if we disable options based on out of stock setting
             if ($option_value['subtract'] && $this->config->get('config_nostock_autodisable') && $option_value['quantity'] <= 0) {
                 continue;
             }
             //Apply option price modifier
             if ($option_value['prefix'] == '%') {
                 $price = $this->tax->calculate($product_price * $option_value['price'] / 100, $product_info['tax_class_id'], (bool) $this->config->get('config_tax'));
                 if ($price != 0) {
                     $price = $this->currency->format($price);
                 } else {
                     $price = '';
                 }
             } else {
                 $price = $this->tax->calculate($option_value['price'], $product_info['tax_class_id'], (bool) $this->config->get('config_tax'));
                 if ($price != 0) {
                     $price = $this->currency->format($price);
                 } else {
                     $price = '';
                 }
             }
             //Check stock and status
             $opt_stock_message = '';
             if ($option_value['subtract']) {
                 if ($option_value['quantity'] <= 0) {
                     //show out of stock message
                     $opt_stock_message = $product_info['stock_status'];
                 } else {
                     if ($this->config->get('config_stock_display')) {
                         $opt_stock_message = $option_value['quantity'] . " " . $this->language->get('text_instock');
                     }
                 }
             }
             $values[$option_value['product_option_value_id']] = $option_value['name'] . ' ' . $price . ' ' . $opt_stock_message;
         }
         //if not values are build, nothing to show
         if (count($values)) {
             $value = '';
             //add price to option name if it is not element with options
             if (!in_array($option['element_type'], $elements_with_options)) {
                 $option['name'] .= ' <small>' . $price . '</small>';
                 if ($opt_stock_message) {
                     $option['name'] .= '<br />' . $opt_stock_message;
                 }
                 $value = $default_value ? $default_value : $name;
             }
             //set default selection is nothing selected
             if (!has_value($value)) {
                 if (has_value($default_value)) {
                     $value = $default_value;
                 } else {
                     if (in_array($option['element_type'], $elements_with_options) && $option['element_type'] != 'S') {
                         //set first from the list to default
                         reset($values);
                         $value = key($values);
                     }
                 }
             }
             //for checkbox with empty value
             if ($value == '' && $option['element_type'] == 'C') {
                 $value = 1;
             }
             $option_data = array('type' => $option['html_type'], 'name' => !in_array($option['element_type'], HtmlElementFactory::getMultivalueElements()) ? 'option[' . $option['product_option_id'] . ']' : 'option[' . $option['product_option_id'] . '][]', 'value' => $value, 'options' => $values, 'required' => $option['required'], 'placeholder' => $option['option_placeholder'], 'regexp_pattern' => $option['regexp_pattern'], 'error_text' => $option['error_text']);
             if ($option['element_type'] == 'C') {
                 if (!in_array($value, array('0', '1'))) {
                     $option_data['label_text'] = $value;
                 }
                 $option_data['checked'] = $preset_value ? true : false;
             }
             $options[] = array('name' => $option['name'], 'html' => $this->html->buildElement($option_data));
         }
     }
     $this->data['options'] = $options;
     //handle stock messages
     // if track stock is off. no messages needed.
     if ($this->model_catalog_product->isStockTrackable($product_id)) {
         $total_quantity = $this->model_catalog_product->hasAnyStock($product_id);
         $this->data['track_stock'] = true;
         //out of stock if no quantity and no stick checkout is disabled
         if ($total_quantity <= 0 && !$this->config->get('config_stock_checkout')) {
             $this->data['in_stock'] = false;
             //show out of stock message
             $this->data['stock'] = $product_info['stock_status'];
         } else {
             $this->data['in_stock'] = true;
             if ($this->config->get('config_stock_display')) {
                 $this->data['stock'] = $product_info['quantity'];
             } else {
                 $this->data['stock'] = $this->language->get('text_instock');
             }
         }
         //check if we need to disable product for no stock
         if ($this->config->get('config_nostock_autodisable') && $total_quantity <= 0) {
             //set available data
             $pd_identifiers = "ID: " . $product_id;
             $pd_identifiers .= empty($product_info['model']) ? '' : " Model: " . $product_info['model'];
             $pd_identifiers .= empty($product_info['sku']) ? '' : " SKU: " . $product_info['sku'];
             $message_ttl = sprintf($this->language->get('notice_out_of_stock_ttl'), $product_info['name']);
             $message_txt = sprintf($this->language->get('notice_out_of_stock_body'), $product_info['name'], $pd_identifiers);
             //record to message box
             $msg = new AMessage();
             $msg->saveNotice($message_ttl, $message_txt);
             $this->model_catalog_product->updateStatus($product_id, 0);
             $this->redirect($this->html->getSEOURL('product/product', '&product_id=' . $product_info['product_id'], '&encode'));
         }
     }
     // main product image
     $sizes = array('main' => array('width' => $this->config->get('config_image_popup_width'), 'height' => $this->config->get('config_image_popup_height')), 'thumb' => array('width' => $this->config->get('config_image_thumb_width'), 'height' => $this->config->get('config_image_thumb_height')));
     $this->data['image_main'] = $resource->getResourceAllObjects('products', $product_id, $sizes, 1, false);
     if ($this->data['image_main']) {
         $this->data['image_main']['sizes'] = $sizes;
     }
     // additional images
     $sizes = array('main' => array('width' => $this->config->get('config_image_popup_width'), 'height' => $this->config->get('config_image_popup_height')), 'thumb' => array('width' => $this->config->get('config_image_additional_width'), 'height' => $this->config->get('config_image_additional_height')));
     $this->data['images'] = $resource->getResourceAllObjects('products', $product_id, $sizes, 0, false);
     $products = array();
     $results = $this->model_catalog_product->getProductRelated($product_id);
     foreach ($results as $result) {
         // related product image
         $sizes = array('main' => array('width' => $this->config->get('config_image_related_width'), 'height' => $this->config->get('config_image_related_height')), 'thumb' => array('width' => $this->config->get('config_image_related_width'), 'height' => $this->config->get('config_image_related_height')));
         $image = $resource->getResourceAllObjects('products', $result['product_id'], $sizes, 1);
         if ($this->config->get('enable_reviews')) {
             $rating = $this->model_catalog_review->getAverageRating($result['product_id']);
         } else {
             $rating = false;
         }
         $special = FALSE;
         $discount = $promoton->getProductDiscount($result['product_id']);
         if ($discount) {
             $price = $this->currency->format($this->tax->calculate($discount, $result['tax_class_id'], (bool) $this->config->get('config_tax')));
         } else {
             $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], (bool) $this->config->get('config_tax')));
             $special = $promoton->getProductSpecial($result['product_id']);
             if ($special) {
                 $special = $this->currency->format($this->tax->calculate($special, $result['tax_class_id'], (bool) $this->config->get('config_tax')));
             }
         }
         $options = $this->model_catalog_product->getProductOptions($result['product_id']);
         if ($options) {
             $add = $this->html->getSEOURL('product/product', '&product_id=' . $result['product_id'], '&encode');
         } else {
             if ($this->config->get('config_cart_ajax')) {
                 $add = '#';
             } else {
                 $add = $this->html->getSecureURL('checkout/cart', '&product_id=' . $result['product_id'], '&encode');
             }
         }
         $products[] = array('product_id' => $result['product_id'], 'name' => $result['name'], 'model' => $result['model'], 'rating' => $rating, 'stars' => sprintf($this->language->get('text_stars'), $rating), 'price' => $price, 'call_to_order' => $result['call_to_order'], 'options' => $options, 'special' => $special, 'image' => $image, 'href' => $this->html->getSEOURL('product/product', '&product_id=' . $result['product_id'], '&encode'), 'add' => $add);
     }
     $this->data['related_products'] = $products;
     if ($this->config->get('config_customer_price')) {
         $display_price = TRUE;
     } elseif ($this->customer->isLogged()) {
         $display_price = TRUE;
     } else {
         $display_price = FALSE;
     }
     $this->data['display_price'] = $display_price;
     $this->model_catalog_product->updateViewed($product_id);
     $tags = array();
     $results = $this->model_catalog_product->getProductTags($product_id);
     foreach ($results as $result) {
         if ($result['tag']) {
             $tags[] = array('tag' => $result['tag'], 'href' => $this->html->getURL('product/search', '&keyword=' . $result['tag'], '&encode'));
         }
     }
     $this->data['tags'] = $tags;
     //downloads before order if allowed
     if ($this->config->get('config_download')) {
         $dwn = new ADownload();
         $download_list = $dwn->getDownloadsBeforeOrder($product_id);
         if ($download_list) {
             foreach ($download_list as $download) {
                 $href = $this->html->getURL('account/download/startdownload', '&download_id=' . $download['download_id']);
                 $download['attributes'] = $this->download->getDownloadAttributesValuesForCustomer($download['download_id']);
                 $download['button'] = $form->getFieldHtml(array('type' => 'button', 'id' => 'download_' . $download['download_id'], 'href' => $href, 'title' => $this->language->get('text_start_download'), 'text' => $this->language->get('text_start_download')));
                 $downloads[] = $download;
             }
             $this->data['downloads'] = $downloads;
         }
     }
     #check if product is in a wishlist
     $this->data['is_customer'] = false;
     if ($this->customer->isLogged() || $this->customer->isUnauthCustomer()) {
         $this->data['is_customer'] = true;
         $whishlist = $this->customer->getWishList();
         if ($whishlist[$product_id]) {
             $this->data['in_wishlist'] = true;
         }
     }
     $this->view->setTemplate('pages/product/product.tpl');
     $this->view->batchAssign($this->data);
     $this->processTemplate();
     //init controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }
コード例 #9
0
 public function processPayment($pd, $customer_stripe_id = '')
 {
     $response = '';
     $this->load->model('checkout/order');
     $this->load->language('default_stripe/default_stripe');
     $order_info = $this->model_checkout_order->getOrder($pd['order_id']);
     try {
         require_once DIR_EXT . 'default_stripe/core/stripe_modules.php';
         grantStripeAccess($this->config);
         //build charge data array
         $charge_data = array();
         $charge_data['amount'] = $pd['amount'];
         $charge_data['currency'] = $pd['currency'];
         $charge_data['description'] = $this->config->get('store_name') . ' Order #' . $pd['order_id'];
         $charge_data['statement_descriptor'] = 'Order #' . $pd['order_id'];
         $charge_data['receipt_email'] = $order_info['email'];
         if ($this->config->get('default_stripe_settlement') == 'delayed') {
             $charge_data['capture'] = false;
         } else {
             $charge_data['capture'] = true;
         }
         //build cc details
         $cc_details = array('number' => $pd['cc_number'], 'exp_month' => $pd['cc_expire_month'], 'exp_year' => $pd['cc_expire_year'], 'cvc' => $pd['cc_cvv2'], 'name' => $pd['cc_owner']);
         $cc_details = array_merge($cc_details, array('address_line1' => $order_info['payment_address_1'], 'address_line2' => $order_info['payment_address_2'], 'address_city' => $order_info['payment_city'], 'address_zip' => $order_info['payment_postcode'], 'address_state' => $order_info['payment_zone'], 'address_country' => $order_info['payment_iso_code_2']));
         //we need get the token for the card first
         $token = array();
         $token = Stripe_Token::create(array('card' => $cc_details));
         if (!$token || !$token['id']) {
             $msg = new AMessage();
             $msg->saveError('Stripe failed to get card token for order_id ' . $pd['order_id'], 'Unable to use card for customer' . $customer_stripe_id);
             $response['error'] = $this->language->get('error_system');
             return $response;
         }
         $charge_data['card'] = $token['id'];
         if ($order_info['shipping_method']) {
             $charge_data['shipping'] = array('name' => $order_info['firstname'] . ' ' . $order_info['lastname'], 'phone' => $order_info['telephone'], 'address' => array('line1' => $order_info['shipping_address_1'], 'line2' => $order_info['shipping_address_2'], 'city' => $order_info['shipping_city'], 'postal_code' => $order_info['shipping_postcode'], 'state' => $order_info['shipping_zone'], 'country' => $order_info['shipping_iso_code_2']));
         }
         $charge_data['metadata'] = array();
         $charge_data['metadata']['order_id'] = $pd['order_id'];
         if ($this->customer->getId() > 0) {
             $charge_data['metadata']['customer_id'] = (int) $this->customer->getId();
         }
         ADebug::variable('Processing stripe payment request: ', $charge_data);
         $response = Stripe_Charge::create($charge_data);
     } catch (Stripe_CardError $e) {
         // card errors
         $body = $e->getJsonBody();
         $response['error'] = $body['error']['message'];
         $response['code'] = $body['error']['code'];
         return $response;
     } catch (Stripe_InvalidRequestError $e) {
         // Invalid parameters were supplied to Stripe's API
         $body = $e->getJsonBody();
         $msg = new AMessage();
         $msg->saveError('Stripe payment failed with invalid parameters!', 'Stripe payment failed. ' . $body['error']['message']);
         $response['error'] = $this->language->get('error_system');
         return $response;
     } catch (Stripe_AuthenticationError $e) {
         // Authentication with Stripe's API failed
         $body = $e->getJsonBody();
         $msg = new AMessage();
         $msg->saveError('Stripe payment failed to authenticate!', 'Stripe payment failed to authenticate to the server. ' . $body['error']['message']);
         $response['error'] = $this->language->get('error_system');
         return $response;
     } catch (Stripe_ApiConnectionError $e) {
         // Network communication with Stripe failed
         $body = $e->getJsonBody();
         $msg = new AMessage();
         $msg->saveError('Stripe payment connection has failed!', 'Stripe payment failed connecting to the server. ' . $body['error']['message']);
         $response['error'] = $this->language->get('error_system');
         return $response;
     } catch (Stripe_Error $e) {
         // Display a very generic error to the user, and maybe send
         $body = $e->getJsonBody();
         $msg = new AMessage();
         $msg->saveError('Stripe payment has failed!', 'Stripe processing failed. ' . $body['error']['message']);
         $response['error'] = $this->language->get('error_system');
         return $response;
     } catch (Exception $e) {
         // Something else happened, completely unrelated to Stripe
         $msg = new AMessage();
         $msg->saveError('Unexpected error in stripe payment!', 'Stripe processing failed. ' . $e->getMessage() . "(" . $e->getCode() . ")");
         $response['error'] = $this->language->get('error_system');
         //log in AException
         $ae = new AException($e->getCode(), $e->getMessage(), $e->getFile(), $e->getLine());
         ac_exception_handler($ae);
         return $response;
     }
     //we still have no result. something unexpected happend
     if (empty($response)) {
         $response['error'] = $this->language->get('error_system');
         return $response;
     }
     ADebug::variable('Processing stripe payment response: ', $response);
     //Do we have an error? exit with no records
     if ($response['failure_message'] || $response['failure_code']) {
         $response['error'] = $response['failure_message'];
         $response['code'] = $response['failure_code'];
         return $response;
     }
     $message .= 'Order id: ' . (string) $pd['order_id'] . "\n";
     $message .= 'Charge id: ' . (string) $response['id'] . "\n";
     $message .= 'Transaction Timestamp: ' . (string) date('m/d/Y H:i:s', $response['created']);
     if ($response['paid']) {
         //finalize order only if payment is a success
         $this->model_checkout_order->addHistory($pd['order_id'], $this->config->get('config_order_status_id'), $message);
         if ($this->config->get('default_stripe_settlement') == 'auto') {
             //auto complete the order in sattled mode
             $this->model_checkout_order->confirm($pd['order_id'], $this->config->get('default_stripe_status_success_settled'));
         } else {
             //complete the order in unsattled mode
             $this->model_checkout_order->confirm($pd['order_id'], $this->config->get('default_stripe_status_success_unsettled'));
         }
     } else {
         // Some other error, assume payment declined
         $this->model_checkout_order->addHistory($pd['order_id'], $this->config->get('default_stripe_status_decline'), $message);
         $response['error'] = "Payment has failed! " . $response['failure_message'];
         $response['code'] = $response['failure_code'];
     }
     return $response;
 }