PageRenderTime 65ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/admin/controller/sale/order.php

https://github.com/zahidiub/yahya
PHP | 2571 lines | 2033 code | 532 blank | 6 comment | 468 complexity | 1b952441772512d6ca81fe723f6a74fa MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. class ControllerSaleOrder extends Controller {
  3. private $error = array();
  4. public function index() {
  5. $this->language->load('sale/order');
  6. $this->document->setTitle($this->language->get('heading_title'));
  7. $this->load->model('sale/order');
  8. $this->getList();
  9. }
  10. public function insert() {
  11. $this->language->load('sale/order');
  12. $this->document->setTitle($this->language->get('heading_title'));
  13. $this->load->model('sale/order');
  14. if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
  15. $this->model_sale_order->addOrder($this->request->post);
  16. $this->session->data['success'] = $this->language->get('text_success');
  17. $url = '';
  18. if (isset($this->request->get['filter_order_id'])) {
  19. $url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
  20. }
  21. if (isset($this->request->get['filter_customer'])) {
  22. $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
  23. }
  24. if (isset($this->request->get['filter_order_status_id'])) {
  25. $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id'];
  26. }
  27. if (isset($this->request->get['filter_total'])) {
  28. $url .= '&filter_total=' . $this->request->get['filter_total'];
  29. }
  30. if (isset($this->request->get['filter_date_added'])) {
  31. $url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
  32. }
  33. if (isset($this->request->get['filter_date_modified'])) {
  34. $url .= '&filter_date_modified=' . $this->request->get['filter_date_modified'];
  35. }
  36. if (isset($this->request->get['sort'])) {
  37. $url .= '&sort=' . $this->request->get['sort'];
  38. }
  39. if (isset($this->request->get['order'])) {
  40. $url .= '&order=' . $this->request->get['order'];
  41. }
  42. if (isset($this->request->get['page'])) {
  43. $url .= '&page=' . $this->request->get['page'];
  44. }
  45. $this->redirect($this->url->link('sale/order', 'token=' . $this->session->data['token'] . $url, 'SSL'));
  46. }
  47. $this->getForm();
  48. }
  49. public function update() {
  50. $this->language->load('sale/order');
  51. $this->document->setTitle($this->language->get('heading_title'));
  52. $this->load->model('sale/order');
  53. if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
  54. $this->model_sale_order->editOrder($this->request->get['order_id'], $this->request->post);
  55. $this->session->data['success'] = $this->language->get('text_success');
  56. $url = '';
  57. if (isset($this->request->get['filter_order_id'])) {
  58. $url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
  59. }
  60. if (isset($this->request->get['filter_customer'])) {
  61. $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
  62. }
  63. if (isset($this->request->get['filter_order_status_id'])) {
  64. $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id'];
  65. }
  66. if (isset($this->request->get['filter_total'])) {
  67. $url .= '&filter_total=' . $this->request->get['filter_total'];
  68. }
  69. if (isset($this->request->get['filter_date_added'])) {
  70. $url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
  71. }
  72. if (isset($this->request->get['filter_date_modified'])) {
  73. $url .= '&filter_date_modified=' . $this->request->get['filter_date_modified'];
  74. }
  75. if (isset($this->request->get['sort'])) {
  76. $url .= '&sort=' . $this->request->get['sort'];
  77. }
  78. if (isset($this->request->get['order'])) {
  79. $url .= '&order=' . $this->request->get['order'];
  80. }
  81. if (isset($this->request->get['page'])) {
  82. $url .= '&page=' . $this->request->get['page'];
  83. }
  84. $this->redirect($this->url->link('sale/order', 'token=' . $this->session->data['token'] . $url, 'SSL'));
  85. }
  86. $this->getForm();
  87. }
  88. public function delete() {
  89. $this->language->load('sale/order');
  90. $this->document->setTitle($this->language->get('heading_title'));
  91. $this->load->model('sale/order');
  92. if (isset($this->request->post['selected']) && ($this->validateDelete())) {
  93. foreach ($this->request->post['selected'] as $order_id) {
  94. $this->model_sale_order->deleteOrder($order_id);
  95. $this->openbay->deleteOrder($order_id);
  96. }
  97. $this->session->data['success'] = $this->language->get('text_success');
  98. $url = '';
  99. if (isset($this->request->get['filter_order_id'])) {
  100. $url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
  101. }
  102. if (isset($this->request->get['filter_customer'])) {
  103. $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
  104. }
  105. if (isset($this->request->get['filter_order_status_id'])) {
  106. $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id'];
  107. }
  108. if (isset($this->request->get['filter_total'])) {
  109. $url .= '&filter_total=' . $this->request->get['filter_total'];
  110. }
  111. if (isset($this->request->get['filter_date_added'])) {
  112. $url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
  113. }
  114. if (isset($this->request->get['filter_date_modified'])) {
  115. $url .= '&filter_date_modified=' . $this->request->get['filter_date_modified'];
  116. }
  117. if (isset($this->request->get['sort'])) {
  118. $url .= '&sort=' . $this->request->get['sort'];
  119. }
  120. if (isset($this->request->get['order'])) {
  121. $url .= '&order=' . $this->request->get['order'];
  122. }
  123. if (isset($this->request->get['page'])) {
  124. $url .= '&page=' . $this->request->get['page'];
  125. }
  126. $this->redirect($this->url->link('sale/order', 'token=' . $this->session->data['token'] . $url, 'SSL'));
  127. }
  128. $this->getList();
  129. }
  130. protected function getList() {
  131. if (isset($this->request->get['filter_order_id'])) {
  132. $filter_order_id = $this->request->get['filter_order_id'];
  133. } else {
  134. $filter_order_id = null;
  135. }
  136. if (isset($this->request->get['filter_customer'])) {
  137. $filter_customer = $this->request->get['filter_customer'];
  138. } else {
  139. $filter_customer = null;
  140. }
  141. if (isset($this->request->get['filter_order_status_id'])) {
  142. $filter_order_status_id = $this->request->get['filter_order_status_id'];
  143. } else {
  144. $filter_order_status_id = null;
  145. }
  146. if (isset($this->request->get['filter_total'])) {
  147. $filter_total = $this->request->get['filter_total'];
  148. } else {
  149. $filter_total = null;
  150. }
  151. if (isset($this->request->get['filter_date_added'])) {
  152. $filter_date_added = $this->request->get['filter_date_added'];
  153. } else {
  154. $filter_date_added = null;
  155. }
  156. if (isset($this->request->get['filter_date_modified'])) {
  157. $filter_date_modified = $this->request->get['filter_date_modified'];
  158. } else {
  159. $filter_date_modified = null;
  160. }
  161. if (isset($this->request->get['sort'])) {
  162. $sort = $this->request->get['sort'];
  163. } else {
  164. $sort = 'o.order_id';
  165. }
  166. if (isset($this->request->get['order'])) {
  167. $order = $this->request->get['order'];
  168. } else {
  169. $order = 'DESC';
  170. }
  171. if (isset($this->request->get['page'])) {
  172. $page = $this->request->get['page'];
  173. } else {
  174. $page = 1;
  175. }
  176. $url = '';
  177. if (isset($this->request->get['filter_order_id'])) {
  178. $url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
  179. }
  180. if (isset($this->request->get['filter_customer'])) {
  181. $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
  182. }
  183. if (isset($this->request->get['filter_order_status_id'])) {
  184. $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id'];
  185. }
  186. if (isset($this->request->get['filter_total'])) {
  187. $url .= '&filter_total=' . $this->request->get['filter_total'];
  188. }
  189. if (isset($this->request->get['filter_date_added'])) {
  190. $url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
  191. }
  192. if (isset($this->request->get['filter_date_modified'])) {
  193. $url .= '&filter_date_modified=' . $this->request->get['filter_date_modified'];
  194. }
  195. if (isset($this->request->get['sort'])) {
  196. $url .= '&sort=' . $this->request->get['sort'];
  197. }
  198. if (isset($this->request->get['order'])) {
  199. $url .= '&order=' . $this->request->get['order'];
  200. }
  201. if (isset($this->request->get['page'])) {
  202. $url .= '&page=' . $this->request->get['page'];
  203. }
  204. $this->data['breadcrumbs'] = array();
  205. $this->data['breadcrumbs'][] = array(
  206. 'text' => $this->language->get('text_home'),
  207. 'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
  208. 'separator' => false
  209. );
  210. $this->data['breadcrumbs'][] = array(
  211. 'text' => $this->language->get('heading_title'),
  212. 'href' => $this->url->link('sale/order', 'token=' . $this->session->data['token'] . $url, 'SSL'),
  213. 'separator' => ' :: '
  214. );
  215. $this->data['invoice'] = $this->url->link('sale/order/invoice', 'token=' . $this->session->data['token'], 'SSL');
  216. $this->data['insert'] = $this->url->link('sale/order/insert', 'token=' . $this->session->data['token'], 'SSL');
  217. $this->data['delete'] = $this->url->link('sale/order/delete', 'token=' . $this->session->data['token'] . $url, 'SSL');
  218. $this->data['orders'] = array();
  219. $data = array(
  220. 'filter_order_id' => $filter_order_id,
  221. 'filter_customer' => $filter_customer,
  222. 'filter_order_status_id' => $filter_order_status_id,
  223. 'filter_total' => $filter_total,
  224. 'filter_date_added' => $filter_date_added,
  225. 'filter_date_modified' => $filter_date_modified,
  226. 'sort' => $sort,
  227. 'order' => $order,
  228. 'start' => ($page - 1) * $this->config->get('config_admin_limit'),
  229. 'limit' => $this->config->get('config_admin_limit')
  230. );
  231. $order_total = $this->model_sale_order->getTotalOrders($data);
  232. $results = $this->model_sale_order->getOrders($data);
  233. foreach ($results as $result) {
  234. $action = array();
  235. $action[] = array(
  236. 'text' => $this->language->get('text_view'),
  237. 'href' => $this->url->link('sale/order/info', 'token=' . $this->session->data['token'] . '&order_id=' . $result['order_id'] . $url, 'SSL')
  238. );
  239. if (strtotime($result['date_added']) > strtotime('-' . (int)$this->config->get('config_order_edit') . ' day')) {
  240. $action[] = array(
  241. 'text' => $this->language->get('text_edit'),
  242. 'href' => $this->url->link('sale/order/update', 'token=' . $this->session->data['token'] . '&order_id=' . $result['order_id'] . $url, 'SSL')
  243. );
  244. }
  245. $this->data['orders'][] = array(
  246. 'order_id' => $result['order_id'],
  247. 'customer' => $result['customer'],
  248. 'status' => $result['status'],
  249. 'total' => $this->currency->format($result['total'], $result['currency_code'], $result['currency_value']),
  250. 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
  251. 'date_modified' => date($this->language->get('date_format_short'), strtotime($result['date_modified'])),
  252. 'selected' => isset($this->request->post['selected']) && in_array($result['order_id'], $this->request->post['selected']),
  253. 'action' => $action
  254. );
  255. }
  256. $this->data['heading_title'] = $this->language->get('heading_title');
  257. $this->data['text_no_results'] = $this->language->get('text_no_results');
  258. $this->data['text_missing'] = $this->language->get('text_missing');
  259. $this->data['column_order_id'] = $this->language->get('column_order_id');
  260. $this->data['column_customer'] = $this->language->get('column_customer');
  261. $this->data['column_status'] = $this->language->get('column_status');
  262. $this->data['column_total'] = $this->language->get('column_total');
  263. $this->data['column_date_added'] = $this->language->get('column_date_added');
  264. $this->data['column_date_modified'] = $this->language->get('column_date_modified');
  265. $this->data['column_action'] = $this->language->get('column_action');
  266. $this->data['button_invoice'] = $this->language->get('button_invoice');
  267. $this->data['button_insert'] = $this->language->get('button_insert');
  268. $this->data['button_delete'] = $this->language->get('button_delete');
  269. $this->data['button_filter'] = $this->language->get('button_filter');
  270. $this->data['token'] = $this->session->data['token'];
  271. if (isset($this->error['warning'])) {
  272. $this->data['error_warning'] = $this->error['warning'];
  273. } else {
  274. $this->data['error_warning'] = '';
  275. }
  276. if (isset($this->session->data['success'])) {
  277. $this->data['success'] = $this->session->data['success'];
  278. unset($this->session->data['success']);
  279. } else {
  280. $this->data['success'] = '';
  281. }
  282. $url = '';
  283. if (isset($this->request->get['filter_order_id'])) {
  284. $url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
  285. }
  286. if (isset($this->request->get['filter_customer'])) {
  287. $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
  288. }
  289. if (isset($this->request->get['filter_order_status_id'])) {
  290. $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id'];
  291. }
  292. if (isset($this->request->get['filter_total'])) {
  293. $url .= '&filter_total=' . $this->request->get['filter_total'];
  294. }
  295. if (isset($this->request->get['filter_date_added'])) {
  296. $url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
  297. }
  298. if (isset($this->request->get['filter_date_modified'])) {
  299. $url .= '&filter_date_modified=' . $this->request->get['filter_date_modified'];
  300. }
  301. if ($order == 'ASC') {
  302. $url .= '&order=DESC';
  303. } else {
  304. $url .= '&order=ASC';
  305. }
  306. if (isset($this->request->get['page'])) {
  307. $url .= '&page=' . $this->request->get['page'];
  308. }
  309. $this->data['sort_order'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . '&sort=o.order_id' . $url, 'SSL');
  310. $this->data['sort_customer'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . '&sort=customer' . $url, 'SSL');
  311. $this->data['sort_status'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . '&sort=status' . $url, 'SSL');
  312. $this->data['sort_total'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . '&sort=o.total' . $url, 'SSL');
  313. $this->data['sort_date_added'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . '&sort=o.date_added' . $url, 'SSL');
  314. $this->data['sort_date_modified'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . '&sort=o.date_modified' . $url, 'SSL');
  315. $url = '';
  316. if (isset($this->request->get['filter_order_id'])) {
  317. $url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
  318. }
  319. if (isset($this->request->get['filter_customer'])) {
  320. $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
  321. }
  322. if (isset($this->request->get['filter_order_status_id'])) {
  323. $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id'];
  324. }
  325. if (isset($this->request->get['filter_total'])) {
  326. $url .= '&filter_total=' . $this->request->get['filter_total'];
  327. }
  328. if (isset($this->request->get['filter_date_added'])) {
  329. $url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
  330. }
  331. if (isset($this->request->get['filter_date_modified'])) {
  332. $url .= '&filter_date_modified=' . $this->request->get['filter_date_modified'];
  333. }
  334. if (isset($this->request->get['sort'])) {
  335. $url .= '&sort=' . $this->request->get['sort'];
  336. }
  337. if (isset($this->request->get['order'])) {
  338. $url .= '&order=' . $this->request->get['order'];
  339. }
  340. $pagination = new Pagination();
  341. $pagination->total = $order_total;
  342. $pagination->page = $page;
  343. $pagination->limit = $this->config->get('config_admin_limit');
  344. $pagination->text = $this->language->get('text_pagination');
  345. $pagination->url = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . $url . '&page={page}', 'SSL');
  346. $this->data['pagination'] = $pagination->render();
  347. $this->data['filter_order_id'] = $filter_order_id;
  348. $this->data['filter_customer'] = $filter_customer;
  349. $this->data['filter_order_status_id'] = $filter_order_status_id;
  350. $this->data['filter_total'] = $filter_total;
  351. $this->data['filter_date_added'] = $filter_date_added;
  352. $this->data['filter_date_modified'] = $filter_date_modified;
  353. $this->load->model('localisation/order_status');
  354. $this->data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
  355. $this->data['sort'] = $sort;
  356. $this->data['order'] = $order;
  357. $this->template = 'sale/order_list.tpl';
  358. $this->children = array(
  359. 'common/header',
  360. 'common/footer'
  361. );
  362. $this->response->setOutput($this->render());
  363. }
  364. public function getForm() {
  365. $this->load->model('sale/customer');
  366. $this->data['heading_title'] = $this->language->get('heading_title');
  367. $this->data['text_no_results'] = $this->language->get('text_no_results');
  368. $this->data['text_default'] = $this->language->get('text_default');
  369. $this->data['text_select'] = $this->language->get('text_select');
  370. $this->data['text_none'] = $this->language->get('text_none');
  371. $this->data['text_wait'] = $this->language->get('text_wait');
  372. $this->data['text_product'] = $this->language->get('text_product');
  373. $this->data['text_voucher'] = $this->language->get('text_voucher');
  374. $this->data['text_order'] = $this->language->get('text_order');
  375. $this->data['entry_store'] = $this->language->get('entry_store');
  376. $this->data['entry_customer'] = $this->language->get('entry_customer');
  377. $this->data['entry_customer_group'] = $this->language->get('entry_customer_group');
  378. $this->data['entry_firstname'] = $this->language->get('entry_firstname');
  379. $this->data['entry_lastname'] = $this->language->get('entry_lastname');
  380. $this->data['entry_email'] = $this->language->get('entry_email');
  381. $this->data['entry_telephone'] = $this->language->get('entry_telephone');
  382. $this->data['entry_fax'] = $this->language->get('entry_fax');
  383. $this->data['entry_order_status'] = $this->language->get('entry_order_status');
  384. $this->data['entry_comment'] = $this->language->get('entry_comment');
  385. $this->data['entry_affiliate'] = $this->language->get('entry_affiliate');
  386. $this->data['entry_address'] = $this->language->get('entry_address');
  387. $this->data['entry_company'] = $this->language->get('entry_company');
  388. $this->data['entry_company_id'] = $this->language->get('entry_company_id');
  389. $this->data['entry_tax_id'] = $this->language->get('entry_tax_id');
  390. $this->data['entry_address_1'] = $this->language->get('entry_address_1');
  391. $this->data['entry_address_2'] = $this->language->get('entry_address_2');
  392. $this->data['entry_city'] = $this->language->get('entry_city');
  393. $this->data['entry_postcode'] = $this->language->get('entry_postcode');
  394. $this->data['entry_zone'] = $this->language->get('entry_zone');
  395. $this->data['entry_zone_code'] = $this->language->get('entry_zone_code');
  396. $this->data['entry_country'] = $this->language->get('entry_country');
  397. $this->data['entry_product'] = $this->language->get('entry_product');
  398. $this->data['entry_option'] = $this->language->get('entry_option');
  399. $this->data['entry_quantity'] = $this->language->get('entry_quantity');
  400. $this->data['entry_to_name'] = $this->language->get('entry_to_name');
  401. $this->data['entry_to_email'] = $this->language->get('entry_to_email');
  402. $this->data['entry_from_name'] = $this->language->get('entry_from_name');
  403. $this->data['entry_from_email'] = $this->language->get('entry_from_email');
  404. $this->data['entry_theme'] = $this->language->get('entry_theme');
  405. $this->data['entry_message'] = $this->language->get('entry_message');
  406. $this->data['entry_amount'] = $this->language->get('entry_amount');
  407. $this->data['entry_shipping'] = $this->language->get('entry_shipping');
  408. $this->data['entry_payment'] = $this->language->get('entry_payment');
  409. $this->data['entry_voucher'] = $this->language->get('entry_voucher');
  410. $this->data['entry_coupon'] = $this->language->get('entry_coupon');
  411. $this->data['entry_reward'] = $this->language->get('entry_reward');
  412. $this->data['column_product'] = $this->language->get('column_product');
  413. $this->data['column_model'] = $this->language->get('column_model');
  414. $this->data['column_quantity'] = $this->language->get('column_quantity');
  415. $this->data['column_price'] = $this->language->get('column_price');
  416. $this->data['column_total'] = $this->language->get('column_total');
  417. $this->data['button_save'] = $this->language->get('button_save');
  418. $this->data['button_cancel'] = $this->language->get('button_cancel');
  419. $this->data['button_add_product'] = $this->language->get('button_add_product');
  420. $this->data['button_add_voucher'] = $this->language->get('button_add_voucher');
  421. $this->data['button_update_total'] = $this->language->get('button_update_total');
  422. $this->data['button_remove'] = $this->language->get('button_remove');
  423. $this->data['button_upload'] = $this->language->get('button_upload');
  424. $this->data['tab_order'] = $this->language->get('tab_order');
  425. $this->data['tab_customer'] = $this->language->get('tab_customer');
  426. $this->data['tab_payment'] = $this->language->get('tab_payment');
  427. $this->data['tab_shipping'] = $this->language->get('tab_shipping');
  428. $this->data['tab_product'] = $this->language->get('tab_product');
  429. $this->data['tab_voucher'] = $this->language->get('tab_voucher');
  430. $this->data['tab_total'] = $this->language->get('tab_total');
  431. if (isset($this->error['warning'])) {
  432. $this->data['error_warning'] = $this->error['warning'];
  433. } else {
  434. $this->data['error_warning'] = '';
  435. }
  436. if (isset($this->error['firstname'])) {
  437. $this->data['error_firstname'] = $this->error['firstname'];
  438. } else {
  439. $this->data['error_firstname'] = '';
  440. }
  441. if (isset($this->error['lastname'])) {
  442. $this->data['error_lastname'] = $this->error['lastname'];
  443. } else {
  444. $this->data['error_lastname'] = '';
  445. }
  446. if (isset($this->error['email'])) {
  447. $this->data['error_email'] = $this->error['email'];
  448. } else {
  449. $this->data['error_email'] = '';
  450. }
  451. if (isset($this->error['telephone'])) {
  452. $this->data['error_telephone'] = $this->error['telephone'];
  453. } else {
  454. $this->data['error_telephone'] = '';
  455. }
  456. if (isset($this->error['payment_firstname'])) {
  457. $this->data['error_payment_firstname'] = $this->error['payment_firstname'];
  458. } else {
  459. $this->data['error_payment_firstname'] = '';
  460. }
  461. if (isset($this->error['payment_lastname'])) {
  462. $this->data['error_payment_lastname'] = $this->error['payment_lastname'];
  463. } else {
  464. $this->data['error_payment_lastname'] = '';
  465. }
  466. if (isset($this->error['payment_address_1'])) {
  467. $this->data['error_payment_address_1'] = $this->error['payment_address_1'];
  468. } else {
  469. $this->data['error_payment_address_1'] = '';
  470. }
  471. if (isset($this->error['payment_city'])) {
  472. $this->data['error_payment_city'] = $this->error['payment_city'];
  473. } else {
  474. $this->data['error_payment_city'] = '';
  475. }
  476. if (isset($this->error['payment_postcode'])) {
  477. $this->data['error_payment_postcode'] = $this->error['payment_postcode'];
  478. } else {
  479. $this->data['error_payment_postcode'] = '';
  480. }
  481. if (isset($this->error['payment_tax_id'])) {
  482. $this->data['error_payment_tax_id'] = $this->error['payment_tax_id'];
  483. } else {
  484. $this->data['error_payment_tax_id'] = '';
  485. }
  486. if (isset($this->error['payment_country'])) {
  487. $this->data['error_payment_country'] = $this->error['payment_country'];
  488. } else {
  489. $this->data['error_payment_country'] = '';
  490. }
  491. if (isset($this->error['payment_zone'])) {
  492. $this->data['error_payment_zone'] = $this->error['payment_zone'];
  493. } else {
  494. $this->data['error_payment_zone'] = '';
  495. }
  496. if (isset($this->error['payment_method'])) {
  497. $this->data['error_payment_method'] = $this->error['payment_method'];
  498. } else {
  499. $this->data['error_payment_method'] = '';
  500. }
  501. if (isset($this->error['shipping_firstname'])) {
  502. $this->data['error_shipping_firstname'] = $this->error['shipping_firstname'];
  503. } else {
  504. $this->data['error_shipping_firstname'] = '';
  505. }
  506. if (isset($this->error['shipping_lastname'])) {
  507. $this->data['error_shipping_lastname'] = $this->error['shipping_lastname'];
  508. } else {
  509. $this->data['error_shipping_lastname'] = '';
  510. }
  511. if (isset($this->error['shipping_address_1'])) {
  512. $this->data['error_shipping_address_1'] = $this->error['shipping_address_1'];
  513. } else {
  514. $this->data['error_shipping_address_1'] = '';
  515. }
  516. if (isset($this->error['shipping_city'])) {
  517. $this->data['error_shipping_city'] = $this->error['shipping_city'];
  518. } else {
  519. $this->data['error_shipping_city'] = '';
  520. }
  521. if (isset($this->error['shipping_postcode'])) {
  522. $this->data['error_shipping_postcode'] = $this->error['shipping_postcode'];
  523. } else {
  524. $this->data['error_shipping_postcode'] = '';
  525. }
  526. if (isset($this->error['shipping_country'])) {
  527. $this->data['error_shipping_country'] = $this->error['shipping_country'];
  528. } else {
  529. $this->data['error_shipping_country'] = '';
  530. }
  531. if (isset($this->error['shipping_zone'])) {
  532. $this->data['error_shipping_zone'] = $this->error['shipping_zone'];
  533. } else {
  534. $this->data['error_shipping_zone'] = '';
  535. }
  536. if (isset($this->error['shipping_method'])) {
  537. $this->data['error_shipping_method'] = $this->error['shipping_method'];
  538. } else {
  539. $this->data['error_shipping_method'] = '';
  540. }
  541. $url = '';
  542. if (isset($this->request->get['filter_order_id'])) {
  543. $url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
  544. }
  545. if (isset($this->request->get['filter_customer'])) {
  546. $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
  547. }
  548. if (isset($this->request->get['filter_order_status_id'])) {
  549. $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id'];
  550. }
  551. if (isset($this->request->get['filter_total'])) {
  552. $url .= '&filter_total=' . $this->request->get['filter_total'];
  553. }
  554. if (isset($this->request->get['filter_date_added'])) {
  555. $url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
  556. }
  557. if (isset($this->request->get['filter_date_modified'])) {
  558. $url .= '&filter_date_modified=' . $this->request->get['filter_date_modified'];
  559. }
  560. if (isset($this->request->get['sort'])) {
  561. $url .= '&sort=' . $this->request->get['sort'];
  562. }
  563. if (isset($this->request->get['order'])) {
  564. $url .= '&order=' . $this->request->get['order'];
  565. }
  566. if (isset($this->request->get['page'])) {
  567. $url .= '&page=' . $this->request->get['page'];
  568. }
  569. $this->data['breadcrumbs'] = array();
  570. $this->data['breadcrumbs'][] = array(
  571. 'text' => $this->language->get('text_home'),
  572. 'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
  573. 'separator' => false
  574. );
  575. $this->data['breadcrumbs'][] = array(
  576. 'text' => $this->language->get('heading_title'),
  577. 'href' => $this->url->link('sale/order', 'token=' . $this->session->data['token'] . $url, 'SSL'),
  578. 'separator' => ' :: '
  579. );
  580. if (!isset($this->request->get['order_id'])) {
  581. $this->data['action'] = $this->url->link('sale/order/insert', 'token=' . $this->session->data['token'] . $url, 'SSL');
  582. } else {
  583. $this->data['action'] = $this->url->link('sale/order/update', 'token=' . $this->session->data['token'] . '&order_id=' . $this->request->get['order_id'] . $url, 'SSL');
  584. }
  585. $this->data['cancel'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . $url, 'SSL');
  586. if (isset($this->request->get['order_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
  587. $order_info = $this->model_sale_order->getOrder($this->request->get['order_id']);
  588. }
  589. $this->data['token'] = $this->session->data['token'];
  590. if (isset($this->request->get['order_id'])) {
  591. $this->data['order_id'] = $this->request->get['order_id'];
  592. } else {
  593. $this->data['order_id'] = 0;
  594. }
  595. if (isset($this->request->post['store_id'])) {
  596. $this->data['store_id'] = $this->request->post['store_id'];
  597. } elseif (!empty($order_info)) {
  598. $this->data['store_id'] = $order_info['store_id'];
  599. } else {
  600. $this->data['store_id'] = '';
  601. }
  602. $this->load->model('setting/store');
  603. $this->data['stores'] = $this->model_setting_store->getStores();
  604. if (isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == 'on') || ($this->request->server['HTTPS'] == '1'))) {
  605. $this->data['store_url'] = HTTPS_CATALOG;
  606. } else {
  607. $this->data['store_url'] = HTTP_CATALOG;
  608. }
  609. if (isset($this->request->post['customer'])) {
  610. $this->data['customer'] = $this->request->post['customer'];
  611. } elseif (!empty($order_info)) {
  612. $this->data['customer'] = $order_info['customer'];
  613. } else {
  614. $this->data['customer'] = '';
  615. }
  616. if (isset($this->request->post['customer_id'])) {
  617. $this->data['customer_id'] = $this->request->post['customer_id'];
  618. } elseif (!empty($order_info)) {
  619. $this->data['customer_id'] = $order_info['customer_id'];
  620. } else {
  621. $this->data['customer_id'] = '';
  622. }
  623. if (isset($this->request->post['customer_group_id'])) {
  624. $this->data['customer_group_id'] = $this->request->post['customer_group_id'];
  625. } elseif (!empty($order_info)) {
  626. $this->data['customer_group_id'] = $order_info['customer_group_id'];
  627. } else {
  628. $this->data['customer_group_id'] = '';
  629. }
  630. $this->load->model('sale/customer_group');
  631. $this->data['customer_groups'] = $this->model_sale_customer_group->getCustomerGroups();
  632. if (isset($this->request->post['firstname'])) {
  633. $this->data['firstname'] = $this->request->post['firstname'];
  634. } elseif (!empty($order_info)) {
  635. $this->data['firstname'] = $order_info['firstname'];
  636. } else {
  637. $this->data['firstname'] = '';
  638. }
  639. if (isset($this->request->post['lastname'])) {
  640. $this->data['lastname'] = $this->request->post['lastname'];
  641. } elseif (!empty($order_info)) {
  642. $this->data['lastname'] = $order_info['lastname'];
  643. } else {
  644. $this->data['lastname'] = '';
  645. }
  646. if (isset($this->request->post['email'])) {
  647. $this->data['email'] = $this->request->post['email'];
  648. } elseif (!empty($order_info)) {
  649. $this->data['email'] = $order_info['email'];
  650. } else {
  651. $this->data['email'] = '';
  652. }
  653. if (isset($this->request->post['telephone'])) {
  654. $this->data['telephone'] = $this->request->post['telephone'];
  655. } elseif (!empty($order_info)) {
  656. $this->data['telephone'] = $order_info['telephone'];
  657. } else {
  658. $this->data['telephone'] = '';
  659. }
  660. if (isset($this->request->post['fax'])) {
  661. $this->data['fax'] = $this->request->post['fax'];
  662. } elseif (!empty($order_info)) {
  663. $this->data['fax'] = $order_info['fax'];
  664. } else {
  665. $this->data['fax'] = '';
  666. }
  667. if (isset($this->request->post['affiliate_id'])) {
  668. $this->data['affiliate_id'] = $this->request->post['affiliate_id'];
  669. } elseif (!empty($order_info)) {
  670. $this->data['affiliate_id'] = $order_info['affiliate_id'];
  671. } else {
  672. $this->data['affiliate_id'] = '';
  673. }
  674. if (isset($this->request->post['affiliate'])) {
  675. $this->data['affiliate'] = $this->request->post['affiliate'];
  676. } elseif (!empty($order_info)) {
  677. $this->data['affiliate'] = ($order_info['affiliate_id'] ? $order_info['affiliate_firstname'] . ' ' . $order_info['affiliate_lastname'] : '');
  678. } else {
  679. $this->data['affiliate'] = '';
  680. }
  681. if (isset($this->request->post['order_status_id'])) {
  682. $this->data['order_status_id'] = $this->request->post['order_status_id'];
  683. } elseif (!empty($order_info)) {
  684. $this->data['order_status_id'] = $order_info['order_status_id'];
  685. } else {
  686. $this->data['order_status_id'] = '';
  687. }
  688. $this->load->model('localisation/order_status');
  689. $this->data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
  690. if (isset($this->request->post['comment'])) {
  691. $this->data['comment'] = $this->request->post['comment'];
  692. } elseif (!empty($order_info)) {
  693. $this->data['comment'] = $order_info['comment'];
  694. } else {
  695. $this->data['comment'] = '';
  696. }
  697. $this->load->model('sale/customer');
  698. if (isset($this->request->post['customer_id'])) {
  699. $this->data['addresses'] = $this->model_sale_customer->getAddresses($this->request->post['customer_id']);
  700. } elseif (!empty($order_info)) {
  701. $this->data['addresses'] = $this->model_sale_customer->getAddresses($order_info['customer_id']);
  702. } else {
  703. $this->data['addresses'] = array();
  704. }
  705. if (isset($this->request->post['payment_firstname'])) {
  706. $this->data['payment_firstname'] = $this->request->post['payment_firstname'];
  707. } elseif (!empty($order_info)) {
  708. $this->data['payment_firstname'] = $order_info['payment_firstname'];
  709. } else {
  710. $this->data['payment_firstname'] = '';
  711. }
  712. if (isset($this->request->post['payment_lastname'])) {
  713. $this->data['payment_lastname'] = $this->request->post['payment_lastname'];
  714. } elseif (!empty($order_info)) {
  715. $this->data['payment_lastname'] = $order_info['payment_lastname'];
  716. } else {
  717. $this->data['payment_lastname'] = '';
  718. }
  719. if (isset($this->request->post['payment_company'])) {
  720. $this->data['payment_company'] = $this->request->post['payment_company'];
  721. } elseif (!empty($order_info)) {
  722. $this->data['payment_company'] = $order_info['payment_company'];
  723. } else {
  724. $this->data['payment_company'] = '';
  725. }
  726. if (isset($this->request->post['payment_company_id'])) {
  727. $this->data['payment_company_id'] = $this->request->post['payment_company_id'];
  728. } elseif (!empty($order_info)) {
  729. $this->data['payment_company_id'] = $order_info['payment_company_id'];
  730. } else {
  731. $this->data['payment_company_id'] = '';
  732. }
  733. if (isset($this->request->post['payment_tax_id'])) {
  734. $this->data['payment_tax_id'] = $this->request->post['payment_tax_id'];
  735. } elseif (!empty($order_info)) {
  736. $this->data['payment_tax_id'] = $order_info['payment_tax_id'];
  737. } else {
  738. $this->data['payment_tax_id'] = '';
  739. }
  740. if (isset($this->request->post['payment_address_1'])) {
  741. $this->data['payment_address_1'] = $this->request->post['payment_address_1'];
  742. } elseif (!empty($order_info)) {
  743. $this->data['payment_address_1'] = $order_info['payment_address_1'];
  744. } else {
  745. $this->data['payment_address_1'] = '';
  746. }
  747. if (isset($this->request->post['payment_address_2'])) {
  748. $this->data['payment_address_2'] = $this->request->post['payment_address_2'];
  749. } elseif (!empty($order_info)) {
  750. $this->data['payment_address_2'] = $order_info['payment_address_2'];
  751. } else {
  752. $this->data['payment_address_2'] = '';
  753. }
  754. if (isset($this->request->post['payment_city'])) {
  755. $this->data['payment_city'] = $this->request->post['payment_city'];
  756. } elseif (!empty($order_info)) {
  757. $this->data['payment_city'] = $order_info['payment_city'];
  758. } else {
  759. $this->data['payment_city'] = '';
  760. }
  761. if (isset($this->request->post['payment_postcode'])) {
  762. $this->data['payment_postcode'] = $this->request->post['payment_postcode'];
  763. } elseif (!empty($order_info)) {
  764. $this->data['payment_postcode'] = $order_info['payment_postcode'];
  765. } else {
  766. $this->data['payment_postcode'] = '';
  767. }
  768. if (isset($this->request->post['payment_country_id'])) {
  769. $this->data['payment_country_id'] = $this->request->post['payment_country_id'];
  770. } elseif (!empty($order_info)) {
  771. $this->data['payment_country_id'] = $order_info['payment_country_id'];
  772. } else {
  773. $this->data['payment_country_id'] = '';
  774. }
  775. if (isset($this->request->post['payment_zone_id'])) {
  776. $this->data['payment_zone_id'] = $this->request->post['payment_zone_id'];
  777. } elseif (!empty($order_info)) {
  778. $this->data['payment_zone_id'] = $order_info['payment_zone_id'];
  779. } else {
  780. $this->data['payment_zone_id'] = '';
  781. }
  782. if (isset($this->request->post['payment_method'])) {
  783. $this->data['payment_method'] = $this->request->post['payment_method'];
  784. } elseif (!empty($order_info)) {
  785. $this->data['payment_method'] = $order_info['payment_method'];
  786. } else {
  787. $this->data['payment_method'] = '';
  788. }
  789. if (isset($this->request->post['payment_code'])) {
  790. $this->data['payment_code'] = $this->request->post['payment_code'];
  791. } elseif (!empty($order_info)) {
  792. $this->data['payment_code'] = $order_info['payment_code'];
  793. } else {
  794. $this->data['payment_code'] = '';
  795. }
  796. if (isset($this->request->post['shipping_firstname'])) {
  797. $this->data['shipping_firstname'] = $this->request->post['shipping_firstname'];
  798. } elseif (!empty($order_info)) {
  799. $this->data['shipping_firstname'] = $order_info['shipping_firstname'];
  800. } else {
  801. $this->data['shipping_firstname'] = '';
  802. }
  803. if (isset($this->request->post['shipping_lastname'])) {
  804. $this->data['shipping_lastname'] = $this->request->post['shipping_lastname'];
  805. } elseif (!empty($order_info)) {
  806. $this->data['shipping_lastname'] = $order_info['shipping_lastname'];
  807. } else {
  808. $this->data['shipping_lastname'] = '';
  809. }
  810. if (isset($this->request->post['shipping_company'])) {
  811. $this->data['shipping_company'] = $this->request->post['shipping_company'];
  812. } elseif (!empty($order_info)) {
  813. $this->data['shipping_company'] = $order_info['shipping_company'];
  814. } else {
  815. $this->data['shipping_company'] = '';
  816. }
  817. if (isset($this->request->post['shipping_address_1'])) {
  818. $this->data['shipping_address_1'] = $this->request->post['shipping_address_1'];
  819. } elseif (!empty($order_info)) {
  820. $this->data['shipping_address_1'] = $order_info['shipping_address_1'];
  821. } else {
  822. $this->data['shipping_address_1'] = '';
  823. }
  824. if (isset($this->request->post['shipping_address_2'])) {
  825. $this->data['shipping_address_2'] = $this->request->post['shipping_address_2'];
  826. } elseif (!empty($order_info)) {
  827. $this->data['shipping_address_2'] = $order_info['shipping_address_2'];
  828. } else {
  829. $this->data['shipping_address_2'] = '';
  830. }
  831. if (isset($this->request->post['shipping_city'])) {
  832. $this->data['shipping_city'] = $this->request->post['shipping_city'];
  833. } elseif (!empty($order_info)) {
  834. $this->data['shipping_city'] = $order_info['shipping_city'];
  835. } else {
  836. $this->data['shipping_city'] = '';
  837. }
  838. if (isset($this->request->post['shipping_postcode'])) {
  839. $this->data['shipping_postcode'] = $this->request->post['shipping_postcode'];
  840. } elseif (!empty($order_info)) {
  841. $this->data['shipping_postcode'] = $order_info['shipping_postcode'];
  842. } else {
  843. $this->data['shipping_postcode'] = '';
  844. }
  845. if (isset($this->request->post['shipping_country_id'])) {
  846. $this->data['shipping_country_id'] = $this->request->post['shipping_country_id'];
  847. } elseif (!empty($order_info)) {
  848. $this->data['shipping_country_id'] = $order_info['shipping_country_id'];
  849. } else {
  850. $this->data['shipping_country_id'] = '';
  851. }
  852. if (isset($this->request->post['shipping_zone_id'])) {
  853. $this->data['shipping_zone_id'] = $this->request->post['shipping_zone_id'];
  854. } elseif (!empty($order_info)) {
  855. $this->data['shipping_zone_id'] = $order_info['shipping_zone_id'];
  856. } else {
  857. $this->data['shipping_zone_id'] = '';
  858. }
  859. $this->load->model('localisation/country');
  860. $this->data['countries'] = $this->model_localisation_country->getCountries();
  861. if (isset($this->request->post['shipping_method'])) {
  862. $this->data['shipping_method'] = $this->request->post['shipping_method'];
  863. } elseif (!empty($order_info)) {
  864. $this->data['shipping_method'] = $order_info['shipping_method'];
  865. } else {
  866. $this->data['shipping_method'] = '';
  867. }
  868. if (isset($this->request->post['shipping_code'])) {
  869. $this->data['shipping_code'] = $this->request->post['shipping_code'];
  870. } elseif (!empty($order_info)) {
  871. $this->data['shipping_code'] = $order_info['shipping_code'];
  872. } else {
  873. $this->data['shipping_code'] = '';
  874. }
  875. if (isset($this->request->post['order_product'])) {
  876. $order_products = $this->request->post['order_product'];
  877. } elseif (isset($this->request->get['order_id'])) {
  878. $order_products = $this->model_sale_order->getOrderProducts($this->request->get['order_id']);
  879. } else {
  880. $order_products = array();
  881. }
  882. $this->load->model('catalog/product');
  883. $this->document->addScript('view/javascript/jquery/ajaxupload.js');
  884. $this->data['order_products'] = array();
  885. foreach ($order_products as $order_product) {
  886. if (isset($order_product['order_option'])) {
  887. $order_option = $order_product['order_option'];
  888. } elseif (isset($this->request->get['order_id'])) {
  889. $order_option = $this->model_sale_order->getOrderOptions($this->request->get['order_id'], $order_product['order_product_id']);
  890. } else {
  891. $order_option = array();
  892. }
  893. if (isset($order_product['order_download'])) {
  894. $order_download = $order_product['order_download'];
  895. } elseif (isset($this->request->get['order_id'])) {
  896. $order_download = $this->model_sale_order->getOrderDownloads($this->request->get['order_id'], $order_product['order_product_id']);
  897. } else {
  898. $order_download = array();
  899. }
  900. $this->data['order_products'][] = array(
  901. 'order_product_id' => $order_product['order_product_id'],
  902. 'product_id' => $order_product['product_id'],
  903. 'name' => $order_product['name'],
  904. 'model' => $order_product['model'],
  905. 'option' => $order_option,
  906. 'download' => $order_download,
  907. 'quantity' => $order_product['quantity'],
  908. 'price' => $order_product['price'],
  909. 'total' => $order_product['total'],
  910. 'tax' => $order_product['tax'],
  911. 'reward' => $order_product['reward']
  912. );
  913. }
  914. if (isset($this->request->post['order_voucher'])) {
  915. $this->data['order_vouchers'] = $this->request->post['order_voucher'];
  916. } elseif (isset($this->request->get['order_id'])) {
  917. $this->data['order_vouchers'] = $this->model_sale_order->getOrderVouchers($this->request->get['order_id']);
  918. } else {
  919. $this->data['order_vouchers'] = array();
  920. }
  921. $this->load->model('sale/voucher_theme');
  922. $this->data['voucher_themes'] = $this->model_sale_voucher_theme->getVoucherThemes();
  923. if (isset($this->request->post['order_total'])) {
  924. $this->data['order_totals'] = $this->request->post['order_total'];
  925. } elseif (isset($this->request->get['order_id'])) {
  926. $this->data['order_totals'] = $this->model_sale_order->getOrderTotals($this->request->get['order_id']);
  927. } else {
  928. $this->data['order_totals'] = array();
  929. }
  930. $this->template = 'sale/order_form.tpl';
  931. $this->children = array(
  932. 'common/header',
  933. 'common/footer'
  934. );
  935. $this->response->setOutput($this->render());
  936. }
  937. protected function validateForm() {
  938. if (!$this->user->hasPermission('modify', 'sale/order')) {
  939. $this->error['warning'] = $this->language->get('error_permission');
  940. }
  941. if ((utf8_strlen($this->request->post['firstname']) < 1) || (utf8_strlen($this->request->post['firstname']) > 32)) {
  942. $this->error['firstname'] = $this->language->get('error_firstname');
  943. }
  944. if ((utf8_strlen($this->request->post['lastname']) < 1) || (utf8_strlen($this->request->post['lastname']) > 32)) {
  945. $this->error['lastname'] = $this->language->get('error_lastname');
  946. }
  947. if ((utf8_strlen($this->request->post['email']) > 96) || (!preg_match('/^[^\@]+@.*\.[a-z]{2,6}$/i', $this->request->post['email']))) {
  948. $this->error['email'] = $this->language->get('error_email');
  949. }
  950. if ((utf8_strlen($this->request->post['telephone']) < 3) || (utf8_strlen($this->request->post['telephone']) > 32)) {
  951. $this->error['telephone'] = $this->language->get('error_telephone');
  952. }
  953. if ((utf8_strlen($this->request->post['payment_firstname']) < 1) || (utf8_strlen($this->request->post['payment_firstname']) > 32)) {
  954. $this->error['payment_firstname'] = $this->language->get('error_firstname');
  955. }
  956. if ((utf8_strlen($this->request->post['payment_lastname']) < 1) || (utf8_strlen($this->request->post['payment_lastname']) > 32)) {
  957. $this->error['payment_lastname'] = $this->language->get('error_lastname');
  958. }
  959. if ((utf8_strlen($this->request->post['payment_address_1']) < 3) || (utf8_strlen($this->request->post['payment_address_1']) > 128)) {
  960. $this->error['payment_address_1'] = $this->language->get('error_address_1');
  961. }
  962. if ((utf8_strlen($this->request->post['payment_city']) < 3) || (utf8_strlen($this->request->post['payment_city']) > 128)) {
  963. $this->error['payment_city'] = $this->language->get('error_city');
  964. }
  965. $this->load->model('localisation/country');
  966. $country_info = $this->model_localisation_country->getCountry($this->request->post['payment_country_id']);
  967. if ($country_info) {
  968. if ($country_info['postcode_required'] && (utf8_strlen($this->request->post['payment_postcode']) < 2) || (utf8_strlen($this->request->post['payment_postcode']) > 10)) {
  969. $this->error['payment_postcode'] = $this->language->get('error_postcode');
  970. }
  971. // VAT Validation
  972. $this->load->helper('vat');
  973. if ($this->config->get('config_vat') && $this->request->post['payment_tax_id'] && (vat_validation($country_info['iso_code_2'], $this->request->post['payment_tax_id']) == 'invalid')) {
  974. $this->error['payment_tax_id'] = $this->language->get('error_vat');
  975. }
  976. }
  977. if ($this->request->post['payment_country_id'] == '') {
  978. $this->error['payment_country'] = $this->language->get('error_country');
  979. }
  980. if (!isset($this->request->post['payment_zone_id']) || $this->request->post['payment_zone_id'] == '') {
  981. $this->error['payment_zone'] = $this->language->get('error_zone');
  982. }
  983. if (!isset($this->request->post['payment_method']) || $this->request->post['payment_method'] == '') {
  984. $this->error['payment_method'] = $this->language->get('error_payment');
  985. }
  986. // Check if any products require shipping
  987. $shipping = false;
  988. if (isset($this->request->post['order_product'])) {
  989. $this->load->model('catalog/product');
  990. foreach ($this->request->post['order_product'] as $order_product) {
  991. $product_info = $this->model_catalog_product->getProduct($order_product['product_id']);
  992. if ($product_info && $product_info['shipping']) {
  993. $shipping = true;
  994. }
  995. }
  996. }
  997. if ($shipping) {
  998. if ((utf8_strlen($this->request->post['shipping_firstname']) < 1) || (utf8_strlen($this->request->post['shipping_firstname']) > 32)) {
  999. $this->error['shipping_firstname'] = $this->language->get('error_firstname');
  1000. }
  1001. if ((utf8_strlen($this->request->post['shipping_lastname']) < 1) || (utf8_strlen($this->request->post['shipping_lastname']) > 32)) {
  1002. $this->error['shipping_lastname'] = $this->language->get('error_lastname');
  1003. }
  1004. if ((utf8_strlen($this->request->post['shipping_address_1']) < 3) || (utf8_strlen($this->request->post['shipping_address_1']) > 128)) {
  1005. $this->error['shipping_address_1'] = $this->language->get('error_address_1');
  1006. }
  1007. if ((utf8_strlen($this->request->post['shipping_city']) < 3) || (utf8_strlen($this->request->post['shipping_city']) > 128)) {
  1008. $this->error['shipping_city'] = $this->language->get('error_city');
  1009. }
  1010. $this->load->model('localisation/country');
  1011. $country_info = $this->model_localisation_country->getCountry($this->request->post['shipping_country_id']);
  1012. if ($country_info && $country_info['postcode_required'] && (utf8_strlen($this->request->post['shipping_postcode']) < 2) || (utf8_strlen($this->request->post['shipping_postcode']) > 10)) {
  1013. $this->error['shipping_postcode'] = $this->language->get('error_postcode');
  1014. }
  1015. if ($this->request->post['shipping_country_id'] == '') {
  1016. $this->error['shipping_country'] = $this->language->get('error_country');
  1017. }
  1018. if (!isset($this->request->post['shipping_zone_id']) || $this->request->post['shipping_zone_id'] == '') {
  1019. $this->error['shipping_zone'] = $this->language->get('error_zone');
  1020. }
  1021. if (!$this->request->post['shipping_method']) {
  1022. $this->error['shipping_method'] = $this->language->get('error_shipping');
  1023. }
  1024. }
  1025. if ($this->error && !isset($this->error['warning'])) {
  1026. $this->error['warning'] = $this->language->get('error_warning');
  1027. }
  1028. if (!$this->error) {
  1029. return true;
  1030. } else {
  1031. return false;
  1032. }
  1033. }
  1034. protected function validateDelete() {
  1035. if (!$this->user->hasPermission('modify', 'sale/order')) {
  1036. $this->error['warning'] = $this->language->get('error_permission');
  1037. }
  1038. if (!$this->error) {
  1039. return true;
  1040. } else {
  1041. return false;
  1042. }
  1043. }
  1044. public function country() {
  1045. $json = array();
  1046. $this->load->model('localisation/country');
  1047. $country_info = $this->model_localisation_country->getCountry($this->request->get['country_id']);
  1048. if ($country_info) {
  1049. $this->load->model('localisation/zone');
  1050. $json = array(
  1051. 'country_id' => $country_info['country_id'],
  1052. 'name' => $country_info['name'],
  1053. 'iso_code_2' => $country_info['iso_code_2'],
  1054. 'iso_code_3' => $country_info['iso_code_3'],
  1055. 'address_format' => $country_info['address_format'],
  1056. 'postcode_required' => $country_info['postcode_required'],
  1057. 'zone' => $this->model_localisation_zone->getZonesByCountryId($this->request->get['country_id']),
  1058. 'status' => $country_info['status']
  1059. );
  1060. }
  1061. $this->response->setOutput(json_encode($json));
  1062. }
  1063. public function info() {
  1064. $this->load->model('sale/order');
  1065. if (isset($this->request->get['order_id'])) {
  1066. $order_id = $this->request->get['order_id'];
  1067. } else {
  1068. $order_id = 0;
  1069. }
  1070. $order_info = $this->model_sale_order->getOrder($order_id);
  1071. if ($order_info) {
  1072. $this->language->load('sale/order');
  1073. $this->document->setTitle($this->language->get('heading_title'));
  1074. $this->data['heading_title'] = $this->language->get('heading_title');
  1075. $this->data['text_amazon_order_id'] = $this->language->get('text_amazon_order_id');
  1076. $this->data['text_name'] = $this->language->get('text_name');
  1077. $this->data['text_order_id'] = $this->language->get('text_order_id');
  1078. $this->data['text_invoice_no'] = $this->language->get('text_invoice_no');
  1079. $this->data['text_invoice_date'] = $this->language->get('text_invoice_date');
  1080. $this->data['text_store_name'] = $this->language->get('text_store_name');
  1081. $this->data['text_store_url'] = $this->language->get('text_store_url');
  1082. $this->data['text_customer'] = $this->language->get('text_customer');
  1083. $this->data['text_customer_group'] = $this->language->get('text_customer_group');
  1084. $this->data['text_email'] = $this->language->get('text_email');
  1085. $this->data['text_telephone'] = $this->language->get('text_telephone');
  1086. $this->data['text_fax'] = $this->language->get('text_fax');
  1087. $this->data['text_total'] = $this->language->get('text_total');
  1088. $this->data['text_reward'] = $this->language->get('text_reward');
  1089. $this->data['text_order_status'] = $this->language->get('text_order_status');
  1090. $this->data['text_comment'] = $this->language->get('text_comment');
  1091. $this->data['text_affiliate'] = $this->language->get('text_affiliate');
  1092. $this->data['text_commission'] = $this->language->get('text_commission');
  1093. $this->data['text_ip'] = $this->language->get('text_ip');
  1094. $this->data['text_forwarded_ip'] = $this->language->get('text_forwarded_ip');
  1095. $this->data['text_user_agent'] = $this->language->get('text_user_agent');
  1096. $this->data['text_accept_language'] = $this->language->get('text_accept_language');
  1097. $this->data['text_date_added'] = $this->language->get('text_date_added');
  1098. $this->data['text_date_modified'] = $this->language->get('text_date_modified');
  1099. $this->data['text_firstname'] = $this->language->get('text_firstname');
  1100. $this->data['text_lastname'] = $this->language->get('text_lastname');
  1101. $this->data['text_company'] = $this->language->get('text_company');
  1102. $this->data['text_company_id'] = $this->language->get('text_company_id');
  1103. $this->data['text_tax_id'] = $this->language->get('text_tax_id');
  1104. $this->data['text_address_1'] = $this->language->get('text_address_1');
  1105. $this->data['text_address_2'] = $this->language->get('text_address_2');
  1106. $this->data['text_city'] = $this->language->get('text_city');
  1107. $this->data['text_postcode'] = $this->language->get('text_postcode');
  1108. $this->data['text_zone'] = $this->language->get('text_zone');
  1109. $this->data['text_zone_code'] = $this->language->get('text_zone_code');
  1110. $this->data['text_country'] = $this->language->get('text_country');
  1111. $this->data['text_shipping_method'] = $this->language->get('text_shipping_method');
  1112. $this->data['text_payment_method'] = $this->language->get('text_payment_method');
  1113. $this->data['text_download'] = $this->language->get('text_download');
  1114. $this->data['text_wait'] = $this->language->get('text_wait');
  1115. $this->data['text_generate'] = $this->language->get('text_generate');
  1116. $this->data['text_reward_add'] = $this->language->get('text_reward_add');
  1117. $this->data['text_reward_remove'] = $this->language->get('text_reward_remove');
  1118. $this->data['text_commission_add'] = $this->language->get('text_commission_add');
  1119. $this->data['text_commission_remove'] = $this->language->get('text_commission_remove');
  1120. $this->data['text_credit_add'] = $this->language->get('text_credit_add');
  1121. $this->data['text_credit_remove'] = $this->language->get('text_credit_remove');
  1122. $this->data['text_country_match'] = $this->language->get('text_country_match');
  1123. $this->data['text_country_code'] = $this->language->get('text_country_code');
  1124. $this->data['text_high_risk_country'] = $this->language->get('text_high_risk_country');
  1125. $this->data['text_distance'] = $this->language->get('text_distance');
  1126. $this->data['text_ip_region'] = $this->language->get('text_ip_region');
  1127. $this->data['text_ip_city'] = $this->language->get('text_ip_city');
  1128. $this->data['text_ip_latitude'] = $this->language->get('text_ip_latitude');
  1129. $this->data['text_ip_longitude'] = $this->language->get('text_ip_longitude');
  1130. $this->data['text_ip_isp'] = $this->language->get('text_ip_isp');
  1131. $this->data['text_ip_org'] = $this->language->get('text_ip_org');
  1132. $this->data['text_ip_asnum'] = $this->language->get('text_ip_asnum');
  1133. $this->data['text_ip_user_type'] = $this->language->get('text_ip_user_type');
  1134. $this->data['text_ip_country_confidence'] = $this->language->get('text_ip_country_confidence');
  1135. $this->data['text_ip_region_confidence'] = $this->language->get('text_ip_region_confidence');
  1136. $this->data['text_ip_city_confidence'] = $this->language->get('text_ip_city_confidence');
  1137. $this->data['text_ip_postal_confidence'] = $this->language->get('text_ip_postal_confidence');
  1138. $this->data['text_ip_postal_code'] = $this->language->get('text_ip_postal_code');
  1139. $this->data['text_ip_accuracy_radius'] = $this->language->get('text_ip_accuracy_radius');
  1140. $this->data['text_ip_net_speed_cell'] = $this->language->get('text_ip_net_speed_cell');
  1141. $this->data['text_ip_metro_code'] = $this->language->get('text_ip_metro_code');
  1142. $this->data['text_ip_area_code'] = $this->language->get('text_ip_area_code');
  1143. $this->data['text_ip_time_zone'] = $this->language->get('text_ip_time_zone');
  1144. $this->data['text_ip_region_name'] = $this->language->get('text_ip_region_name');
  1145. $this->data['text_ip_domain'] = $this->language->get('text_ip_domain');
  1146. $this->data['text_ip_country_name'] = $this->language->get('text_ip_country_name');
  1147. $this->data['text_ip_continent_code'] = $this->language->get('text_ip_continent_code');
  1148. $this->data['text_ip_corporate_proxy'] = $this->language->get('text_ip_corporate_proxy');
  1149. $this->data['text_anonymous_proxy'] = $this->language->get('text_anonymous_proxy');
  1150. $this->data['text_proxy_score'] = $this->language->get('text_proxy_score');
  1151. $this->data['text_is_trans_proxy'] = $this->language->get('text_is_trans_proxy');
  1152. $this->data['text_free_mail'] = $this->language->get('text_free_mail');
  1153. $this->data['text_carder_email'] = $this->language->get('text_carder_email');
  1154. $this->data['text_high_risk_username'] = $this->language->get('text_high_risk_username');
  1155. $this->data['text_high_risk_password'] = $this->language->get('text_high_risk_password');
  1156. $this->data['text_bin_match'] = $this->language->get('text_bin_match');
  1157. $this->data['text_bin_country'] = $this->language->get('text_bin_country');
  1158. $this->data['text_bin_name_match'] = $this->language->get('text_bin_name_match');
  1159. $this->data['text_bin_name'] = $this->language->get('text_bin_name');
  1160. $this->data['text_bin_phone_match'] = $this->language->get('text_bin_phone_match');
  1161. $this->data['text_bin_phone'] = $this->language->get('text_bin_phone');
  1162. $this->data['text_customer_phone_in_billing_location'] = $this->language->get('text_customer_phone_in_billing_location');
  1163. $this->data['text_ship_forward'] = $this->language->get('text_ship_forward');
  1164. $this->data['text_city_postal_match'] = $this->language->get('text_city_postal_match');
  1165. $this->data['text_ship_city_postal_match'] = $this->language->get('text_ship_city_postal_match');
  1166. $this->data['text_score'] = $this->language->get('text_score');
  1167. $this->data['text_explanation'] = $this->language->get('text_explanation');
  1168. $this->data['text_risk_score'] = $this->language->get('text_risk_score');
  1169. $this->data['text_queries_remaining'] = $this->language->get('text_queries_remaining');
  1170. $this->data['text_maxmind_id'] = $this->language->get('text_maxmind_id');
  1171. $this->data['text_error'] = $this->language->get('text_error');
  1172. $this->data['column_product'] = $this->language->get('column_product');
  1173. $this->data['column_model'] = $this->language->get('column_model');
  1174. $this->data['column_quantity'] = $this->language->get('column_quantity');
  1175. $this->data['column_price'] = $this->language->get('column_price');
  1176. $this->data['column_total'] = $this->language->get('column_total');
  1177. $this->data['column_download'] = $this->language->get('column_download');
  1178. $this->data['column_filename'] = $this->language->get('column_filename');
  1179. $this->data['column_remaining'] = $this->language->get('column_remaining');
  1180. $this->data['entry_order_status'] = $this->language->get('entry_order_status');
  1181. $this->data['entry_notify'] = $this->language->get('entry_notify');
  1182. $this->data['entry_comment'] = $this->language->get('entry_comment');
  1183. $this->data['button_invoice'] = $this->language->get('button_invoice');
  1184. $this->data['button_cancel'] = $this->language->get('button_cancel');
  1185. $this->data['button_add_history'] = $this->language->get('button_add_history');
  1186. $this->data['tab_order'] = $this->language->get('tab_order');
  1187. $this->data['tab_payment'] = $this->language->get('tab_payment');
  1188. $this->data['tab_shipping'] = $this->language->get('tab_shipping');
  1189. $this->data['tab_product'] = $this->language->get('tab_product');
  1190. $this->data['tab_history'] = $this->language->get('tab_history');
  1191. $this->data['tab_fraud'] = $this->language->get('tab_fraud');
  1192. $this->data['token'] = $this->session->data['token'];
  1193. $url = '';
  1194. if (isset($this->request->get['filter_order_id'])) {
  1195. $url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
  1196. }
  1197. if (isset($this->request->get['filter_customer'])) {
  1198. $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
  1199. }
  1200. if (isset($this->request->get['filter_order_status_id'])) {
  1201. $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id'];
  1202. }
  1203. if (isset($this->request->get['filter_total'])) {
  1204. $url .= '&filter_total=' . $this->request->get['filter_total'];
  1205. }
  1206. if (isset($this->request->get['filter_date_added'])) {
  1207. $url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
  1208. }
  1209. if (isset($this->request->get['filter_date_modified'])) {
  1210. $url .= '&filter_date_modified=' . $this->request->get['filter_date_modified'];
  1211. }
  1212. if (isset($this->request->get['sort'])) {
  1213. $url .= '&sort=' . $this->request->get['sort'];
  1214. }
  1215. if (isset($this->request->get['order'])) {
  1216. $url .= '&order=' . $this->request->get['order'];
  1217. }
  1218. if (isset($this->request->get['page'])) {
  1219. $url .= '&page=' . $this->request->get['page'];
  1220. }
  1221. $this->data['breadcrumbs'] = array();
  1222. $this->data['breadcrumbs'][] = array(
  1223. 'text' => $this->language->get('text_home'),
  1224. 'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
  1225. 'separator' => false
  1226. );
  1227. $this->data['breadcrumbs'][] = array(
  1228. 'text' => $this->language->get('heading_title'),
  1229. 'href' => $this->url->link('sale/order', 'token=' . $this->session->data['token'] . $url, 'SSL'),
  1230. 'separator' => ' :: '
  1231. );
  1232. $this->data['invoice'] = $this->url->link('sale/order/invoice', 'token=' . $this->session->data['token'] . '&order_id=' . (int)$this->request->get['order_id'], 'SSL');
  1233. $this->data['cancel'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . $url, 'SSL');
  1234. $this->data['order_id'] = $this->request->get['order_id'];
  1235. if ($order_info['invoice_no']) {
  1236. $this->data['invoice_no'] = $order_info['invoice_prefix'] . $order_info['invoice_no'];
  1237. } else {
  1238. $this->data['invoice_no'] = '';
  1239. }
  1240. $this->data['amazon_order_id'] = $order_info['amazon_order_id'];
  1241. $this->data['store_name'] = $order_info['store_name'];
  1242. $this->data['store_url'] = $order_info['store_url'];
  1243. $this->data['firstname'] = $order_info['firstname'];
  1244. $this->data['lastname'] = $order_info['lastname'];
  1245. if ($order_info['customer_id']) {
  1246. $this->data['customer'] = $this->url->link('sale/customer/update', 'token=' . $this->session->data['token'] . '&customer_id=' . $order_info['customer_id'], 'SSL');
  1247. } else {
  1248. $this->data['customer'] = '';
  1249. }
  1250. $this->load->model('sale/customer_group');
  1251. $customer_group_info = $this->model_sale_customer_group->getCustomerGroup($order_info['customer_group_id']);
  1252. if ($customer_group_info) {
  1253. $this->data['customer_group'] = $customer_group_info['name'];
  1254. } else {
  1255. $this->data['customer_group'] = '';
  1256. }
  1257. $this->data['email'] = $order_info['email'];
  1258. $this->data['telephone'] = $order_info['telephone'];
  1259. $this->data['fax'] = $order_info['fax'];
  1260. $this->data['comment'] = nl2br($order_info['comment']);
  1261. $this->data['shipping_method'] = $order_info['shipping_method'];
  1262. $this->data['payment_method'] = $order_info['payment_method'];
  1263. $this->data['total'] = $this->currency->format($order_info['total'], $order_info['currency_code'], $order_info['currency_value']);
  1264. if ($order_info['total'] < 0) {
  1265. $this->data['credit'] = $order_info['total'];
  1266. } else {
  1267. $this->data['credit'] = 0;
  1268. }
  1269. $this->load->model('sale/customer');
  1270. $this->data['credit_total'] = $this->model_sale_customer->getTotalTransactionsByOrderId($this->request->get['order_id']);
  1271. $this->data['reward'] = $order_info['reward'];
  1272. $this->data['reward_total'] = $this->model_sale_customer->getTotalCustomerRewardsByOrderId($this->request->get['order_id']);
  1273. $this->data['affiliate_firstname'] = $order_info['affiliate_firstname'];
  1274. $this->data['affiliate_lastname'] = $order_info['affiliate_lastname'];
  1275. if ($order_info['affiliate_id']) {
  1276. $this->data['affiliate'] = $this->url->link('sale/affiliate/update', 'token=' . $this->session->data['token'] . '&affiliate_id=' . $order_info['affiliate_id'], 'SSL');
  1277. } else {
  1278. $this->data['affiliate'] = '';
  1279. }
  1280. $this->data['commission'] = $this->currency->format($order_info['commission'], $order_info['currency_code'], $order_info['currency_value']);
  1281. $this->load->model('sale/affiliate');
  1282. $this->data['commission_total'] = $this->model_sale_affiliate->getTotalTransactionsByOrderId($this->request->get['order_id']);
  1283. $this->load->model('localisation/order_status');
  1284. $order_status_info = $this->model_localisation_order_status->getOrderStatus($order_info['order_status_id']);
  1285. if ($order_status_info) {
  1286. $this->data['order_status'] = $order_status_info['name'];
  1287. } else {
  1288. $this->data['order_status'] = '';
  1289. }
  1290. $this->data['ip'] = $order_info['ip'];
  1291. $this->data['forwarded_ip'] = $order_info['forwarded_ip'];
  1292. $this->data['user_agent'] = $order_info['user_agent'];
  1293. $this->data['accept_language'] = $order_info['accept_language'];
  1294. $this->data['date_added'] = date($this->language->get('date_format_short'), strtotime($order_info['date_added']));
  1295. $this->data['date_modified'] = date($this->language->get('date_format_short'), strtotime($order_info['date_modified']));
  1296. $this->data['payment_firstname'] = $order_info['payment_firstname'];
  1297. $this->data['payment_lastname'] = $order_info['payment_lastname'];
  1298. $this->data['payment_company'] = $order_info['payment_company'];
  1299. $this->data['payment_company_id'] = $order_info['payment_company_id'];
  1300. $this->data['payment_tax_id'] = $order_info['payment_tax_id'];
  1301. $this->data['payment_address_1'] = $order_info['payment_address_1'];
  1302. $this->data['payment_address_2'] = $order_info['payment_address_2'];
  1303. $this->data['payment_city'] = $order_info['payment_city'];
  1304. $this->data['payment_postcode'] = $order_info['payment_postcode'];
  1305. $this->data['payment_zone'] = $order_info['payment_zone'];
  1306. $this->data['payment_zone_code'] = $order_info['payment_zone_code'];
  1307. $this->data['payment_country'] = $order_info['payment_country'];
  1308. $this->data['shipping_firstname'] = $order_info['shipping_firstname'];
  1309. $this->data['shipping_lastname'] = $order_info['shipping_lastname'];
  1310. $this->data['shipping_company'] = $order_info['shipping_company'];
  1311. $this->data['shipping_address_1'] = $order_info['shipping_address_1'];
  1312. $this->data['shipping_address_2'] = $order_info['shipping_address_2'];
  1313. $this->data['shipping_city'] = $order_info['shipping_city'];
  1314. $this->data['shipping_postcode'] = $order_info['shipping_postcode'];
  1315. $this->data['shipping_zone'] = $order_info['shipping_zone'];
  1316. $this->data['shipping_zone_code'] = $order_info['shipping_zone_code'];
  1317. $this->data['shipping_country'] = $order_info['shipping_country'];
  1318. $this->data['products'] = array();
  1319. $products = $this->model_sale_order->getOrderProducts($this->request->get['order_id']);
  1320. foreach ($products as $product) {
  1321. $option_data = array();
  1322. $options = $this->model_sale_order->getOrderOptions($this->request->get['order_id'], $product['order_product_id']);
  1323. foreach ($options as $option) {
  1324. if ($option['type'] != 'file') {
  1325. $option_data[] = array(
  1326. 'name' => $option['name'],
  1327. 'value' => $option['value'],
  1328. 'type' => $option['type']
  1329. );
  1330. } else {
  1331. $option_data[] = array(
  1332. 'name' => $option['name'],
  1333. 'value' => utf8_substr($option['value'], 0, utf8_strrpos($option['value'], '.')),
  1334. 'type' => $option['type'],
  1335. 'href' => $this->url->link('sale/order/download', 'token=' . $this->session->data['token'] . '&order_id=' . $this->request->get['order_id'] . '&order_option_id=' . $option['order_option_id'], 'SSL')
  1336. );
  1337. }
  1338. }
  1339. $this->data['products'][] = array(
  1340. 'order_product_id' => $product['order_product_id'],
  1341. 'product_id' => $product['product_id'],
  1342. 'name' => $product['name'],
  1343. 'model' => $product['model'],
  1344. 'option' => $option_data,
  1345. 'quantity' => $product['quantity'],
  1346. 'price' => $this->currency->format($product['price'] + ($this->config->get('config_tax') ? $product['tax'] : 0), $order_info['currency_code'], $order_info['currency_value']),
  1347. 'total' => $this->currency->format($product['total'] + ($this->config->get('config_tax') ? ($product['tax'] * $product['quantity']) : 0), $order_info['currency_code'], $order_info['currency_value']),
  1348. 'href' => $this->url->link('catalog/product/update', 'token=' . $this->session->data['token'] . '&product_id=' . $product['product_id'], 'SSL')
  1349. );
  1350. }
  1351. $this->data['vouchers'] = array();
  1352. $vouchers = $this->model_sale_order->getOrderVouchers($this->request->get['order_id']);
  1353. foreach ($vouchers as $voucher) {
  1354. $this->data['vouchers'][] = array(
  1355. 'description' => $voucher['description'],
  1356. 'amount' => $this->currency->format($voucher['amount'], $order_info['currency_code'], $order_info['currency_value']),
  1357. 'href' => $this->url->link('sale/voucher/update', 'token=' . $this->session->data['token'] . '&voucher_id=' . $voucher['voucher_id'], 'SSL')
  1358. );
  1359. }
  1360. $this->data['totals'] = $this->model_sale_order->getOrderTotals($this->request->get['order_id']);
  1361. $this->data['downloads'] = array();
  1362. foreach ($products as $product) {
  1363. $results = $this->model_sale_order->getOrderDownloads($this->request->get['order_id'], $product['order_product_id']);
  1364. foreach ($results as $result) {
  1365. $this->data['downloads'][] = array(
  1366. 'name' => $result['name'],
  1367. 'filename' => $result['mask'],
  1368. 'remaining' => $result['remaining']
  1369. );
  1370. }
  1371. }
  1372. $this->data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
  1373. $this->data['order_status_id'] = $order_info['order_status_id'];
  1374. // Fraud
  1375. $this->load->model('sale/fraud');
  1376. $fraud_info = $this->model_sale_fraud->getFraud($order_info['order_id']);
  1377. if ($fraud_info) {
  1378. $this->data['country_match'] = $fraud_info['country_match'];
  1379. if ($fraud_info['country_code']) {
  1380. $this->data['country_code'] = $fraud_info['country_code'];
  1381. } else {
  1382. $this->data['country_code'] = '';
  1383. }
  1384. $this->data['high_risk_country'] = $fraud_info['high_risk_country'];
  1385. $this->data['distance'] = $fraud_info['distance'];
  1386. if ($fraud_info['ip_region']) {
  1387. $this->data['ip_region'] = $fraud_info['ip_region'];
  1388. } else {
  1389. $this->data['ip_region'] = '';
  1390. }
  1391. if ($fraud_info['ip_city']) {
  1392. $this->data['ip_city'] = $fraud_info['ip_city'];
  1393. } else {
  1394. $this->data['ip_city'] = '';
  1395. }
  1396. $this->data['ip_latitude'] = $fraud_info['ip_latitude'];
  1397. $this->data['ip_longitude'] = $fraud_info['ip_longitude'];
  1398. if ($fraud_info['ip_isp']) {
  1399. $this->data['ip_isp'] = $fraud_info['ip_isp'];
  1400. } else {
  1401. $this->data['ip_isp'] = '';
  1402. }
  1403. if ($fraud_info['ip_org']) {
  1404. $this->data['ip_org'] = $fraud_info['ip_org'];
  1405. } else {
  1406. $this->data['ip_org'] = '';
  1407. }
  1408. $this->data['ip_asnum'] = $fraud_info['ip_asnum'];
  1409. if ($fraud_info['ip_user_type']) {
  1410. $this->data['ip_user_type'] = $fraud_info['ip_user_type'];
  1411. } else {
  1412. $this->data['ip_user_type'] = '';
  1413. }
  1414. if ($fraud_info['ip_country_confidence']) {
  1415. $this->data['ip_country_confidence'] = $fraud_info['ip_country_confidence'];
  1416. } else {
  1417. $this->data['ip_country_confidence'] = '';
  1418. }
  1419. if ($fraud_info['ip_region_confidence']) {
  1420. $this->data['ip_region_confidence'] = $fraud_info['ip_region_confidence'];
  1421. } else {
  1422. $this->data['ip_region_confidence'] = '';
  1423. }
  1424. if ($fraud_info['ip_city_confidence']) {
  1425. $this->data['ip_city_confidence'] = $fraud_info['ip_city_confidence'];
  1426. } else {
  1427. $this->data['ip_city_confidence'] = '';
  1428. }
  1429. if ($fraud_info['ip_postal_confidence']) {
  1430. $this->data['ip_postal_confidence'] = $fraud_info['ip_postal_confidence'];
  1431. } else {
  1432. $this->data['ip_postal_confidence'] = '';
  1433. }
  1434. if ($fraud_info['ip_postal_code']) {
  1435. $this->data['ip_postal_code'] = $fraud_info['ip_postal_code'];
  1436. } else {
  1437. $this->data['ip_postal_code'] = '';
  1438. }
  1439. $this->data['ip_accuracy_radius'] = $fraud_info['ip_accuracy_radius'];
  1440. if ($fraud_info['ip_net_speed_cell']) {
  1441. $this->data['ip_net_speed_cell'] = $fraud_info['ip_net_speed_cell'];
  1442. } else {
  1443. $this->data['ip_net_speed_cell'] = '';
  1444. }
  1445. $this->data['ip_metro_code'] = $fraud_info['ip_metro_code'];
  1446. $this->data['ip_area_code'] = $fraud_info['ip_area_code'];
  1447. if ($fraud_info['ip_time_zone']) {
  1448. $this->data['ip_time_zone'] = $fraud_info['ip_time_zone'];
  1449. } else {
  1450. $this->data['ip_time_zone'] = '';
  1451. }
  1452. if ($fraud_info['ip_region_name']) {
  1453. $this->data['ip_region_name'] = $fraud_info['ip_region_name'];
  1454. } else {
  1455. $this->data['ip_region_name'] = '';
  1456. }
  1457. if ($fraud_info['ip_domain']) {
  1458. $this->data['ip_domain'] = $fraud_info['ip_domain'];
  1459. } else {
  1460. $this->data['ip_domain'] = '';
  1461. }
  1462. if ($fraud_info['ip_country_name']) {
  1463. $this->data['ip_country_name'] = $fraud_info['ip_country_name'];
  1464. } else {
  1465. $this->data['ip_country_name'] = '';
  1466. }
  1467. if ($fraud_info['ip_continent_code']) {
  1468. $this->data['ip_continent_code'] = $fraud_info['ip_continent_code'];
  1469. } else {
  1470. $this->data['ip_continent_code'] = '';
  1471. }
  1472. if ($fraud_info['ip_corporate_proxy']) {
  1473. $this->data['ip_corporate_proxy'] = $fraud_info['ip_corporate_proxy'];
  1474. } else {
  1475. $this->data['ip_corporate_proxy'] = '';
  1476. }
  1477. $this->data['anonymous_proxy'] = $fraud_info['anonymous_proxy'];
  1478. $this->data['proxy_score'] = $fraud_info['proxy_score'];
  1479. if ($fraud_info['is_trans_proxy']) {
  1480. $this->data['is_trans_proxy'] = $fraud_info['is_trans_proxy'];
  1481. } else {
  1482. $this->data['is_trans_proxy'] = '';
  1483. }
  1484. $this->data['free_mail'] = $fraud_info['free_mail'];
  1485. $this->data['carder_email'] = $fraud_info['carder_email'];
  1486. if ($fraud_info['high_risk_username']) {
  1487. $this->data['high_risk_username'] = $fraud_info['high_risk_username'];
  1488. } else {
  1489. $this->data['high_risk_username'] = '';
  1490. }
  1491. if ($fraud_info['high_risk_password']) {
  1492. $this->data['high_risk_password'] = $fraud_info['high_risk_password'];
  1493. } else {
  1494. $this->data['high_risk_password'] = '';
  1495. }
  1496. $this->data['bin_match'] = $fraud_info['bin_match'];
  1497. if ($fraud_info['bin_country']) {
  1498. $this->data['bin_country'] = $fraud_info['bin_country'];
  1499. } else {
  1500. $this->data['bin_country'] = '';
  1501. }
  1502. $this->data['bin_name_match'] = $fraud_info['bin_name_match'];
  1503. if ($fraud_info['bin_name']) {
  1504. $this->data['bin_name'] = $fraud_info['bin_name'];
  1505. } else {
  1506. $this->data['bin_name'] = '';
  1507. }
  1508. $this->data['bin_phone_match'] = $fraud_info['bin_phone_match'];
  1509. if ($fraud_info['bin_phone']) {
  1510. $this->data['bin_phone'] = $fraud_info['bin_phone'];
  1511. } else {
  1512. $this->data['bin_phone'] = '';
  1513. }
  1514. if ($fraud_info['customer_phone_in_billing_location']) {
  1515. $this->data['customer_phone_in_billing_location'] = $fraud_info['customer_phone_in_billing_location'];
  1516. } else {
  1517. $this->data['customer_phone_in_billing_location'] = '';
  1518. }
  1519. $this->data['ship_forward'] = $fraud_info['ship_forward'];
  1520. if ($fraud_info['city_postal_match']) {
  1521. $this->data['city_postal_match'] = $fraud_info['city_postal_match'];
  1522. } else {
  1523. $this->data['city_postal_match'] = '';
  1524. }
  1525. if ($fraud_info['ship_city_postal_match']) {
  1526. $this->data['ship_city_postal_match'] = $fraud_info['ship_city_postal_match'];
  1527. } else {
  1528. $this->data['ship_city_postal_match'] = '';
  1529. }
  1530. $this->data['score'] = $fraud_info['score'];
  1531. $this->data['explanation'] = $fraud_info['explanation'];
  1532. $this->data['risk_score'] = $fraud_info['risk_score'];
  1533. $this->data['queries_remaining'] = $fraud_info['queries_remaining'];
  1534. $this->data['maxmind_id'] = $fraud_info['maxmind_id'];
  1535. $this->data['error'] = $fraud_info['error'];
  1536. } else {
  1537. $this->data['maxmind_id'] = '';
  1538. }
  1539. if($this->hasAction('payment/' . $order_info['payment_code'] . '/orderAction') == true){
  1540. $this->data['payment_action'] = $this->getChild('payment/' . $order_info['payment_code'] . '/orderAction');
  1541. }else{
  1542. $this->data['payment_action'] = '';
  1543. }
  1544. $this->template = 'sale/order_info.tpl';
  1545. $this->children = array(
  1546. 'common/header',
  1547. 'common/footer'
  1548. );
  1549. $this->response->setOutput($this->render());
  1550. } else {
  1551. $this->language->load('error/not_found');
  1552. $this->document->setTitle($this->language->get('heading_title'));
  1553. $this->data['heading_title'] = $this->language->get('heading_title');
  1554. $this->data['text_not_found'] = $this->language->get('text_not_found');
  1555. $this->data['breadcrumbs'] = array();
  1556. $this->data['breadcrumbs'][] = array(
  1557. 'text' => $this->language->get('text_home'),
  1558. 'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
  1559. 'separator' => false
  1560. );
  1561. $this->data['breadcrumbs'][] = array(
  1562. 'text' => $this->language->get('heading_title'),
  1563. 'href' => $this->url->link('error/not_found', 'token=' . $this->session->data['token'], 'SSL'),
  1564. 'separator' => ' :: '
  1565. );
  1566. $this->template = 'error/not_found.tpl';
  1567. $this->children = array(
  1568. 'common/header',
  1569. 'common/footer'
  1570. );
  1571. $this->response->setOutput($this->render());
  1572. }
  1573. }
  1574. public function createInvoiceNo() {
  1575. $this->language->load('sale/order');
  1576. $json = array();
  1577. if (!$this->user->hasPermission('modify', 'sale/order')) {
  1578. $json['error'] = $this->language->get('error_permission');
  1579. } elseif (isset($this->request->get['order_id'])) {
  1580. $this->load->model('sale/order');
  1581. $invoice_no = $this->model_sale_order->createInvoiceNo($this->request->get['order_id']);
  1582. if ($invoice_no) {
  1583. $json['invoice_no'] = $invoice_no;
  1584. } else {
  1585. $json['error'] = $this->language->get('error_action');
  1586. }
  1587. }
  1588. $this->response->setOutput(json_encode($json));
  1589. }
  1590. public function addCredit() {
  1591. $this->language->load('sale/order');
  1592. $json = array();
  1593. if (!$this->user->hasPermission('modify', 'sale/order')) {
  1594. $json['error'] = $this->language->get('error_permission');
  1595. } elseif (isset($this->request->get['order_id'])) {
  1596. $this->load->model('sale/order');
  1597. $order_info = $this->model_sale_order->getOrder($this->request->get['order_id']);
  1598. if ($order_info && $order_info['customer_id']) {
  1599. $this->load->model('sale/customer');
  1600. $credit_total = $this->model_sale_customer->getTotalTransactionsByOrderId($this->request->get['order_id']);
  1601. if (!$credit_total) {
  1602. $this->model_sale_customer->addTransaction($order_info['customer_id'], $this->language->get('text_order_id') . ' #' . $this->request->get['order_id'], $order_info['total'], $this->request->get['order_id']);
  1603. $json['success'] = $this->language->get('text_credit_added');
  1604. } else {
  1605. $json['error'] = $this->language->get('error_action');
  1606. }
  1607. }
  1608. }
  1609. $this->response->setOutput(json_encode($json));
  1610. }
  1611. public function removeCredit() {
  1612. $this->language->load('sale/order');
  1613. $json = array();
  1614. if (!$this->user->hasPermission('modify', 'sale/order')) {
  1615. $json['error'] = $this->language->get('error_permission');
  1616. } elseif (isset($this->request->get['order_id'])) {
  1617. $this->load->model('sale/order');
  1618. $order_info = $this->model_sale_order->getOrder($this->request->get['order_id']);
  1619. if ($order_info && $order_info['customer_id']) {
  1620. $this->load->model('sale/customer');
  1621. $this->model_sale_customer->deleteTransaction($this->request->get['order_id']);
  1622. $json['success'] = $this->language->get('text_credit_removed');
  1623. } else {
  1624. $json['error'] = $this->language->get('error_action');
  1625. }
  1626. }
  1627. $this->response->setOutput(json_encode($json));
  1628. }
  1629. public function addReward() {
  1630. $this->language->load('sale/order');
  1631. $json = array();
  1632. if (!$this->user->hasPermission('modify', 'sale/order')) {
  1633. $json['error'] = $this->language->get('error_permission');
  1634. } elseif (isset($this->request->get['order_id'])) {
  1635. $this->load->model('sale/order');
  1636. $order_info = $this->model_sale_order->getOrder($this->request->get['order_id']);
  1637. if ($order_info && $order_info['customer_id']) {
  1638. $this->load->model('sale/customer');
  1639. $reward_total = $this->model_sale_customer->getTotalCustomerRewardsByOrderId($this->request->get['order_id']);
  1640. if (!$reward_total) {
  1641. $this->model_sale_customer->addReward($order_info['customer_id'], $this->language->get('text_order_id') . ' #' . $this->request->get['order_id'], $order_info['reward'], $this->request->get['order_id']);
  1642. $json['success'] = $this->language->get('text_reward_added');
  1643. } else {
  1644. $json['error'] = $this->language->get('error_action');
  1645. }
  1646. } else {
  1647. $json['error'] = $this->language->get('error_action');
  1648. }
  1649. }
  1650. $this->response->setOutput(json_encode($json));
  1651. }
  1652. public function removeReward() {
  1653. $this->language->load('sale/order');
  1654. $json = array();
  1655. if (!$this->user->hasPermission('modify', 'sale/order')) {
  1656. $json['error'] = $this->language->get('error_permission');
  1657. } elseif (isset($this->request->get['order_id'])) {
  1658. $this->load->model('sale/order');
  1659. $order_info = $this->model_sale_order->getOrder($this->request->get['order_id']);
  1660. if ($order_info && $order_info['customer_id']) {
  1661. $this->load->model('sale/customer');
  1662. $this->model_sale_customer->deleteReward($this->request->get['order_id']);
  1663. $json['success'] = $this->language->get('text_reward_removed');
  1664. } else {
  1665. $json['error'] = $this->language->get('error_action');
  1666. }
  1667. }
  1668. $this->response->setOutput(json_encode($json));
  1669. }
  1670. public function addCommission() {
  1671. $this->language->load('sale/order');
  1672. $json = array();
  1673. if (!$this->user->hasPermission('modify', 'sale/order')) {
  1674. $json['error'] = $this->language->get('error_permission');
  1675. } elseif (isset($this->request->get['order_id'])) {
  1676. $this->load->model('sale/order');
  1677. $order_info = $this->model_sale_order->getOrder($this->request->get['order_id']);
  1678. if ($order_info && $order_info['affiliate_id']) {
  1679. $this->load->model('sale/affiliate');
  1680. $affiliate_total = $this->model_sale_affiliate->getTotalTransactionsByOrderId($this->request->get['order_id']);
  1681. if (!$affiliate_total) {
  1682. $this->model_sale_affiliate->addTransaction($order_info['affiliate_id'], $this->language->get('text_order_id') . ' #' . $this->request->get['order_id'], $order_info['commission'], $this->request->get['order_id']);
  1683. $json['success'] = $this->language->get('text_commission_added');
  1684. } else {
  1685. $json['error'] = $this->language->get('error_action');
  1686. }
  1687. } else {
  1688. $json['error'] = $this->language->get('error_action');
  1689. }
  1690. }
  1691. $this->response->setOutput(json_encode($json));
  1692. }
  1693. public function removeCommission() {
  1694. $this->language->load('sale/order');
  1695. $json = array();
  1696. if (!$this->user->hasPermission('modify', 'sale/order')) {
  1697. $json['error'] = $this->language->get('error_permission');
  1698. } elseif (isset($this->request->get['order_id'])) {
  1699. $this->load->model('sale/order');
  1700. $order_info = $this->model_sale_order->getOrder($this->request->get['order_id']);
  1701. if ($order_info && $order_info['affiliate_id']) {
  1702. $this->load->model('sale/affiliate');
  1703. $this->model_sale_affiliate->deleteTransaction($this->request->get['order_id']);
  1704. $json['success'] = $this->language->get('text_commission_removed');
  1705. } else {
  1706. $json['error'] = $this->language->get('error_action');
  1707. }
  1708. }
  1709. $this->response->setOutput(json_encode($json));
  1710. }
  1711. public function history() {
  1712. $this->language->load('sale/order');
  1713. $this->data['error'] = '';
  1714. $this->data['success'] = '';
  1715. $this->load->model('sale/order');
  1716. if ($this->request->server['REQUEST_METHOD'] == 'POST') {
  1717. if (!$this->user->hasPermission('modify', 'sale/order')) {
  1718. $this->data['error'] = $this->language->get('error_permission');
  1719. }
  1720. if (!$this->data['error']) {
  1721. $this->model_sale_order->addOrderHistory($this->request->get['order_id'], $this->request->post);
  1722. $this->data['success'] = $this->language->get('text_success');
  1723. }
  1724. }
  1725. $this->data['text_no_results'] = $this->language->get('text_no_results');
  1726. $this->data['column_date_added'] = $this->language->get('column_date_added');
  1727. $this->data['column_status'] = $this->language->get('column_status');
  1728. $this->data['column_notify'] = $this->language->get('column_notify');
  1729. $this->data['column_comment'] = $this->language->get('column_comment');
  1730. if (isset($this->request->get['page'])) {
  1731. $page = $this->request->get['page'];
  1732. } else {
  1733. $page = 1;
  1734. }
  1735. $this->data['histories'] = array();
  1736. $results = $this->model_sale_order->getOrderHistories($this->request->get['order_id'], ($page - 1) * 10, 10);
  1737. foreach ($results as $result) {
  1738. $this->data['histories'][] = array(
  1739. 'notify' => $result['notify'] ? $this->language->get('text_yes') : $this->language->get('text_no'),
  1740. 'status' => $result['status'],
  1741. 'comment' => nl2br($result['comment']),
  1742. 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added']))
  1743. );
  1744. }
  1745. $history_total = $this->model_sale_order->getTotalOrderHistories($this->request->get['order_id']);
  1746. $pagination = new Pagination();
  1747. $pagination->total = $history_total;
  1748. $pagination->page = $page;
  1749. $pagination->limit = 10;
  1750. $pagination->text = $this->language->get('text_pagination');
  1751. $pagination->url = $this->url->link('sale/order/history', 'token=' . $this->session->data['token'] . '&order_id=' . $this->request->get['order_id'] . '&page={page}', 'SSL');
  1752. $this->data['pagination'] = $pagination->render();
  1753. $this->template = 'sale/order_history.tpl';
  1754. $this->response->setOutput($this->render());
  1755. }
  1756. public function download() {
  1757. $this->load->model('sale/order');
  1758. if (isset($this->request->get['order_option_id'])) {
  1759. $order_option_id = $this->request->get['order_option_id'];
  1760. } else {
  1761. $order_option_id = 0;
  1762. }
  1763. $option_info = $this->model_sale_order->getOrderOption($this->request->get['order_id'], $order_option_id);
  1764. if ($option_info && $option_info['type'] == 'file') {
  1765. $file = DIR_DOWNLOAD . $option_info['value'];
  1766. $mask = basename(utf8_substr($option_info['value'], 0, utf8_strrpos($option_info['value'], '.')));
  1767. if (!headers_sent()) {
  1768. if (file_exists($file)) {
  1769. header('Content-Type: application/octet-stream');
  1770. header('Content-Description: File Transfer');
  1771. header('Content-Disposition: attachment; filename="' . ($mask ? $mask : basename($file)) . '"');
  1772. header('Content-Transfer-Encoding: binary');
  1773. header('Expires: 0');
  1774. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  1775. header('Pragma: public');
  1776. header('Content-Length: ' . filesize($file));
  1777. readfile($file, 'rb');
  1778. exit;
  1779. } else {
  1780. exit('Error: Could not find file ' . $file . '!');
  1781. }
  1782. } else {
  1783. exit('Error: Headers already sent out!');
  1784. }
  1785. } else {
  1786. $this->language->load('error/not_found');
  1787. $this->document->setTitle($this->language->get('heading_title'));
  1788. $this->data['heading_title'] = $this->language->get('heading_title');
  1789. $this->data['text_not_found'] = $this->language->get('text_not_found');
  1790. $this->data['breadcrumbs'] = array();
  1791. $this->data['breadcrumbs'][] = array(
  1792. 'text' => $this->language->get('text_home'),
  1793. 'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
  1794. 'separator' => false
  1795. );
  1796. $this->data['breadcrumbs'][] = array(
  1797. 'text' => $this->language->get('heading_title'),
  1798. 'href' => $this->url->link('error/not_found', 'token=' . $this->session->data['token'], 'SSL'),
  1799. 'separator' => ' :: '
  1800. );
  1801. $this->template = 'error/not_found.tpl';
  1802. $this->children = array(
  1803. 'common/header',
  1804. 'common/footer'
  1805. );
  1806. $this->response->setOutput($this->render());
  1807. }
  1808. }
  1809. public function upload() {
  1810. $this->language->load('sale/order');
  1811. $json = array();
  1812. if ($this->request->server['REQUEST_METHOD'] == 'POST') {
  1813. if (!empty($this->request->files['file']['name'])) {
  1814. $filename = html_entity_decode($this->request->files['file']['name'], ENT_QUOTES, 'UTF-8');
  1815. if ((utf8_strlen($filename) < 3) || (utf8_strlen($filename) > 128)) {
  1816. $json['error'] = $this->language->get('error_filename');
  1817. }
  1818. // Allowed file extension types
  1819. $allowed = array();
  1820. $filetypes = explode("\n", $this->config->get('config_file_extension_allowed'));
  1821. foreach ($filetypes as $filetype) {
  1822. $allowed[] = trim($filetype);
  1823. }
  1824. if (!in_array(substr(strrchr($filename, '.'), 1), $allowed)) {
  1825. $json['error'] = $this->language->get('error_filetype');
  1826. }
  1827. // Allowed file mime types
  1828. $allowed = array();
  1829. $filetypes = explode("\n", $this->config->get('config_file_mime_allowed'));
  1830. foreach ($filetypes as $filetype) {
  1831. $allowed[] = trim($filetype);
  1832. }
  1833. if (!in_array($this->request->files['file']['type'], $allowed)) {
  1834. $json['error'] = $this->language->get('error_filetype');
  1835. }
  1836. // Check to see if any PHP files are trying to be uploaded
  1837. $content = file_get_contents($this->request->files['file']['tmp_name']);
  1838. if (preg_match('/\<\?php/i', $content)) {
  1839. $json['error'] = $this->language->get('error_filetype');
  1840. }
  1841. if ($this->request->files['file']['error'] != UPLOAD_ERR_OK) {
  1842. $json['error'] = $this->language->get('error_upload_' . $this->request->files['file']['error']);
  1843. }
  1844. } else {
  1845. $json['error'] = $this->language->get('error_upload');
  1846. }
  1847. if (!isset($json['error'])) {
  1848. if (is_uploaded_file($this->request->files['file']['tmp_name']) && file_exists($this->request->files['file']['tmp_name'])) {
  1849. $file = basename($filename) . '.' . md5(mt_rand());
  1850. $json['file'] = $file;
  1851. move_uploaded_file($this->request->files['file']['tmp_name'], DIR_DOWNLOAD . $file);
  1852. }
  1853. $json['success'] = $this->language->get('text_upload');
  1854. }
  1855. }
  1856. $this->response->setOutput(json_encode($json));
  1857. }
  1858. public function invoice() {
  1859. $this->language->load('sale/order');
  1860. $this->data['title'] = $this->language->get('heading_title');
  1861. if (isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == 'on') || ($this->request->server['HTTPS'] == '1'))) {
  1862. $this->data['base'] = HTTPS_SERVER;
  1863. } else {
  1864. $this->data['base'] = HTTP_SERVER;
  1865. }
  1866. $this->data['direction'] = $this->language->get('direction');
  1867. $this->data['language'] = $this->language->get('code');
  1868. $this->data['text_invoice'] = $this->language->get('text_invoice');
  1869. $this->data['text_order_id'] = $this->language->get('text_order_id');
  1870. $this->data['text_invoice_no'] = $this->language->get('text_invoice_no');
  1871. $this->data['text_invoice_date'] = $this->language->get('text_invoice_date');
  1872. $this->data['text_date_added'] = $this->language->get('text_date_added');
  1873. $this->data['text_telephone'] = $this->language->get('text_telephone');
  1874. $this->data['text_fax'] = $this->language->get('text_fax');
  1875. $this->data['text_to'] = $this->language->get('text_to');
  1876. $this->data['text_company_id'] = $this->language->get('text_company_id');
  1877. $this->data['text_tax_id'] = $this->language->get('text_tax_id');
  1878. $this->data['text_ship_to'] = $this->language->get('text_ship_to');
  1879. $this->data['text_payment_method'] = $this->language->get('text_payment_method');
  1880. $this->data['text_shipping_method'] = $this->language->get('text_shipping_method');
  1881. $this->data['column_product'] = $this->language->get('column_product');
  1882. $this->data['column_model'] = $this->language->get('column_model');
  1883. $this->data['column_quantity'] = $this->language->get('column_quantity');
  1884. $this->data['column_price'] = $this->language->get('column_price');
  1885. $this->data['column_total'] = $this->language->get('column_total');
  1886. $this->data['column_comment'] = $this->language->get('column_comment');
  1887. $this->load->model('sale/order');
  1888. $this->load->model('setting/setting');
  1889. $this->data['orders'] = array();
  1890. $orders = array();
  1891. if (isset($this->request->post['selected'])) {
  1892. $orders = $this->request->post['selected'];
  1893. } elseif (isset($this->request->get['order_id'])) {
  1894. $orders[] = $this->request->get['order_id'];
  1895. }
  1896. foreach ($orders as $order_id) {
  1897. $order_info = $this->model_sale_order->getOrder($order_id);
  1898. if ($order_info) {
  1899. $store_info = $this->model_setting_setting->getSetting('config', $order_info['store_id']);
  1900. if ($store_info) {
  1901. $store_address = $store_info['config_address'];
  1902. $store_email = $store_info['config_email'];
  1903. $store_telephone = $store_info['config_telephone'];
  1904. $store_fax = $store_info['config_fax'];
  1905. } else {
  1906. $store_address = $this->config->get('config_address');
  1907. $store_email = $this->config->get('config_email');
  1908. $store_telephone = $this->config->get('config_telephone');
  1909. $store_fax = $this->config->get('config_fax');
  1910. }
  1911. if ($order_info['invoice_no']) {
  1912. $invoice_no = $order_info['invoice_prefix'] . $order_info['invoice_no'];
  1913. } else {
  1914. $invoice_no = '';
  1915. }
  1916. if ($order_info['shipping_address_format']) {
  1917. $format = $order_info['shipping_address_format'];
  1918. } else {
  1919. $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
  1920. }
  1921. $find = array(
  1922. '{firstname}',
  1923. '{lastname}',
  1924. '{company}',
  1925. '{address_1}',
  1926. '{address_2}',
  1927. '{city}',
  1928. '{postcode}',
  1929. '{zone}',
  1930. '{zone_code}',
  1931. '{country}'
  1932. );
  1933. $replace = array(
  1934. 'firstname' => $order_info['shipping_firstname'],
  1935. 'lastname' => $order_info['shipping_lastname'],
  1936. 'company' => $order_info['shipping_company'],
  1937. 'address_1' => $order_info['shipping_address_1'],
  1938. 'address_2' => $order_info['shipping_address_2'],
  1939. 'city' => $order_info['shipping_city'],
  1940. 'postcode' => $order_info['shipping_postcode'],
  1941. 'zone' => $order_info['shipping_zone'],
  1942. 'zone_code' => $order_info['shipping_zone_code'],
  1943. 'country' => $order_info['shipping_country']
  1944. );
  1945. $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))));
  1946. if ($order_info['payment_address_format']) {
  1947. $format = $order_info['payment_address_format'];
  1948. } else {
  1949. $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
  1950. }
  1951. $find = array(
  1952. '{firstname}',
  1953. '{lastname}',
  1954. '{company}',
  1955. '{address_1}',
  1956. '{address_2}',
  1957. '{city}',
  1958. '{postcode}',
  1959. '{zone}',
  1960. '{zone_code}',
  1961. '{country}'
  1962. );
  1963. $replace = array(
  1964. 'firstname' => $order_info['payment_firstname'],
  1965. 'lastname' => $order_info['payment_lastname'],
  1966. 'company' => $order_info['payment_company'],
  1967. 'address_1' => $order_info['payment_address_1'],
  1968. 'address_2' => $order_info['payment_address_2'],
  1969. 'city' => $order_info['payment_city'],
  1970. 'postcode' => $order_info['payment_postcode'],
  1971. 'zone' => $order_info['payment_zone'],
  1972. 'zone_code' => $order_info['payment_zone_code'],
  1973. 'country' => $order_info['payment_country']
  1974. );
  1975. $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))));
  1976. $product_data = array();
  1977. $products = $this->model_sale_order->getOrderProducts($order_id);
  1978. foreach ($products as $product) {
  1979. $option_data = array();
  1980. $options = $this->model_sale_order->getOrderOptions($order_id, $product['order_product_id']);
  1981. foreach ($options as $option) {
  1982. if ($option['type'] != 'file') {
  1983. $value = $option['value'];
  1984. } else {
  1985. $value = utf8_substr($option['value'], 0, utf8_strrpos($option['value'], '.'));
  1986. }
  1987. $option_data[] = array(
  1988. 'name' => $option['name'],
  1989. 'value' => $value
  1990. );
  1991. }
  1992. $product_data[] = array(
  1993. 'name' => $product['name'],
  1994. 'model' => $product['model'],
  1995. 'option' => $option_data,
  1996. 'quantity' => $product['quantity'],
  1997. 'price' => $this->currency->format($product['price'] + ($this->config->get('config_tax') ? $product['tax'] : 0), $order_info['currency_code'], $order_info['currency_value']),
  1998. 'total' => $this->currency->format($product['total'] + ($this->config->get('config_tax') ? ($product['tax'] * $product['quantity']) : 0), $order_info['currency_code'], $order_info['currency_value'])
  1999. );
  2000. }
  2001. $voucher_data = array();
  2002. $vouchers = $this->model_sale_order->getOrderVouchers($order_id);
  2003. foreach ($vouchers as $voucher) {
  2004. $voucher_data[] = array(
  2005. 'description' => $voucher['description'],
  2006. 'amount' => $this->currency->format($voucher['amount'], $order_info['currency_code'], $order_info['currency_value'])
  2007. );
  2008. }
  2009. $total_data = $this->model_sale_order->getOrderTotals($order_id);
  2010. $this->data['orders'][] = array(
  2011. 'order_id' => $order_id,
  2012. 'invoice_no' => $invoice_no,
  2013. 'date_added' => date($this->language->get('date_format_short'), strtotime($order_info['date_added'])),
  2014. 'store_name' => $order_info['store_name'],
  2015. 'store_url' => rtrim($order_info['store_url'], '/'),
  2016. 'store_address' => nl2br($store_address),
  2017. 'store_email' => $store_email,
  2018. 'store_telephone' => $store_telephone,
  2019. 'store_fax' => $store_fax,
  2020. 'email' => $order_info['email'],
  2021. 'telephone' => $order_info['telephone'],
  2022. 'shipping_address' => $shipping_address,
  2023. 'shipping_method' => $order_info['shipping_method'],
  2024. 'payment_address' => $payment_address,
  2025. 'payment_company_id' => $order_info['payment_company_id'],
  2026. 'payment_tax_id' => $order_info['payment_tax_id'],
  2027. 'payment_method' => $order_info['payment_method'],
  2028. 'product' => $product_data,
  2029. 'voucher' => $voucher_data,
  2030. 'total' => $total_data,
  2031. 'comment' => nl2br($order_info['comment'])
  2032. );
  2033. }
  2034. }
  2035. $this->template = 'sale/order_invoice.tpl';
  2036. $this->response->setOutput($this->render());
  2037. }
  2038. }
  2039. ?>