Guest User

Untitled

a guest
Jul 28th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.87 KB | None | 0 0
  1. <?php
  2. class ModelCheckoutOrder extends Model {
  3. public function getOrder($order_id) {
  4. $order_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order` WHERE order_id = '" . (int)$order_id . "'");
  5.  
  6. if ($order_query->num_rows) {
  7. $country_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "country` WHERE country_id = '" . (int)$order_query->row['shipping_country_id'] . "'");
  8.  
  9. if ($country_query->num_rows) {
  10. $shipping_iso_code_2 = $country_query->row['iso_code_2'];
  11. $shipping_iso_code_3 = $country_query->row['iso_code_3'];
  12. } else {
  13. $shipping_iso_code_2 = '';
  14. $shipping_iso_code_3 = '';
  15. }
  16.  
  17. $zone_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone` WHERE zone_id = '" . (int)$order_query->row['shipping_zone_id'] . "'");
  18.  
  19. if ($zone_query->num_rows) {
  20. $shipping_zone_code = $zone_query->row['code'];
  21. } else {
  22. $shipping_zone_code = '';
  23. }
  24.  
  25. $country_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "country` WHERE country_id = '" . (int)$order_query->row['payment_country_id'] . "'");
  26.  
  27. if ($country_query->num_rows) {
  28. $payment_iso_code_2 = $country_query->row['iso_code_2'];
  29. $payment_iso_code_3 = $country_query->row['iso_code_3'];
  30. } else {
  31. $payment_iso_code_2 = '';
  32. $payment_iso_code_3 = '';
  33. }
  34.  
  35. $zone_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone` WHERE zone_id = '" . (int)$order_query->row['payment_zone_id'] . "'");
  36.  
  37. if ($zone_query->num_rows) {
  38. $payment_zone_code = $zone_query->row['code'];
  39. } else {
  40. $payment_zone_code = '';
  41. }
  42.  
  43. $order_data = $order_query->row;
  44.  
  45. $order_data['shipping_zone_code'] = $shipping_zone_code;
  46. $order_data['shipping_iso_code_2'] = $shipping_iso_code_2;
  47. $order_data['shipping_iso_code_3'] = $shipping_iso_code_3;
  48. $order_data['payment_zone_code'] = $payment_zone_code;
  49. $order_data['payment_iso_code_2'] = $payment_iso_code_2;
  50. $order_data['payment_iso_code_3'] = $payment_iso_code_3;
  51.  
  52. return $order_data;
  53. } else {
  54. return FALSE;
  55. }
  56. }
  57.  
  58. public function create($data) {
  59. $query = $this->db->query("SELECT order_id FROM `" . DB_PREFIX . "order` WHERE date_added < '" . date('Y-m-d', strtotime('-1 month')) . "' AND order_status_id = '0'");
  60.  
  61. foreach ($query->rows as $result) {
  62. $this->db->query("DELETE FROM `" . DB_PREFIX . "order` WHERE order_id = '" . (int)$result['order_id'] . "'");
  63. $this->db->query("DELETE FROM " . DB_PREFIX . "order_history WHERE order_id = '" . (int)$result['order_id'] . "'");
  64. $this->db->query("DELETE FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$result['order_id'] . "'");
  65. $this->db->query("DELETE FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int)$result['order_id'] . "'");
  66. $this->db->query("DELETE FROM " . DB_PREFIX . "order_download WHERE order_id = '" . (int)$result['order_id'] . "'");
  67. $this->db->query("DELETE FROM " . DB_PREFIX . "order_total WHERE order_id = '" . (int)$result['order_id'] . "'");
  68. }
  69.  
  70. $this->db->query("INSERT INTO `" . DB_PREFIX . "order` SET store_id = '" . (int)$data['store_id'] . "', store_name = '" . $this->db->escape($data['store_name']) . "', store_url = '" . $this->db->escape($data['store_url']) . "', customer_id = '" . (int)$data['customer_id'] . "', customer_group_id = '" . (int)$data['customer_group_id'] . "', firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', email = '" . $this->db->escape($data['email']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', fax = '" . $this->db->escape($data['fax']) . "', total = '" . (float)$data['total'] . "', language_id = '" . (int)$data['language_id'] . "', currency = '" . $this->db->escape($data['currency']) . "', currency_id = '" . (int)$data['currency_id'] . "', value = '" . (float)$data['value'] . "', coupon_id = '" . (int)$data['coupon_id'] . "', ip = '" . $this->db->escape($data['ip']) . "', shipping_firstname = '" . $this->db->escape($data['shipping_firstname']) . "', shipping_lastname = '" . $this->db->escape($data['shipping_lastname']) . "', shipping_company = '" . $this->db->escape($data['shipping_company']) . "', shipping_address_1 = '" . $this->db->escape($data['shipping_address_1']) . "', shipping_address_2 = '" . $this->db->escape($data['shipping_address_2']) . "', shipping_city = '" . $this->db->escape($data['shipping_city']) . "', shipping_postcode = '" . $this->db->escape($data['shipping_postcode']) . "', shipping_zone = '" . $this->db->escape($data['shipping_zone']) . "', shipping_zone_id = '" . (int)$data['shipping_zone_id'] . "', shipping_country = '" . $this->db->escape($data['shipping_country']) . "', shipping_country_id = '" . (int)$data['shipping_country_id'] . "', shipping_address_format = '" . $this->db->escape($data['shipping_address_format']) . "', shipping_method = '" . $this->db->escape($data['shipping_method']) . "', payment_firstname = '" . $this->db->escape($data['payment_firstname']) . "', payment_lastname = '" . $this->db->escape($data['payment_lastname']) . "', payment_company = '" . $this->db->escape($data['payment_company']) . "', payment_address_1 = '" . $this->db->escape($data['payment_address_1']) . "', payment_address_2 = '" . $this->db->escape($data['payment_address_2']) . "', payment_city = '" . $this->db->escape($data['payment_city']) . "', payment_postcode = '" . $this->db->escape($data['payment_postcode']) . "', payment_zone = '" . $this->db->escape($data['payment_zone']) . "', payment_zone_id = '" . (int)$data['payment_zone_id'] . "', payment_country = '" . $this->db->escape($data['payment_country']) . "', payment_country_id = '" . (int)$data['payment_country_id'] . "', payment_address_format = '" . $this->db->escape($data['payment_address_format']) . "', payment_method = '" . $this->db->escape($data['payment_method']) . "', comment = '" . $this->db->escape($data['comment']) . "', date_modified = NOW(), date_added = NOW()");
  71.  
  72. $order_id = $this->db->getLastId();
  73.  
  74. foreach ($data['products'] as $product) {
  75. $this->db->query("INSERT INTO " . DB_PREFIX . "order_product SET order_id = '" . (int)$order_id . "', product_id = '" . (int)$product['product_id'] . "', name = '" . $this->db->escape($product['name']) . "', model = '" . $this->db->escape($product['model']) . "', price = '" . (float)$product['price'] . "', total = '" . (float)$product['total'] . "', tax = '" . (float)$product['tax'] . "', quantity = '" . (int)$product['quantity'] . "'");
  76.  
  77. $order_product_id = $this->db->getLastId();
  78.  
  79. foreach ($product['option'] as $option) {
  80. $this->db->query("INSERT INTO " . DB_PREFIX . "order_option SET order_id = '" . (int)$order_id . "', order_product_id = '" . (int)$order_product_id . "', product_option_value_id = '" . (int)$option['product_option_value_id'] . "', name = '" . $this->db->escape($option['name']) . "', `value` = '" . $this->db->escape($option['value']) . "', price = '" . (float)$product['price'] . "', prefix = '" . $this->db->escape($option['prefix']) . "'");
  81. }
  82.  
  83. foreach ($product['download'] as $download) {
  84. $this->db->query("INSERT INTO " . DB_PREFIX . "order_download SET order_id = '" . (int)$order_id . "', order_product_id = '" . (int)$order_product_id . "', name = '" . $this->db->escape($download['name']) . "', filename = '" . $this->db->escape($download['filename']) . "', mask = '" . $this->db->escape($download['mask']) . "', remaining = '" . (int)($download['remaining'] * $product['quantity']) . "'");
  85. }
  86. }
  87.  
  88. foreach ($data['totals'] as $total) {
  89. $this->db->query("INSERT INTO " . DB_PREFIX . "order_total SET order_id = '" . (int)$order_id . "', title = '" . $this->db->escape($total['title']) . "', text = '" . $this->db->escape($total['text']) . "', `value` = '" . (float)$total['value'] . "', sort_order = '" . (int)$total['sort_order'] . "'");
  90. }
  91.  
  92. return $order_id;
  93. }
  94.  
  95. public function confirm($order_id, $order_status_id, $comment = '') {
  96. $order_query = $this->db->query("SELECT *, l.filename AS filename, l.directory AS directory FROM `" . DB_PREFIX . "order` o LEFT JOIN " . DB_PREFIX . "language l ON (o.language_id = l.language_id) WHERE o.order_id = '" . (int)$order_id . "' AND o.order_status_id = '0'");
  97.  
  98. if ($order_query->num_rows) {
  99. $this->db->query("UPDATE `" . DB_PREFIX . "order` SET order_status_id = '" . (int)$order_status_id . "' WHERE order_id = '" . (int)$order_id . "'");
  100.  
  101. $this->db->query("INSERT INTO " . DB_PREFIX . "order_history SET order_id = '" . (int)$order_id . "', order_status_id = '" . (int)$order_status_id . "', notify = '1', comment = '" . $this->db->escape($comment) . "', date_added = NOW()");
  102.  
  103. if ($this->config->get('config_stock_subtract')) {
  104. $order_product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");
  105.  
  106. foreach ($order_product_query->rows as $product) {
  107. $this->db->query("UPDATE " . DB_PREFIX . "product SET quantity = (quantity - " . (int)$product['quantity'] . ") WHERE product_id = '" . (int)$product['product_id'] . "'");
  108.  
  109. $order_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int)$order_id . "' AND order_product_id = '" . (int)$product['order_product_id'] . "'");
  110.  
  111. foreach ($order_option_query->rows as $option) {
  112. $this->db->query("UPDATE " . DB_PREFIX . "product_option_value SET quantity = (quantity - " . (int)$product['quantity'] . ") WHERE product_option_value_id = '" . (int)$option['product_option_value_id'] . "' AND subtract = '1'");
  113. }
  114. }
  115. }
  116.  
  117. $language = new Language($order_query->row['directory']);
  118. $language->load($order_query->row['filename']);
  119. $language->load('mail/order_confirm');
  120.  
  121. $this->load->model('localisation/currency');
  122.  
  123. $order_status_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_status WHERE order_status_id = '" . (int)$order_status_id . "' AND language_id = '" . (int)$order_query->row['language_id'] . "'");
  124. $order_product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");
  125. $order_total_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_total WHERE order_id = '" . (int)$order_id . "' ORDER BY sort_order ASC");
  126. $order_download_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_download WHERE order_id = '" . (int)$order_id . "'");
  127.  
  128. $subject = sprintf($language->get('text_subject'), $order_query->row['store_name'], $order_id);
  129.  
  130. // HTML Mail
  131. $template = new Template();
  132.  
  133. $template->data['title'] = sprintf($language->get('text_subject'), html_entity_decode($order_query->row['store_name'], ENT_QUOTES, 'UTF-8'), $order_id);
  134.  
  135. $template->data['text_greeting'] = sprintf($language->get('text_greeting'), html_entity_decode($order_query->row['store_name'], ENT_QUOTES, 'UTF-8'));
  136. $template->data['text_order_detail'] = $language->get('text_order_detail');
  137. $template->data['text_order_id'] = $language->get('text_order_id');
  138. $template->data['text_invoice'] = $language->get('text_invoice');
  139. $template->data['text_date_added'] = $language->get('text_date_added');
  140. $template->data['text_telephone'] = $language->get('text_telephone');
  141. $template->data['text_fax'] = $language->get('text_fax');
  142. $template->data['text_shipping_address'] = $language->get('text_shipping_address');
  143. $template->data['text_payment_address'] = $language->get('text_payment_address');
  144. $template->data['text_shipping_method'] = $language->get('text_shipping_method');
  145. $template->data['text_payment_method'] = $language->get('text_payment_method');
  146. $template->data['text_comment'] = $language->get('text_comment');
  147. $template->data['text_powered_by'] = $language->get('text_powered_by');
  148.  
  149. $template->data['column_product'] = $language->get('column_product');
  150. $template->data['column_model'] = $language->get('column_model');
  151. $template->data['column_quantity'] = $language->get('column_quantity');
  152. $template->data['column_price'] = $language->get('column_price');
  153. $template->data['column_total'] = $language->get('column_total');
  154.  
  155. $template->data['order_id'] = $order_id;
  156. $template->data['customer_id'] = $order_query->row['customer_id'];
  157. $template->data['date_added'] = date($language->get('date_format_short'), strtotime($order_query->row['date_added']));
  158. $template->data['logo'] = 'cid:' . basename($this->config->get('config_logo'));
  159. $template->data['store_name'] = $order_query->row['store_name'];
  160. $template->data['address'] = nl2br($this->config->get('config_address'));
  161. $template->data['telephone'] = $this->config->get('config_telephone');
  162. $template->data['fax'] = $this->config->get('config_fax');
  163. $template->data['email'] = $this->config->get('config_email');
  164. $template->data['store_url'] = $order_query->row['store_url'];
  165. $template->data['invoice'] = $order_query->row['store_url'] . 'index.php?route=account/invoice&order_id=' . $order_id;
  166. $template->data['firstname'] = $order_query->row['firstname'];
  167. $template->data['lastname'] = $order_query->row['lastname'];
  168. $template->data['shipping_method'] = $order_query->row['shipping_method'];
  169. $template->data['payment_method'] = $order_query->row['payment_method'];
  170. $template->data['comment'] = $order_query->row['comment'];
  171.  
  172. $zone_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone` WHERE zone_id = '" . (int)$order_query->row['shipping_zone_id'] . "'");
  173.  
  174. if ($zone_query->num_rows) {
  175. $zone_code = $zone_query->row['code'];
  176. } else {
  177. $zone_code = '';
  178. }
  179.  
  180. if ($order_query->row['shipping_address_format']) {
  181. $format = $order_query->row['shipping_address_format'];
  182. } else {
  183. $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
  184. }
  185.  
  186. $find = array(
  187. '{firstname}',
  188. '{lastname}',
  189. '{company}',
  190. '{address_1}',
  191. '{address_2}',
  192. '{city}',
  193. '{postcode}',
  194. '{zone}',
  195. '{zone_code}',
  196. '{country}'
  197. );
  198.  
  199. $replace = array(
  200. 'firstname' => $order_query->row['shipping_firstname'],
  201. 'lastname' => $order_query->row['shipping_lastname'],
  202. 'company' => $order_query->row['shipping_company'],
  203. 'address_1' => $order_query->row['shipping_address_1'],
  204. 'address_2' => $order_query->row['shipping_address_2'],
  205. 'city' => $order_query->row['shipping_city'],
  206. 'postcode' => $order_query->row['shipping_postcode'],
  207. 'zone' => $order_query->row['shipping_zone'],
  208. 'zone_code' => $zone_code,
  209. 'country' => $order_query->row['shipping_country']
  210. );
  211.  
  212. $template->data['shipping_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));
  213.  
  214. $zone_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone` WHERE zone_id = '" . (int)$order_query->row['payment_zone_id'] . "'");
  215.  
  216. if ($zone_query->num_rows) {
  217. $zone_code = $zone_query->row['code'];
  218. } else {
  219. $zone_code = '';
  220. }
  221.  
  222. if ($order_query->row['payment_address_format']) {
  223. $format = $order_query->row['payment_address_format'];
  224. } else {
  225. $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
  226. }
  227.  
  228. $find = array(
  229. '{firstname}',
  230. '{lastname}',
  231. '{company}',
  232. '{address_1}',
  233. '{address_2}',
  234. '{city}',
  235. '{postcode}',
  236. '{zone}',
  237. '{zone_code}',
  238. '{country}'
  239. );
  240.  
  241. $replace = array(
  242. 'firstname' => $order_query->row['payment_firstname'],
  243. 'lastname' => $order_query->row['payment_lastname'],
  244. 'company' => $order_query->row['payment_company'],
  245. 'address_1' => $order_query->row['payment_address_1'],
  246. 'address_2' => $order_query->row['payment_address_2'],
  247. 'city' => $order_query->row['payment_city'],
  248. 'postcode' => $order_query->row['payment_postcode'],
  249. 'zone' => $order_query->row['payment_zone'],
  250. 'zone_code' => $zone_code,
  251. 'country' => $order_query->row['payment_country']
  252. );
  253.  
  254. $template->data['payment_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));
  255.  
  256. $template->data['products'] = array();
  257.  
  258. foreach ($order_product_query->rows as $product) {
  259. $option_data = array();
  260.  
  261. $order_option_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int)$order_id . "' AND order_product_id = '" . (int)$product['order_product_id'] . "'");
  262.  
  263. foreach ($order_option_query->rows as $option) {
  264. $option_data[] = array(
  265. 'name' => $option['name'],
  266. 'value' => $option['value']
  267. );
  268. }
  269.  
  270. $template->data['products'][] = array(
  271. 'name' => $product['name'],
  272. 'model' => $product['model'],
  273. 'option' => $option_data,
  274. 'quantity' => $product['quantity'],
  275. 'price' => $this->currency->format($product['price'], $order_query->row['currency'], $order_query->row['value']),
  276. 'total' => $this->currency->format($product['total'], $order_query->row['currency'], $order_query->row['value'])
  277. );
  278. }
  279.  
  280. $template->data['totals'] = $order_total_query->rows;
  281.  
  282. if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/mail/order_confirm.tpl')) {
  283. $html = $template->fetch($this->config->get('config_template') . '/template/mail/order_confirm.tpl');
  284. } else {
  285. $html = $template->fetch('default/template/mail/order_confirm.tpl');
  286. }
  287.  
  288. // Text Mail
  289. $text = sprintf($language->get('text_greeting'), html_entity_decode($order_query->row['store_name'], ENT_QUOTES, 'UTF-8')) . "\n\n";
  290. $text .= $language->get('text_order_id') . ' ' . $order_id . "\n";
  291. $text .= $language->get('text_date_added') . ' ' . date($language->get('date_format_short'), strtotime($order_query->row['date_added'])) . "\n";
  292. $text .= $language->get('text_order_status') . ' ' . $order_status_query->row['name'] . "\n\n";
  293. $text .= $language->get('text_product') . "\n";
  294.  
  295. foreach ($order_product_query->rows as $result) {
  296. $text .= $result['quantity'] . 'x ' . $result['name'] . ' (' . $result['model'] . ') ' . html_entity_decode($this->currency->format($result['total'], $order_query->row['currency'], $order_query->row['value']), ENT_NOQUOTES, 'UTF-8') . "\n";
  297. }
  298.  
  299. $text .= "\n";
  300.  
  301. $text .= $language->get('text_total') . "\n";
  302.  
  303. foreach ($order_total_query->rows as $result) {
  304. $text .= $result['title'] . ' ' . html_entity_decode($result['text'], ENT_NOQUOTES, 'UTF-8') . "\n";
  305. }
  306.  
  307. $text .= "\n";
  308.  
  309. if ($order_query->row['customer_id']) {
  310. $text .= $language->get('text_invoice') . "\n";
  311. $text .= $order_query->row['store_url'] . 'index.php?route=account/invoice&order_id=' . $order_id . "\n\n";
  312. }
  313.  
  314. if ($order_download_query->num_rows) {
  315. $text .= $language->get('text_download') . "\n";
  316. $text .= $order_query->row['store_url'] . 'index.php?route=account/download' . "\n\n";
  317. }
  318.  
  319. if ($comment) {
  320. $text .= $language->get('text_comment') . "\n\n";
  321. $text .= $comment . "\n\n";
  322. }
  323.  
  324. $text .= $language->get('text_footer');
  325.  
  326. $mail = new Mail();
  327. $mail->protocol = $this->config->get('config_mail_protocol');
  328. $mail->hostname = $this->config->get('config_smtp_host');
  329. $mail->username = $this->config->get('config_smtp_username');
  330. $mail->password = $this->config->get('config_smtp_password');
  331. $mail->port = $this->config->get('config_smtp_port');
  332. $mail->timeout = $this->config->get('config_smtp_timeout');
  333. $mail->setTo($order_query->row['email']);
  334. $mail->setFrom($this->config->get('config_email'));
  335. $mail->setSender($order_query->row['store_name']);
  336. $mail->setSubject($subject);
  337. $mail->setHtml($html);
  338. $mail->setText(html_entity_decode($text, ENT_QUOTES, 'UTF-8'));
  339. $mail->addAttachment(DIR_IMAGE . $this->config->get('config_logo'));
  340. $mail->send();
  341.  
  342. if ($this->config->get('config_alert_mail')) {
  343. $text = $language->get('text_received') . "\n\n";
  344. $text .= $language->get('text_order_id') . ' ' . $order_id . "\n";
  345. $text .= $language->get('text_date_added') . ' ' . date($language->get('date_format_short'), strtotime($order_query->row['date_added'])) . "\n";
  346. $text .= $language->get('text_order_status') . ' ' . $order_status_query->row['name'] . "\n\n";
  347. $text .= $language->get('text_product') . "\n";
  348.  
  349. foreach ($order_product_query->rows as $result) {
  350. $text .= $result['quantity'] . 'x ' . $result['name'] . ' (' . $result['model'] . ') ' . html_entity_decode($this->currency->format($result['total'], $order_query->row['currency'], $order_query->row['value']), ENT_NOQUOTES, 'UTF-8') . "\n";
  351. }
  352.  
  353. $text .= "\n";
  354.  
  355. $text.= $language->get('text_total') . "\n";
  356.  
  357. foreach ($order_total_query->rows as $result) {
  358. $text .= $result['title'] . ' ' . html_entity_decode($result['text'], ENT_NOQUOTES, 'UTF-8') . "\n";
  359. }
  360.  
  361. $text .= "\n";
  362.  
  363. if ($comment) {
  364. $text .= $language->get('text_comment') . "\n\n";
  365. $text .= $comment . "\n\n";
  366. }
  367.  
  368. $mail = new Mail();
  369. $mail->protocol = $this->config->get('config_mail_protocol');
  370. $mail->hostname = $this->config->get('config_smtp_host');
  371. $mail->username = $this->config->get('config_smtp_username');
  372. $mail->password = $this->config->get('config_smtp_password');
  373. $mail->port = $this->config->get('config_smtp_port');
  374. $mail->timeout = $this->config->get('config_smtp_timeout');
  375. $mail->setTo($this->config->get('config_email'));
  376. $mail->setFrom($this->config->get('config_email'));
  377. $mail->setSender($order_query->row['store_name']);
  378. $mail->setSubject($subject);
  379. $mail->setText($text);
  380. $mail->send();
  381. }
  382. }
  383. }
  384.  
  385. public function update($order_id, $order_status_id, $comment = '', $notify = FALSE) {
  386. $order_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order` o LEFT JOIN " . DB_PREFIX . "language l ON (o.language_id = l.language_id) WHERE o.order_id = '" . (int)$order_id . "' AND o.order_status_id > '0'");
  387.  
  388. if ($order_query->num_rows) {
  389. $this->db->query("UPDATE `" . DB_PREFIX . "order` SET order_status_id = '" . (int)$order_status_id . "', date_modified = NOW() WHERE order_id = '" . (int)$order_id . "'");
  390.  
  391. $this->db->query("INSERT INTO " . DB_PREFIX . "order_history SET order_id = '" . (int)$order_id . "', order_status_id = '" . (int)$order_status_id . "', notify = '" . (int)$notify . "', comment = '" . $this->db->escape($comment) . "', date_added = NOW()");
  392.  
  393. if ($notify) {
  394. $language = new Language($order_query->row['directory']);
  395. $language->load($order_query->row['filename']);
  396. $language->load('mail/order_update');
  397.  
  398. $subject = sprintf($language->get('text_subject'), html_entity_decode($order_query->row['store_name'], ENT_QUOTES, 'UTF-8'), $order_id);
  399.  
  400. $message = $language->get('text_order') . ' ' . $order_id . "\n";
  401. $message .= $language->get('text_date_added') . ' ' . date($language->get('date_format_short'), strtotime($order_query->row['date_added'])) . "\n\n";
  402.  
  403. $order_status_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_status WHERE order_status_id = '" . (int)$order_status_id . "' AND language_id = '" . (int)$order_query->row['language_id'] . "'");
  404.  
  405. if ($order_status_query->num_rows) {
  406. $message .= $language->get('text_order_status') . "\n\n";
  407. $message .= $order_status_query->row['name'] . "\n\n";
  408. }
  409.  
  410. $message .= $language->get('text_invoice') . "\n";
  411. $message .= $order_query->row['store_url'] . 'index.php?route=account/invoice&order_id=' . $order_id . "\n\n";
  412.  
  413. if ($comment) {
  414. $message .= $language->get('text_comment') . "\n\n";
  415. $message .= $comment . "\n\n";
  416. }
  417.  
  418. $message .= $language->get('text_footer');
  419.  
  420. $mail = new Mail();
  421. $mail->protocol = $this->config->get('config_mail_protocol');
  422. $mail->hostname = $this->config->get('config_smtp_host');
  423. $mail->username = $this->config->get('config_smtp_username');
  424. $mail->password = $this->config->get('config_smtp_password');
  425. $mail->port = $this->config->get('config_smtp_port');
  426. $mail->timeout = $this->config->get('config_smtp_timeout');
  427. $mail->setTo($order_query->row['email']);
  428. $mail->setFrom($this->config->get('config_email'));
  429. $mail->setSender($order_query->row['store_name']);
  430. $mail->setSubject($subject);
  431. $mail->setText(html_entity_decode($message, ENT_QUOTES, 'UTF-8'));
  432. $mail->send();
  433. }
  434. }
  435. }
  436. }
  437. ?>
Add Comment
Please, Sign In to add comment