/upload/admin/controller/sale/order.php

https://github.com/opencartlite/opencart · PHP · 2261 lines · 1759 code · 498 blank · 4 comment · 456 complexity · 11f71a6f85ab1802aae402b4b89fa913 MD5 · raw file

  1. <?php
  2. class ControllerSaleOrder extends Controller {
  3. private $error = array();
  4. public function index() {
  5. $this->data += $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->data += $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->data += $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->data += $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. }
  96. $this->session->data['success'] = $this->language->get('text_success');
  97. $url = '';
  98. if (isset($this->request->get['filter_order_id'])) {
  99. $url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
  100. }
  101. if (isset($this->request->get['filter_customer'])) {
  102. $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
  103. }
  104. if (isset($this->request->get['filter_order_status_id'])) {
  105. $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id'];
  106. }
  107. if (isset($this->request->get['filter_total'])) {
  108. $url .= '&filter_total=' . $this->request->get['filter_total'];
  109. }
  110. if (isset($this->request->get['filter_date_added'])) {
  111. $url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
  112. }
  113. if (isset($this->request->get['filter_date_modified'])) {
  114. $url .= '&filter_date_modified=' . $this->request->get['filter_date_modified'];
  115. }
  116. if (isset($this->request->get['sort'])) {
  117. $url .= '&sort=' . $this->request->get['sort'];
  118. }
  119. if (isset($this->request->get['order'])) {
  120. $url .= '&order=' . $this->request->get['order'];
  121. }
  122. if (isset($this->request->get['page'])) {
  123. $url .= '&page=' . $this->request->get['page'];
  124. }
  125. $this->redirect($this->url->link('sale/order', 'token=' . $this->session->data['token'] . $url, 'SSL'));
  126. }
  127. $this->getList();
  128. }
  129. protected function getList() {
  130. if (isset($this->request->get['filter_order_id'])) {
  131. $filter_order_id = $this->request->get['filter_order_id'];
  132. } else {
  133. $filter_order_id = null;
  134. }
  135. if (isset($this->request->get['filter_customer'])) {
  136. $filter_customer = $this->request->get['filter_customer'];
  137. } else {
  138. $filter_customer = null;
  139. }
  140. if (isset($this->request->get['filter_order_status_id'])) {
  141. $filter_order_status_id = $this->request->get['filter_order_status_id'];
  142. } else {
  143. $filter_order_status_id = null;
  144. }
  145. if (isset($this->request->get['filter_total'])) {
  146. $filter_total = $this->request->get['filter_total'];
  147. } else {
  148. $filter_total = null;
  149. }
  150. if (isset($this->request->get['filter_date_added'])) {
  151. $filter_date_added = $this->request->get['filter_date_added'];
  152. } else {
  153. $filter_date_added = null;
  154. }
  155. if (isset($this->request->get['filter_date_modified'])) {
  156. $filter_date_modified = $this->request->get['filter_date_modified'];
  157. } else {
  158. $filter_date_modified = null;
  159. }
  160. if (isset($this->request->get['sort'])) {
  161. $sort = $this->request->get['sort'];
  162. } else {
  163. $sort = 'o.order_id';
  164. }
  165. if (isset($this->request->get['order'])) {
  166. $order = $this->request->get['order'];
  167. } else {
  168. $order = 'DESC';
  169. }
  170. if (isset($this->request->get['page'])) {
  171. $page = $this->request->get['page'];
  172. } else {
  173. $page = 1;
  174. }
  175. $url = '';
  176. if (isset($this->request->get['filter_order_id'])) {
  177. $url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
  178. }
  179. if (isset($this->request->get['filter_customer'])) {
  180. $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
  181. }
  182. if (isset($this->request->get['filter_order_status_id'])) {
  183. $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id'];
  184. }
  185. if (isset($this->request->get['filter_total'])) {
  186. $url .= '&filter_total=' . $this->request->get['filter_total'];
  187. }
  188. if (isset($this->request->get['filter_date_added'])) {
  189. $url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
  190. }
  191. if (isset($this->request->get['filter_date_modified'])) {
  192. $url .= '&filter_date_modified=' . $this->request->get['filter_date_modified'];
  193. }
  194. if (isset($this->request->get['sort'])) {
  195. $url .= '&sort=' . $this->request->get['sort'];
  196. }
  197. if (isset($this->request->get['order'])) {
  198. $url .= '&order=' . $this->request->get['order'];
  199. }
  200. if (isset($this->request->get['page'])) {
  201. $url .= '&page=' . $this->request->get['page'];
  202. }
  203. $this->data['breadcrumbs'] = array();
  204. $this->data['breadcrumbs'][] = array(
  205. 'text' => $this->language->get('text_home'),
  206. 'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL')
  207. );
  208. $this->data['breadcrumbs'][] = array(
  209. 'text' => $this->language->get('heading_title'),
  210. 'href' => $this->url->link('sale/order', 'token=' . $this->session->data['token'] . $url, 'SSL')
  211. );
  212. $this->data['invoice'] = $this->url->link('sale/order/invoice', 'token=' . $this->session->data['token'], 'SSL');
  213. $this->data['insert'] = $this->url->link('sale/order/insert', 'token=' . $this->session->data['token'], 'SSL');
  214. $this->data['delete'] = $this->url->link('sale/order/delete', 'token=' . $this->session->data['token'] . $url, 'SSL');
  215. $this->data['orders'] = array();
  216. $data = array(
  217. 'filter_order_id' => $filter_order_id,
  218. 'filter_customer' => $filter_customer,
  219. 'filter_order_status_id' => $filter_order_status_id,
  220. 'filter_total' => $filter_total,
  221. 'filter_date_added' => $filter_date_added,
  222. 'filter_date_modified' => $filter_date_modified,
  223. 'sort' => $sort,
  224. 'order' => $order,
  225. 'start' => ($page - 1) * $this->config->get('config_admin_limit'),
  226. 'limit' => $this->config->get('config_admin_limit')
  227. );
  228. $order_total = $this->model_sale_order->getTotalOrders($data);
  229. $results = $this->model_sale_order->getOrders($data);
  230. foreach ($results as $result) {
  231. $action = array();
  232. $action[] = array(
  233. 'text' => $this->language->get('text_view'),
  234. 'href' => $this->url->link('sale/order/info', 'token=' . $this->session->data['token'] . '&order_id=' . $result['order_id'] . $url, 'SSL')
  235. );
  236. if (strtotime($result['date_added']) > strtotime('-' . (int)$this->config->get('config_order_edit') . ' day')) {
  237. $action[] = array(
  238. 'text' => $this->language->get('text_edit'),
  239. 'href' => $this->url->link('sale/order/update', 'token=' . $this->session->data['token'] . '&order_id=' . $result['order_id'] . $url, 'SSL')
  240. );
  241. }
  242. $this->data['orders'][] = array(
  243. 'order_id' => $result['order_id'],
  244. 'customer' => $result['customer'],
  245. 'status' => $result['status'],
  246. 'total' => $this->currency->format($result['total'], $result['currency_code'], $result['currency_value']),
  247. 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
  248. 'date_modified' => date($this->language->get('date_format_short'), strtotime($result['date_modified'])),
  249. 'selected' => isset($this->request->post['selected']) && in_array($result['order_id'], $this->request->post['selected']),
  250. 'action' => $action
  251. );
  252. }
  253. $this->data['token'] = $this->session->data['token'];
  254. if (isset($this->error['warning'])) {
  255. $this->data['error_warning'] = $this->error['warning'];
  256. } else {
  257. $this->data['error_warning'] = '';
  258. }
  259. if (isset($this->session->data['success'])) {
  260. $this->data['success'] = $this->session->data['success'];
  261. unset($this->session->data['success']);
  262. } else {
  263. $this->data['success'] = '';
  264. }
  265. $url = '';
  266. if (isset($this->request->get['filter_order_id'])) {
  267. $url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
  268. }
  269. if (isset($this->request->get['filter_customer'])) {
  270. $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
  271. }
  272. if (isset($this->request->get['filter_order_status_id'])) {
  273. $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id'];
  274. }
  275. if (isset($this->request->get['filter_total'])) {
  276. $url .= '&filter_total=' . $this->request->get['filter_total'];
  277. }
  278. if (isset($this->request->get['filter_date_added'])) {
  279. $url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
  280. }
  281. if (isset($this->request->get['filter_date_modified'])) {
  282. $url .= '&filter_date_modified=' . $this->request->get['filter_date_modified'];
  283. }
  284. if ($order == 'ASC') {
  285. $url .= '&order=DESC';
  286. } else {
  287. $url .= '&order=ASC';
  288. }
  289. if (isset($this->request->get['page'])) {
  290. $url .= '&page=' . $this->request->get['page'];
  291. }
  292. $this->data['sort_order'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . '&sort=o.order_id' . $url, 'SSL');
  293. $this->data['sort_customer'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . '&sort=customer' . $url, 'SSL');
  294. $this->data['sort_status'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . '&sort=status' . $url, 'SSL');
  295. $this->data['sort_total'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . '&sort=o.total' . $url, 'SSL');
  296. $this->data['sort_date_added'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . '&sort=o.date_added' . $url, 'SSL');
  297. $this->data['sort_date_modified'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . '&sort=o.date_modified' . $url, 'SSL');
  298. $url = '';
  299. if (isset($this->request->get['filter_order_id'])) {
  300. $url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
  301. }
  302. if (isset($this->request->get['filter_customer'])) {
  303. $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
  304. }
  305. if (isset($this->request->get['filter_order_status_id'])) {
  306. $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id'];
  307. }
  308. if (isset($this->request->get['filter_total'])) {
  309. $url .= '&filter_total=' . $this->request->get['filter_total'];
  310. }
  311. if (isset($this->request->get['filter_date_added'])) {
  312. $url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
  313. }
  314. if (isset($this->request->get['filter_date_modified'])) {
  315. $url .= '&filter_date_modified=' . $this->request->get['filter_date_modified'];
  316. }
  317. if (isset($this->request->get['sort'])) {
  318. $url .= '&sort=' . $this->request->get['sort'];
  319. }
  320. if (isset($this->request->get['order'])) {
  321. $url .= '&order=' . $this->request->get['order'];
  322. }
  323. $pagination = new Pagination();
  324. $pagination->total = $order_total;
  325. $pagination->page = $page;
  326. $pagination->limit = $this->config->get('config_admin_limit');
  327. $pagination->text = $this->language->get('text_pagination');
  328. $pagination->url = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . $url . '&page={page}', 'SSL');
  329. $this->data['pagination'] = $pagination->render();
  330. $this->data['filter_order_id'] = $filter_order_id;
  331. $this->data['filter_customer'] = $filter_customer;
  332. $this->data['filter_order_status_id'] = $filter_order_status_id;
  333. $this->data['filter_total'] = $filter_total;
  334. $this->data['filter_date_added'] = $filter_date_added;
  335. $this->data['filter_date_modified'] = $filter_date_modified;
  336. $this->load->model('localisation/order_status');
  337. $this->data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
  338. $this->data['sort'] = $sort;
  339. $this->data['order'] = $order;
  340. $this->template = 'sale/order_list.tpl';
  341. $this->children = array(
  342. 'common/header',
  343. 'common/footer'
  344. );
  345. $this->response->setOutput($this->render());
  346. }
  347. public function getForm() {
  348. $this->load->model('sale/customer');
  349. if (isset($this->error['warning'])) {
  350. $this->data['error_warning'] = $this->error['warning'];
  351. } else {
  352. $this->data['error_warning'] = '';
  353. }
  354. if (isset($this->error['firstname'])) {
  355. $this->data['error_firstname'] = $this->error['firstname'];
  356. } else {
  357. $this->data['error_firstname'] = '';
  358. }
  359. if (isset($this->error['lastname'])) {
  360. $this->data['error_lastname'] = $this->error['lastname'];
  361. } else {
  362. $this->data['error_lastname'] = '';
  363. }
  364. if (isset($this->error['email'])) {
  365. $this->data['error_email'] = $this->error['email'];
  366. } else {
  367. $this->data['error_email'] = '';
  368. }
  369. if (isset($this->error['telephone'])) {
  370. $this->data['error_telephone'] = $this->error['telephone'];
  371. } else {
  372. $this->data['error_telephone'] = '';
  373. }
  374. if (isset($this->error['payment_firstname'])) {
  375. $this->data['error_payment_firstname'] = $this->error['payment_firstname'];
  376. } else {
  377. $this->data['error_payment_firstname'] = '';
  378. }
  379. if (isset($this->error['payment_lastname'])) {
  380. $this->data['error_payment_lastname'] = $this->error['payment_lastname'];
  381. } else {
  382. $this->data['error_payment_lastname'] = '';
  383. }
  384. if (isset($this->error['payment_address_1'])) {
  385. $this->data['error_payment_address_1'] = $this->error['payment_address_1'];
  386. } else {
  387. $this->data['error_payment_address_1'] = '';
  388. }
  389. if (isset($this->error['payment_city'])) {
  390. $this->data['error_payment_city'] = $this->error['payment_city'];
  391. } else {
  392. $this->data['error_payment_city'] = '';
  393. }
  394. if (isset($this->error['payment_postcode'])) {
  395. $this->data['error_payment_postcode'] = $this->error['payment_postcode'];
  396. } else {
  397. $this->data['error_payment_postcode'] = '';
  398. }
  399. if (isset($this->error['payment_country'])) {
  400. $this->data['error_payment_country'] = $this->error['payment_country'];
  401. } else {
  402. $this->data['error_payment_country'] = '';
  403. }
  404. if (isset($this->error['payment_zone'])) {
  405. $this->data['error_payment_zone'] = $this->error['payment_zone'];
  406. } else {
  407. $this->data['error_payment_zone'] = '';
  408. }
  409. if (isset($this->error['payment_method'])) {
  410. $this->data['error_payment_method'] = $this->error['payment_method'];
  411. } else {
  412. $this->data['error_payment_method'] = '';
  413. }
  414. if (isset($this->error['shipping_firstname'])) {
  415. $this->data['error_shipping_firstname'] = $this->error['shipping_firstname'];
  416. } else {
  417. $this->data['error_shipping_firstname'] = '';
  418. }
  419. if (isset($this->error['shipping_lastname'])) {
  420. $this->data['error_shipping_lastname'] = $this->error['shipping_lastname'];
  421. } else {
  422. $this->data['error_shipping_lastname'] = '';
  423. }
  424. if (isset($this->error['shipping_address_1'])) {
  425. $this->data['error_shipping_address_1'] = $this->error['shipping_address_1'];
  426. } else {
  427. $this->data['error_shipping_address_1'] = '';
  428. }
  429. if (isset($this->error['shipping_city'])) {
  430. $this->data['error_shipping_city'] = $this->error['shipping_city'];
  431. } else {
  432. $this->data['error_shipping_city'] = '';
  433. }
  434. if (isset($this->error['shipping_postcode'])) {
  435. $this->data['error_shipping_postcode'] = $this->error['shipping_postcode'];
  436. } else {
  437. $this->data['error_shipping_postcode'] = '';
  438. }
  439. if (isset($this->error['shipping_country'])) {
  440. $this->data['error_shipping_country'] = $this->error['shipping_country'];
  441. } else {
  442. $this->data['error_shipping_country'] = '';
  443. }
  444. if (isset($this->error['shipping_zone'])) {
  445. $this->data['error_shipping_zone'] = $this->error['shipping_zone'];
  446. } else {
  447. $this->data['error_shipping_zone'] = '';
  448. }
  449. if (isset($this->error['shipping_method'])) {
  450. $this->data['error_shipping_method'] = $this->error['shipping_method'];
  451. } else {
  452. $this->data['error_shipping_method'] = '';
  453. }
  454. $url = '';
  455. if (isset($this->request->get['filter_order_id'])) {
  456. $url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
  457. }
  458. if (isset($this->request->get['filter_customer'])) {
  459. $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
  460. }
  461. if (isset($this->request->get['filter_order_status_id'])) {
  462. $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id'];
  463. }
  464. if (isset($this->request->get['filter_total'])) {
  465. $url .= '&filter_total=' . $this->request->get['filter_total'];
  466. }
  467. if (isset($this->request->get['filter_date_added'])) {
  468. $url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
  469. }
  470. if (isset($this->request->get['filter_date_modified'])) {
  471. $url .= '&filter_date_modified=' . $this->request->get['filter_date_modified'];
  472. }
  473. if (isset($this->request->get['sort'])) {
  474. $url .= '&sort=' . $this->request->get['sort'];
  475. }
  476. if (isset($this->request->get['order'])) {
  477. $url .= '&order=' . $this->request->get['order'];
  478. }
  479. if (isset($this->request->get['page'])) {
  480. $url .= '&page=' . $this->request->get['page'];
  481. }
  482. $this->data['breadcrumbs'] = array();
  483. $this->data['breadcrumbs'][] = array(
  484. 'text' => $this->language->get('text_home'),
  485. 'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL')
  486. );
  487. $this->data['breadcrumbs'][] = array(
  488. 'text' => $this->language->get('heading_title'),
  489. 'href' => $this->url->link('sale/order', 'token=' . $this->session->data['token'] . $url, 'SSL')
  490. );
  491. if (!isset($this->request->get['order_id'])) {
  492. $this->data['action'] = $this->url->link('sale/order/insert', 'token=' . $this->session->data['token'] . $url, 'SSL');
  493. } else {
  494. $this->data['action'] = $this->url->link('sale/order/update', 'token=' . $this->session->data['token'] . '&order_id=' . $this->request->get['order_id'] . $url, 'SSL');
  495. }
  496. $this->data['cancel'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . $url, 'SSL');
  497. if (isset($this->request->get['order_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
  498. $order_info = $this->model_sale_order->getOrder($this->request->get['order_id']);
  499. }
  500. $this->data['token'] = $this->session->data['token'];
  501. if (isset($this->request->get['order_id'])) {
  502. $this->data['order_id'] = $this->request->get['order_id'];
  503. } else {
  504. $this->data['order_id'] = 0;
  505. }
  506. if (isset($this->request->post['store_id'])) {
  507. $this->data['store_id'] = $this->request->post['store_id'];
  508. } elseif (!empty($order_info)) {
  509. $this->data['store_id'] = $order_info['store_id'];
  510. } else {
  511. $this->data['store_id'] = '';
  512. }
  513. $this->load->model('setting/store');
  514. $this->data['stores'] = $this->model_setting_store->getStores();
  515. if (isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == 'on') || ($this->request->server['HTTPS'] == '1'))) {
  516. $this->data['store_url'] = HTTPS_CATALOG;
  517. } else {
  518. $this->data['store_url'] = HTTP_CATALOG;
  519. }
  520. if (isset($this->request->post['customer'])) {
  521. $this->data['customer'] = $this->request->post['customer'];
  522. } elseif (!empty($order_info)) {
  523. $this->data['customer'] = $order_info['customer'];
  524. } else {
  525. $this->data['customer'] = '';
  526. }
  527. if (isset($this->request->post['customer_id'])) {
  528. $this->data['customer_id'] = $this->request->post['customer_id'];
  529. } elseif (!empty($order_info)) {
  530. $this->data['customer_id'] = $order_info['customer_id'];
  531. } else {
  532. $this->data['customer_id'] = '';
  533. }
  534. if (isset($this->request->post['customer_group_id'])) {
  535. $this->data['customer_group_id'] = $this->request->post['customer_group_id'];
  536. } elseif (!empty($order_info)) {
  537. $this->data['customer_group_id'] = $order_info['customer_group_id'];
  538. } else {
  539. $this->data['customer_group_id'] = '';
  540. }
  541. $this->load->model('sale/customer_group');
  542. $this->data['customer_groups'] = $this->model_sale_customer_group->getCustomerGroups();
  543. if (isset($this->request->post['firstname'])) {
  544. $this->data['firstname'] = $this->request->post['firstname'];
  545. } elseif (!empty($order_info)) {
  546. $this->data['firstname'] = $order_info['firstname'];
  547. } else {
  548. $this->data['firstname'] = '';
  549. }
  550. if (isset($this->request->post['lastname'])) {
  551. $this->data['lastname'] = $this->request->post['lastname'];
  552. } elseif (!empty($order_info)) {
  553. $this->data['lastname'] = $order_info['lastname'];
  554. } else {
  555. $this->data['lastname'] = '';
  556. }
  557. if (isset($this->request->post['email'])) {
  558. $this->data['email'] = $this->request->post['email'];
  559. } elseif (!empty($order_info)) {
  560. $this->data['email'] = $order_info['email'];
  561. } else {
  562. $this->data['email'] = '';
  563. }
  564. if (isset($this->request->post['telephone'])) {
  565. $this->data['telephone'] = $this->request->post['telephone'];
  566. } elseif (!empty($order_info)) {
  567. $this->data['telephone'] = $order_info['telephone'];
  568. } else {
  569. $this->data['telephone'] = '';
  570. }
  571. if (isset($this->request->post['fax'])) {
  572. $this->data['fax'] = $this->request->post['fax'];
  573. } elseif (!empty($order_info)) {
  574. $this->data['fax'] = $order_info['fax'];
  575. } else {
  576. $this->data['fax'] = '';
  577. }
  578. if (isset($this->request->post['affiliate_id'])) {
  579. $this->data['affiliate_id'] = $this->request->post['affiliate_id'];
  580. } elseif (!empty($order_info)) {
  581. $this->data['affiliate_id'] = $order_info['affiliate_id'];
  582. } else {
  583. $this->data['affiliate_id'] = '';
  584. }
  585. if (isset($this->request->post['affiliate'])) {
  586. $this->data['affiliate'] = $this->request->post['affiliate'];
  587. } elseif (!empty($order_info)) {
  588. $this->data['affiliate'] = ($order_info['affiliate_id'] ? $order_info['affiliate_firstname'] . ' ' . $order_info['affiliate_lastname'] : '');
  589. } else {
  590. $this->data['affiliate'] = '';
  591. }
  592. if (isset($this->request->post['order_status_id'])) {
  593. $this->data['order_status_id'] = $this->request->post['order_status_id'];
  594. } elseif (!empty($order_info)) {
  595. $this->data['order_status_id'] = $order_info['order_status_id'];
  596. } else {
  597. $this->data['order_status_id'] = '';
  598. }
  599. $this->load->model('localisation/order_status');
  600. $this->data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
  601. if (isset($this->request->post['comment'])) {
  602. $this->data['comment'] = $this->request->post['comment'];
  603. } elseif (!empty($order_info)) {
  604. $this->data['comment'] = $order_info['comment'];
  605. } else {
  606. $this->data['comment'] = '';
  607. }
  608. $this->load->model('sale/customer');
  609. if (isset($this->request->post['customer_id'])) {
  610. $this->data['addresses'] = $this->model_sale_customer->getAddresses($this->request->post['customer_id']);
  611. } elseif (!empty($order_info)) {
  612. $this->data['addresses'] = $this->model_sale_customer->getAddresses($order_info['customer_id']);
  613. } else {
  614. $this->data['addresses'] = array();
  615. }
  616. if (isset($this->request->post['payment_firstname'])) {
  617. $this->data['payment_firstname'] = $this->request->post['payment_firstname'];
  618. } elseif (!empty($order_info)) {
  619. $this->data['payment_firstname'] = $order_info['payment_firstname'];
  620. } else {
  621. $this->data['payment_firstname'] = '';
  622. }
  623. if (isset($this->request->post['payment_lastname'])) {
  624. $this->data['payment_lastname'] = $this->request->post['payment_lastname'];
  625. } elseif (!empty($order_info)) {
  626. $this->data['payment_lastname'] = $order_info['payment_lastname'];
  627. } else {
  628. $this->data['payment_lastname'] = '';
  629. }
  630. if (isset($this->request->post['payment_company'])) {
  631. $this->data['payment_company'] = $this->request->post['payment_company'];
  632. } elseif (!empty($order_info)) {
  633. $this->data['payment_company'] = $order_info['payment_company'];
  634. } else {
  635. $this->data['payment_company'] = '';
  636. }
  637. if (isset($this->request->post['payment_address_1'])) {
  638. $this->data['payment_address_1'] = $this->request->post['payment_address_1'];
  639. } elseif (!empty($order_info)) {
  640. $this->data['payment_address_1'] = $order_info['payment_address_1'];
  641. } else {
  642. $this->data['payment_address_1'] = '';
  643. }
  644. if (isset($this->request->post['payment_address_2'])) {
  645. $this->data['payment_address_2'] = $this->request->post['payment_address_2'];
  646. } elseif (!empty($order_info)) {
  647. $this->data['payment_address_2'] = $order_info['payment_address_2'];
  648. } else {
  649. $this->data['payment_address_2'] = '';
  650. }
  651. if (isset($this->request->post['payment_city'])) {
  652. $this->data['payment_city'] = $this->request->post['payment_city'];
  653. } elseif (!empty($order_info)) {
  654. $this->data['payment_city'] = $order_info['payment_city'];
  655. } else {
  656. $this->data['payment_city'] = '';
  657. }
  658. if (isset($this->request->post['payment_postcode'])) {
  659. $this->data['payment_postcode'] = $this->request->post['payment_postcode'];
  660. } elseif (!empty($order_info)) {
  661. $this->data['payment_postcode'] = $order_info['payment_postcode'];
  662. } else {
  663. $this->data['payment_postcode'] = '';
  664. }
  665. if (isset($this->request->post['payment_country_id'])) {
  666. $this->data['payment_country_id'] = $this->request->post['payment_country_id'];
  667. } elseif (!empty($order_info)) {
  668. $this->data['payment_country_id'] = $order_info['payment_country_id'];
  669. } else {
  670. $this->data['payment_country_id'] = '';
  671. }
  672. if (isset($this->request->post['payment_zone_id'])) {
  673. $this->data['payment_zone_id'] = $this->request->post['payment_zone_id'];
  674. } elseif (!empty($order_info)) {
  675. $this->data['payment_zone_id'] = $order_info['payment_zone_id'];
  676. } else {
  677. $this->data['payment_zone_id'] = '';
  678. }
  679. if (isset($this->request->post['payment_method'])) {
  680. $this->data['payment_method'] = $this->request->post['payment_method'];
  681. } elseif (!empty($order_info)) {
  682. $this->data['payment_method'] = $order_info['payment_method'];
  683. } else {
  684. $this->data['payment_method'] = '';
  685. }
  686. if (isset($this->request->post['payment_code'])) {
  687. $this->data['payment_code'] = $this->request->post['payment_code'];
  688. } elseif (!empty($order_info)) {
  689. $this->data['payment_code'] = $order_info['payment_code'];
  690. } else {
  691. $this->data['payment_code'] = '';
  692. }
  693. if (isset($this->request->post['shipping_firstname'])) {
  694. $this->data['shipping_firstname'] = $this->request->post['shipping_firstname'];
  695. } elseif (!empty($order_info)) {
  696. $this->data['shipping_firstname'] = $order_info['shipping_firstname'];
  697. } else {
  698. $this->data['shipping_firstname'] = '';
  699. }
  700. if (isset($this->request->post['shipping_lastname'])) {
  701. $this->data['shipping_lastname'] = $this->request->post['shipping_lastname'];
  702. } elseif (!empty($order_info)) {
  703. $this->data['shipping_lastname'] = $order_info['shipping_lastname'];
  704. } else {
  705. $this->data['shipping_lastname'] = '';
  706. }
  707. if (isset($this->request->post['shipping_company'])) {
  708. $this->data['shipping_company'] = $this->request->post['shipping_company'];
  709. } elseif (!empty($order_info)) {
  710. $this->data['shipping_company'] = $order_info['shipping_company'];
  711. } else {
  712. $this->data['shipping_company'] = '';
  713. }
  714. if (isset($this->request->post['shipping_address_1'])) {
  715. $this->data['shipping_address_1'] = $this->request->post['shipping_address_1'];
  716. } elseif (!empty($order_info)) {
  717. $this->data['shipping_address_1'] = $order_info['shipping_address_1'];
  718. } else {
  719. $this->data['shipping_address_1'] = '';
  720. }
  721. if (isset($this->request->post['shipping_address_2'])) {
  722. $this->data['shipping_address_2'] = $this->request->post['shipping_address_2'];
  723. } elseif (!empty($order_info)) {
  724. $this->data['shipping_address_2'] = $order_info['shipping_address_2'];
  725. } else {
  726. $this->data['shipping_address_2'] = '';
  727. }
  728. if (isset($this->request->post['shipping_city'])) {
  729. $this->data['shipping_city'] = $this->request->post['shipping_city'];
  730. } elseif (!empty($order_info)) {
  731. $this->data['shipping_city'] = $order_info['shipping_city'];
  732. } else {
  733. $this->data['shipping_city'] = '';
  734. }
  735. if (isset($this->request->post['shipping_postcode'])) {
  736. $this->data['shipping_postcode'] = $this->request->post['shipping_postcode'];
  737. } elseif (!empty($order_info)) {
  738. $this->data['shipping_postcode'] = $order_info['shipping_postcode'];
  739. } else {
  740. $this->data['shipping_postcode'] = '';
  741. }
  742. if (isset($this->request->post['shipping_country_id'])) {
  743. $this->data['shipping_country_id'] = $this->request->post['shipping_country_id'];
  744. } elseif (!empty($order_info)) {
  745. $this->data['shipping_country_id'] = $order_info['shipping_country_id'];
  746. } else {
  747. $this->data['shipping_country_id'] = '';
  748. }
  749. if (isset($this->request->post['shipping_zone_id'])) {
  750. $this->data['shipping_zone_id'] = $this->request->post['shipping_zone_id'];
  751. } elseif (!empty($order_info)) {
  752. $this->data['shipping_zone_id'] = $order_info['shipping_zone_id'];
  753. } else {
  754. $this->data['shipping_zone_id'] = '';
  755. }
  756. $this->load->model('localisation/country');
  757. $this->data['countries'] = $this->model_localisation_country->getCountries();
  758. if (isset($this->request->post['shipping_method'])) {
  759. $this->data['shipping_method'] = $this->request->post['shipping_method'];
  760. } elseif (!empty($order_info)) {
  761. $this->data['shipping_method'] = $order_info['shipping_method'];
  762. } else {
  763. $this->data['shipping_method'] = '';
  764. }
  765. if (isset($this->request->post['shipping_code'])) {
  766. $this->data['shipping_code'] = $this->request->post['shipping_code'];
  767. } elseif (!empty($order_info)) {
  768. $this->data['shipping_code'] = $order_info['shipping_code'];
  769. } else {
  770. $this->data['shipping_code'] = '';
  771. }
  772. if (isset($this->request->post['order_product'])) {
  773. $order_products = $this->request->post['order_product'];
  774. } elseif (isset($this->request->get['order_id'])) {
  775. $order_products = $this->model_sale_order->getOrderProducts($this->request->get['order_id']);
  776. } else {
  777. $order_products = array();
  778. }
  779. $this->load->model('catalog/product');
  780. $this->data['order_products'] = array();
  781. foreach ($order_products as $order_product) {
  782. if (isset($order_product['order_option'])) {
  783. $order_option = $order_product['order_option'];
  784. } elseif (isset($this->request->get['order_id'])) {
  785. $order_option = $this->model_sale_order->getOrderOptions($this->request->get['order_id'], $order_product['order_product_id']);
  786. } else {
  787. $order_option = array();
  788. }
  789. if (isset($order_product['order_download'])) {
  790. $order_download = $order_product['order_download'];
  791. } elseif (isset($this->request->get['order_id'])) {
  792. $order_download = $this->model_sale_order->getOrderDownloads($this->request->get['order_id'], $order_product['order_product_id']);
  793. } else {
  794. $order_download = array();
  795. }
  796. $this->data['order_products'][] = array(
  797. 'order_product_id' => $order_product['order_product_id'],
  798. 'product_id' => $order_product['product_id'],
  799. 'name' => $order_product['name'],
  800. 'model' => $order_product['model'],
  801. 'option' => $order_option,
  802. 'download' => $order_download,
  803. 'quantity' => $order_product['quantity'],
  804. 'price' => $order_product['price'],
  805. 'total' => $order_product['total'],
  806. 'tax' => $order_product['tax'],
  807. 'reward' => $order_product['reward']
  808. );
  809. }
  810. if (isset($this->request->post['order_voucher'])) {
  811. $this->data['order_vouchers'] = $this->request->post['order_voucher'];
  812. } elseif (isset($this->request->get['order_id'])) {
  813. $this->data['order_vouchers'] = $this->model_sale_order->getOrderVouchers($this->request->get['order_id']);
  814. } else {
  815. $this->data['order_vouchers'] = array();
  816. }
  817. $this->load->model('sale/voucher_theme');
  818. $this->data['voucher_themes'] = $this->model_sale_voucher_theme->getVoucherThemes();
  819. if (isset($this->request->post['order_total'])) {
  820. $this->data['order_totals'] = $this->request->post['order_total'];
  821. } elseif (isset($this->request->get['order_id'])) {
  822. $this->data['order_totals'] = $this->model_sale_order->getOrderTotals($this->request->get['order_id']);
  823. } else {
  824. $this->data['order_totals'] = array();
  825. }
  826. $this->template = 'sale/order_form.tpl';
  827. $this->children = array(
  828. 'common/header',
  829. 'common/footer'
  830. );
  831. $this->response->setOutput($this->render());
  832. }
  833. protected function validateForm() {
  834. if (!$this->user->hasPermission('modify', 'sale/order')) {
  835. $this->error['warning'] = $this->language->get('error_permission');
  836. }
  837. if ((utf8_strlen($this->request->post['firstname']) < 1) || (utf8_strlen($this->request->post['firstname']) > 32)) {
  838. $this->error['firstname'] = $this->language->get('error_firstname');
  839. }
  840. if ((utf8_strlen($this->request->post['lastname']) < 1) || (utf8_strlen($this->request->post['lastname']) > 32)) {
  841. $this->error['lastname'] = $this->language->get('error_lastname');
  842. }
  843. if ((utf8_strlen($this->request->post['email']) > 96) || (!preg_match('/^[^\@]+@.*\.[a-z]{2,6}$/i', $this->request->post['email']))) {
  844. $this->error['email'] = $this->language->get('error_email');
  845. }
  846. if ((utf8_strlen($this->request->post['telephone']) < 3) || (utf8_strlen($this->request->post['telephone']) > 32)) {
  847. $this->error['telephone'] = $this->language->get('error_telephone');
  848. }
  849. if ((utf8_strlen($this->request->post['payment_firstname']) < 1) || (utf8_strlen($this->request->post['payment_firstname']) > 32)) {
  850. $this->error['payment_firstname'] = $this->language->get('error_firstname');
  851. }
  852. if ((utf8_strlen($this->request->post['payment_lastname']) < 1) || (utf8_strlen($this->request->post['payment_lastname']) > 32)) {
  853. $this->error['payment_lastname'] = $this->language->get('error_lastname');
  854. }
  855. if ((utf8_strlen($this->request->post['payment_address_1']) < 3) || (utf8_strlen($this->request->post['payment_address_1']) > 128)) {
  856. $this->error['payment_address_1'] = $this->language->get('error_address_1');
  857. }
  858. if ((utf8_strlen($this->request->post['payment_city']) < 3) || (utf8_strlen($this->request->post['payment_city']) > 128)) {
  859. $this->error['payment_city'] = $this->language->get('error_city');
  860. }
  861. $this->load->model('localisation/country');
  862. $country_info = $this->model_localisation_country->getCountry($this->request->post['payment_country_id']);
  863. if ($country_info && $country_info['postcode_required'] && (utf8_strlen($this->request->post['payment_postcode']) < 2) || (utf8_strlen($this->request->post['payment_postcode']) > 10)) {
  864. $this->error['payment_postcode'] = $this->language->get('error_postcode');
  865. }
  866. if ($this->request->post['payment_country_id'] == '') {
  867. $this->error['payment_country'] = $this->language->get('error_country');
  868. }
  869. if (!isset($this->request->post['payment_zone_id']) || $this->request->post['payment_zone_id'] == '') {
  870. $this->error['payment_zone'] = $this->language->get('error_zone');
  871. }
  872. if ($this->request->post['payment_method'] == '') {
  873. $this->error['payment_zone'] = $this->language->get('error_zone');
  874. }
  875. if (!$this->request->post['payment_method']) {
  876. $this->error['payment_method'] = $this->language->get('error_payment');
  877. }
  878. // Check if any products require shipping
  879. $shipping = false;
  880. if (isset($this->request->post['order_product'])) {
  881. $this->load->model('catalog/product');
  882. foreach ($this->request->post['order_product'] as $order_product) {
  883. $product_info = $this->model_catalog_product->getProduct($order_product['product_id']);
  884. if ($product_info && $product_info['shipping']) {
  885. $shipping = true;
  886. }
  887. }
  888. }
  889. if ($shipping) {
  890. if ((utf8_strlen($this->request->post['shipping_firstname']) < 1) || (utf8_strlen($this->request->post['shipping_firstname']) > 32)) {
  891. $this->error['shipping_firstname'] = $this->language->get('error_firstname');
  892. }
  893. if ((utf8_strlen($this->request->post['shipping_lastname']) < 1) || (utf8_strlen($this->request->post['shipping_lastname']) > 32)) {
  894. $this->error['shipping_lastname'] = $this->language->get('error_lastname');
  895. }
  896. if ((utf8_strlen($this->request->post['shipping_address_1']) < 3) || (utf8_strlen($this->request->post['shipping_address_1']) > 128)) {
  897. $this->error['shipping_address_1'] = $this->language->get('error_address_1');
  898. }
  899. if ((utf8_strlen($this->request->post['shipping_city']) < 3) || (utf8_strlen($this->request->post['shipping_city']) > 128)) {
  900. $this->error['shipping_city'] = $this->language->get('error_city');
  901. }
  902. $this->load->model('localisation/country');
  903. $country_info = $this->model_localisation_country->getCountry($this->request->post['shipping_country_id']);
  904. if ($country_info && $country_info['postcode_required'] && (utf8_strlen($this->request->post['shipping_postcode']) < 2) || (utf8_strlen($this->request->post['shipping_postcode']) > 10)) {
  905. $this->error['shipping_postcode'] = $this->language->get('error_postcode');
  906. }
  907. if ($this->request->post['shipping_country_id'] == '') {
  908. $this->error['shipping_country'] = $this->language->get('error_country');
  909. }
  910. if (!isset($this->request->post['shipping_zone_id']) || $this->request->post['shipping_zone_id'] == '') {
  911. $this->error['shipping_zone'] = $this->language->get('error_zone');
  912. }
  913. if (!$this->request->post['shipping_method']) {
  914. $this->error['shipping_method'] = $this->language->get('error_shipping');
  915. }
  916. }
  917. if ($this->error && !isset($this->error['warning'])) {
  918. $this->error['warning'] = $this->language->get('error_warning');
  919. }
  920. if (!$this->error) {
  921. return true;
  922. } else {
  923. return false;
  924. }
  925. }
  926. protected function validateDelete() {
  927. if (!$this->user->hasPermission('modify', 'sale/order')) {
  928. $this->error['warning'] = $this->language->get('error_permission');
  929. }
  930. if (!$this->error) {
  931. return true;
  932. } else {
  933. return false;
  934. }
  935. }
  936. public function country() {
  937. $json = array();
  938. $this->load->model('localisation/country');
  939. $country_info = $this->model_localisation_country->getCountry($this->request->get['country_id']);
  940. if ($country_info) {
  941. $this->load->model('localisation/zone');
  942. $json = array(
  943. 'country_id' => $country_info['country_id'],
  944. 'name' => $country_info['name'],
  945. 'iso_code_2' => $country_info['iso_code_2'],
  946. 'iso_code_3' => $country_info['iso_code_3'],
  947. 'address_format' => $country_info['address_format'],
  948. 'postcode_required' => $country_info['postcode_required'],
  949. 'zone' => $this->model_localisation_zone->getZonesByCountryId($this->request->get['country_id']),
  950. 'status' => $country_info['status']
  951. );
  952. }
  953. $this->response->setOutput(json_encode($json));
  954. }
  955. public function info() {
  956. $this->load->model('sale/order');
  957. if (isset($this->request->get['order_id'])) {
  958. $order_id = $this->request->get['order_id'];
  959. } else {
  960. $order_id = 0;
  961. }
  962. $order_info = $this->model_sale_order->getOrder($order_id);
  963. if ($order_info) {
  964. $this->data += $this->language->load('sale/order');
  965. $this->document->setTitle($this->language->get('heading_title'));
  966. $this->data['token'] = $this->session->data['token'];
  967. $url = '';
  968. if (isset($this->request->get['filter_order_id'])) {
  969. $url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
  970. }
  971. if (isset($this->request->get['filter_customer'])) {
  972. $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
  973. }
  974. if (isset($this->request->get['filter_order_status_id'])) {
  975. $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id'];
  976. }
  977. if (isset($this->request->get['filter_total'])) {
  978. $url .= '&filter_total=' . $this->request->get['filter_total'];
  979. }
  980. if (isset($this->request->get['filter_date_added'])) {
  981. $url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
  982. }
  983. if (isset($this->request->get['filter_date_modified'])) {
  984. $url .= '&filter_date_modified=' . $this->request->get['filter_date_modified'];
  985. }
  986. if (isset($this->request->get['sort'])) {
  987. $url .= '&sort=' . $this->request->get['sort'];
  988. }
  989. if (isset($this->request->get['order'])) {
  990. $url .= '&order=' . $this->request->get['order'];
  991. }
  992. if (isset($this->request->get['page'])) {
  993. $url .= '&page=' . $this->request->get['page'];
  994. }
  995. $this->data['breadcrumbs'] = array();
  996. $this->data['breadcrumbs'][] = array(
  997. 'text' => $this->language->get('text_home'),
  998. 'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL')
  999. );
  1000. $this->data['breadcrumbs'][] = array(
  1001. 'text' => $this->language->get('heading_title'),
  1002. 'href' => $this->url->link('sale/order', 'token=' . $this->session->data['token'] . $url, 'SSL')
  1003. );
  1004. $this->data['invoice'] = $this->url->link('sale/order/invoice', 'token=' . $this->session->data['token'] . '&order_id=' . (int)$this->request->get['order_id'], 'SSL');
  1005. $this->data['cancel'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . $url, 'SSL');
  1006. $this->data['order_id'] = $this->request->get['order_id'];
  1007. if ($order_info['invoice_no']) {
  1008. $this->data['invoice_no'] = $order_info['invoice_prefix'] . $order_info['invoice_no'];
  1009. } else {
  1010. $this->data['invoice_no'] = '';
  1011. }
  1012. $this->data['store_name'] = $order_info['store_name'];
  1013. $this->data['store_url'] = $order_info['store_url'];
  1014. $this->data['firstname'] = $order_info['firstname'];
  1015. $this->data['lastname'] = $order_info['lastname'];
  1016. if ($order_info['customer_id']) {
  1017. $this->data['customer'] = $this->url->link('sale/customer/update', 'token=' . $this->session->data['token'] . '&customer_id=' . $order_info['customer_id'], 'SSL');
  1018. } else {
  1019. $this->data['customer'] = '';
  1020. }
  1021. $this->load->model('sale/customer_group');
  1022. $customer_group_info = $this->model_sale_customer_group->getCustomerGroup($order_info['customer_group_id']);
  1023. if ($customer_group_info) {
  1024. $this->data['customer_group'] = $customer_group_info['name'];
  1025. } else {
  1026. $this->data['customer_group'] = '';
  1027. }
  1028. $this->data['email'] = $order_info['email'];
  1029. $this->data['telephone'] = $order_info['telephone'];
  1030. $this->data['fax'] = $order_info['fax'];
  1031. $this->data['comment'] = nl2br($order_info['comment']);
  1032. $this->data['shipping_method'] = $order_info['shipping_method'];
  1033. $this->data['payment_method'] = $order_info['payment_method'];
  1034. $this->data['total'] = $this->currency->format($order_info['total'], $order_info['currency_code'], $order_info['currency_value']);
  1035. if ($order_info['total'] < 0) {
  1036. $this->data['credit'] = $order_info['total'];
  1037. } else {
  1038. $this->data['credit'] = 0;
  1039. }
  1040. $this->load->model('sale/customer');
  1041. $this->data['credit_total'] = $this->model_sale_customer->getTotalTransactionsByOrderId($this->request->get['order_id']);
  1042. $this->data['reward'] = $order_info['reward'];
  1043. $this->data['reward_total'] = $this->model_sale_customer->getTotalCustomerRewardsByOrderId($this->request->get['order_id']);
  1044. $this->data['affiliate_firstname'] = $order_info['affiliate_firstname'];
  1045. $this->data['affiliate_lastname'] = $order_info['affiliate_lastname'];
  1046. if ($order_info['affiliate_id']) {
  1047. $this->data['affiliate'] = $this->url->link('sale/affiliate/update', 'token=' . $this->session->data['token'] . '&affiliate_id=' . $order_info['affiliate_id'], 'SSL');
  1048. } else {
  1049. $this->data['affiliate'] = '';
  1050. }
  1051. $this->data['commission'] = $this->currency->format($order_info['commission'], $order_info['currency_code'], $order_info['currency_value']);
  1052. $this->load->model('sale/affiliate');
  1053. $this->data['commission_total'] = $this->model_sale_affiliate->getTotalTransactionsByOrderId($this->request->get['order_id']);
  1054. $this->load->model('localisation/order_status');
  1055. $order_status_info = $this->model_localisation_order_status->getOrderStatus($order_info['order_status_id']);
  1056. if ($order_status_info) {
  1057. $this->data['order_status'] = $order_status_info['name'];
  1058. } else {
  1059. $this->data['order_status'] = '';
  1060. }
  1061. $this->data['ip'] = $order_info['ip'];
  1062. $this->data['forwarded_ip'] = $order_info['forwarded_ip'];
  1063. $this->data['user_agent'] = $order_info['user_agent'];
  1064. $this->data['accept_language'] = $order_info['accept_language'];
  1065. $this->data['date_added'] = date($this->language->get('date_format_short'), strtotime($order_info['date_added']));
  1066. $this->data['date_modified'] = date($this->language->get('date_format_short'), strtotime($order_info['date_modified']));
  1067. $this->data['payment_firstname'] = $order_info['payment_firstname'];
  1068. $this->data['payment_lastname'] = $order_info['payment_lastname'];
  1069. $this->data['payment_company'] = $order_info['payment_company'];
  1070. $this->data['payment_address_1'] = $order_info['payment_address_1'];
  1071. $this->data['payment_address_2'] = $order_info['payment_address_2'];
  1072. $this->data['payment_city'] = $order_info['payment_city'];
  1073. $this->data['payment_postcode'] = $order_info['payment_postcode'];
  1074. $this->data['payment_zone'] = $order_info['payment_zone'];
  1075. $this->data['payment_zone_code'] = $order_info['payment_zone_code'];
  1076. $this->data['payment_country'] = $order_info['payment_country'];
  1077. $this->data['shipping_firstname'] = $order_info['shipping_firstname'];
  1078. $this->data['shipping_lastname'] = $order_info['shipping_lastname'];
  1079. $this->data['shipping_company'] = $order_info['shipping_company'];
  1080. $this->data['shipping_address_1'] = $order_info['shipping_address_1'];
  1081. $this->data['shipping_address_2'] = $order_info['shipping_address_2'];
  1082. $this->data['shipping_city'] = $order_info['shipping_city'];
  1083. $this->data['shipping_postcode'] = $order_info['shipping_postcode'];
  1084. $this->data['shipping_zone'] = $order_info['shipping_zone'];
  1085. $this->data['shipping_zone_code'] = $order_info['shipping_zone_code'];
  1086. $this->data['shipping_country'] = $order_info['shipping_country'];
  1087. $this->data['products'] = array();
  1088. $products = $this->model_sale_order->getOrderProducts($this->request->get['order_id']);
  1089. foreach ($products as $product) {
  1090. $option_data = array();
  1091. $options = $this->model_sale_order->getOrderOptions($this->request->get['order_id'], $product['order_product_id']);
  1092. foreach ($options as $option) {
  1093. if ($option['type'] != 'file') {
  1094. $option_data[] = array(
  1095. 'name' => $option['name'],
  1096. 'value' => $option['value'],
  1097. 'type' => $option['type']
  1098. );
  1099. } else {
  1100. $option_data[] = array(
  1101. 'name' => $option['name'],
  1102. 'value' => utf8_substr($option['value'], 0, utf8_strrpos($option['value'], '.')),
  1103. 'type' => $option['type'],
  1104. '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')
  1105. );
  1106. }
  1107. }
  1108. $this->data['products'][] = array(
  1109. 'order_product_id' => $product['order_product_id'],
  1110. 'product_id' => $product['product_id'],
  1111. 'name' => $product['name'],
  1112. 'model' => $product['model'],
  1113. 'option' => $option_data,
  1114. 'quantity' => $product['quantity'],
  1115. 'price' => $this->currency->format($product['price'] + ($this->config->get('config_tax') ? $product['tax'] : 0), $order_info['currency_code'], $order_info['currency_value']),
  1116. 'total' => $this->currency->format($product['total'] + ($this->config->get('config_tax') ? ($product['tax'] * $product['quantity']) : 0), $order_info['currency_code'], $order_info['currency_value']),
  1117. 'href' => $this->url->link('catalog/product/update', 'token=' . $this->session->data['token'] . '&product_id=' . $product['product_id'], 'SSL')
  1118. );
  1119. }
  1120. $this->data['vouchers'] = array();
  1121. $vouchers = $this->model_sale_order->getOrderVouchers($this->request->get['order_id']);
  1122. foreach ($vouchers as $voucher) {
  1123. $this->data['vouchers'][] = array(
  1124. 'description' => $voucher['description'],
  1125. 'amount' => $this->currency->format($voucher['amount'], $order_info['currency_code'], $order_info['currency_value']),
  1126. 'href' => $this->url->link('sale/voucher/update', 'token=' . $this->session->data['token'] . '&voucher_id=' . $voucher['voucher_id'], 'SSL')
  1127. );
  1128. }
  1129. $this->data['totals'] = $this->model_sale_order->getOrderTotals($this->request->get['order_id']);
  1130. $this->data['downloads'] = array();
  1131. foreach ($products as $product) {
  1132. $results = $this->model_sale_order->getOrderDownloads($this->request->get['order_id'], $product['order_product_id']);
  1133. foreach ($results as $result) {
  1134. $this->data['downloads'][] = array(
  1135. 'name' => $result['name'],
  1136. 'filename' => $result['mask'],
  1137. 'remaining' => $result['remaining']
  1138. );
  1139. }
  1140. }
  1141. $this->data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
  1142. $this->data['order_status_id'] = $order_info['order_status_id'];
  1143. // Fraud
  1144. $this->load->model('sale/fraud');
  1145. $fraud_info = $this->model_sale_fraud->getFraud($order_info['order_id']);
  1146. if ($fraud_info) {
  1147. $this->data['country_match'] = $fraud_info['country_match'];
  1148. if ($fraud_info['country_code']) {
  1149. $this->data['country_code'] = $fraud_info['country_code'];
  1150. } else {
  1151. $this->data['country_code'] = '';
  1152. }
  1153. $this->data['high_risk_country'] = $fraud_info['high_risk_country'];
  1154. $this->data['distance'] = $fraud_info['distance'];
  1155. if ($fraud_info['ip_region']) {
  1156. $this->data['ip_region'] = $fraud_info['ip_region'];
  1157. } else {
  1158. $this->data['ip_region'] = '';
  1159. }
  1160. if ($fraud_info['ip_city']) {
  1161. $this->data['ip_city'] = $fraud_info['ip_city'];
  1162. } else {
  1163. $this->data['ip_city'] = '';
  1164. }
  1165. $this->data['ip_latitude'] = $fraud_info['ip_latitude'];
  1166. $this->data['ip_longitude'] = $fraud_info['ip_longitude'];
  1167. if ($fraud_info['ip_isp']) {
  1168. $this->data['ip_isp'] = $fraud_info['ip_isp'];
  1169. } else {
  1170. $this->data['ip_isp'] = '';
  1171. }
  1172. if ($fraud_info['ip_org']) {
  1173. $this->data['ip_org'] = $fraud_info['ip_org'];
  1174. } else {
  1175. $this->data['ip_org'] = '';
  1176. }
  1177. $this->data['ip_asnum'] = $fraud_info['ip_asnum'];
  1178. if ($fraud_info['ip_user_type']) {
  1179. $this->data['ip_user_type'] = $fraud_info['ip_user_type'];
  1180. } else {
  1181. $this->data['ip_user_type'] = '';
  1182. }
  1183. if ($fraud_info['ip_country_confidence']) {
  1184. $this->data['ip_country_confidence'] = $fraud_info['ip_country_confidence'];
  1185. } else {
  1186. $this->data['ip_country_confidence'] = '';
  1187. }
  1188. if ($fraud_info['ip_region_confidence']) {
  1189. $this->data['ip_region_confidence'] = $fraud_info['ip_region_confidence'];
  1190. } else {
  1191. $this->data['ip_region_confidence'] = '';
  1192. }
  1193. if ($fraud_info['ip_city_confidence']) {
  1194. $this->data['ip_city_confidence'] = $fraud_info['ip_city_confidence'];
  1195. } else {
  1196. $this->data['ip_city_confidence'] = '';
  1197. }
  1198. if ($fraud_info['ip_postal_confidence']) {
  1199. $this->data['ip_postal_confidence'] = $fraud_info['ip_postal_confidence'];
  1200. } else {
  1201. $this->data['ip_postal_confidence'] = '';
  1202. }
  1203. if ($fraud_info['ip_postal_code']) {
  1204. $this->data['ip_postal_code'] = $fraud_info['ip_postal_code'];
  1205. } else {
  1206. $this->data['ip_postal_code'] = '';
  1207. }
  1208. $this->data['ip_accuracy_radius'] = $fraud_info['ip_accuracy_radius'];
  1209. if ($fraud_info['ip_net_speed_cell']) {
  1210. $this->data['ip_net_speed_cell'] = $fraud_info['ip_net_speed_cell'];
  1211. } else {
  1212. $this->data['ip_net_speed_cell'] = '';
  1213. }
  1214. $this->data['ip_metro_code'] = $fraud_info['ip_metro_code'];
  1215. $this->data['ip_area_code'] = $fraud_info['ip_area_code'];
  1216. if ($fraud_info['ip_time_zone']) {
  1217. $this->data['ip_time_zone'] = $fraud_info['ip_time_zone'];
  1218. } else {
  1219. $this->data['ip_time_zone'] = '';
  1220. }
  1221. if ($fraud_info['ip_region_name']) {
  1222. $this->data['ip_region_name'] = $fraud_info['ip_region_name'];
  1223. } else {
  1224. $this->data['ip_region_name'] = '';
  1225. }
  1226. if ($fraud_info['ip_domain']) {
  1227. $this->data['ip_domain'] = $fraud_info['ip_domain'];
  1228. } else {
  1229. $this->data['ip_domain'] = '';
  1230. }
  1231. if ($fraud_info['ip_country_name']) {
  1232. $this->data['ip_country_name'] = $fraud_info['ip_country_name'];
  1233. } else {
  1234. $this->data['ip_country_name'] = '';
  1235. }
  1236. if ($fraud_info['ip_continent_code']) {
  1237. $this->data['ip_continent_code'] = $fraud_info['ip_continent_code'];
  1238. } else {
  1239. $this->data['ip_continent_code'] = '';
  1240. }
  1241. if ($fraud_info['ip_corporate_proxy']) {
  1242. $this->data['ip_corporate_proxy'] = $fraud_info['ip_corporate_proxy'];
  1243. } else {
  1244. $this->data['ip_corporate_proxy'] = '';
  1245. }
  1246. $this->data['anonymous_proxy'] = $fraud_info['anonymous_proxy'];
  1247. $this->data['proxy_score'] = $fraud_info['proxy_score'];
  1248. if ($fraud_info['is_trans_proxy']) {
  1249. $this->data['is_trans_proxy'] = $fraud_info['is_trans_proxy'];
  1250. } else {
  1251. $this->data['is_trans_proxy'] = '';
  1252. }
  1253. $this->data['free_mail'] = $fraud_info['free_mail'];
  1254. $this->data['carder_email'] = $fraud_info['carder_email'];
  1255. if ($fraud_info['high_risk_username']) {
  1256. $this->data['high_risk_username'] = $fraud_info['high_risk_username'];
  1257. } else {
  1258. $this->data['high_risk_username'] = '';
  1259. }
  1260. if ($fraud_info['high_risk_password']) {
  1261. $this->data['high_risk_password'] = $fraud_info['high_risk_password'];
  1262. } else {
  1263. $this->data['high_risk_password'] = '';
  1264. }
  1265. $this->data['bin_match'] = $fraud_info['bin_match'];
  1266. if ($fraud_info['bin_country']) {
  1267. $this->data['bin_country'] = $fraud_info['bin_country'];
  1268. } else {
  1269. $this->data['bin_country'] = '';
  1270. }
  1271. $this->data['bin_name_match'] = $fraud_info['bin_name_match'];
  1272. if ($fraud_info['bin_name']) {
  1273. $this->data['bin_name'] = $fraud_info['bin_name'];
  1274. } else {
  1275. $this->data['bin_name'] = '';
  1276. }
  1277. $this->data['bin_phone_match'] = $fraud_info['bin_phone_match'];
  1278. if ($fraud_info['bin_phone']) {
  1279. $this->data['bin_phone'] = $fraud_info['bin_phone'];
  1280. } else {
  1281. $this->data['bin_phone'] = '';
  1282. }
  1283. if ($fraud_info['customer_phone_in_billing_location']) {
  1284. $this->data['customer_phone_in_billing_location'] = $fraud_info['customer_phone_in_billing_location'];
  1285. } else {
  1286. $this->data['customer_phone_in_billing_location'] = '';
  1287. }
  1288. $this->data['ship_forward'] = $fraud_info['ship_forward'];
  1289. if ($fraud_info['city_postal_match']) {
  1290. $this->data['city_postal_match'] = $fraud_info['city_postal_match'];
  1291. } else {
  1292. $this->data['city_postal_match'] = '';
  1293. }
  1294. if ($fraud_info['ship_city_postal_match']) {
  1295. $this->data['ship_city_postal_match'] = $fraud_info['ship_city_postal_match'];
  1296. } else {
  1297. $this->data['ship_city_postal_match'] = '';
  1298. }
  1299. $this->data['score'] = $fraud_info['score'];
  1300. $this->data['explanation'] = $fraud_info['explanation'];
  1301. $this->data['risk_score'] = $fraud_info['risk_score'];
  1302. $this->data['queries_remaining'] = $fraud_info['queries_remaining'];
  1303. $this->data['maxmind_id'] = $fraud_info['maxmind_id'];
  1304. $this->data['error'] = $fraud_info['error'];
  1305. } else {
  1306. $this->data['maxmind_id'] = '';
  1307. }
  1308. $this->template = 'sale/order_info.tpl';
  1309. $this->children = array(
  1310. 'common/header',
  1311. 'common/footer'
  1312. );
  1313. $this->response->setOutput($this->render());
  1314. } else {
  1315. $this->data += $this->language->load('error/not_found');
  1316. $this->document->setTitle($this->language->get('heading_title'));
  1317. $this->data['breadcrumbs'] = array();
  1318. $this->data['breadcrumbs'][] = array(
  1319. 'text' => $this->language->get('text_home'),
  1320. 'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL')
  1321. );
  1322. $this->data['breadcrumbs'][] = array(
  1323. 'text' => $this->language->get('heading_title'),
  1324. 'href' => $this->url->link('error/not_found', 'token=' . $this->session->data['token'], 'SSL')
  1325. );
  1326. $this->template = 'error/not_found.tpl';
  1327. $this->children = array(
  1328. 'common/header',
  1329. 'common/footer'
  1330. );
  1331. $this->response->setOutput($this->render());
  1332. }
  1333. }
  1334. public function createInvoiceNo() {
  1335. $this->data += $this->language->load('sale/order');
  1336. $json = array();
  1337. if (!$this->user->hasPermission('modify', 'sale/order')) {
  1338. $json['error'] = $this->language->get('error_permission');
  1339. } elseif (isset($this->request->get['order_id'])) {
  1340. $this->load->model('sale/order');
  1341. $invoice_no = $this->model_sale_order->createInvoiceNo($this->request->get['order_id']);
  1342. if ($invoice_no) {
  1343. $json['invoice_no'] = $invoice_no;
  1344. } else {
  1345. $json['error'] = $this->language->get('error_action');
  1346. }
  1347. }
  1348. $this->response->setOutput(json_encode($json));
  1349. }
  1350. public function addCredit() {
  1351. $this->data += $this->language->load('sale/order');
  1352. $json = array();
  1353. if (!$this->user->hasPermission('modify', 'sale/order')) {
  1354. $json['error'] = $this->language->get('error_permission');
  1355. } elseif (isset($this->request->get['order_id'])) {
  1356. $this->load->model('sale/order');
  1357. $order_info = $this->model_sale_order->getOrder($this->request->get['order_id']);
  1358. if ($order_info && $order_info['customer_id']) {
  1359. $this->load->model('sale/customer');
  1360. $credit_total = $this->model_sale_customer->getTotalTransactionsByOrderId($this->request->get['order_id']);
  1361. if (!$credit_total) {
  1362. $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']);
  1363. $json['success'] = $this->language->get('text_credit_added');
  1364. } else {
  1365. $json['error'] = $this->language->get('error_action');
  1366. }
  1367. }
  1368. }
  1369. $this->response->setOutput(json_encode($json));
  1370. }
  1371. public function removeCredit() {
  1372. $this->data += $this->language->load('sale/order');
  1373. $json = array();
  1374. if (!$this->user->hasPermission('modify', 'sale/order')) {
  1375. $json['error'] = $this->language->get('error_permission');
  1376. } elseif (isset($this->request->get['order_id'])) {
  1377. $this->load->model('sale/order');
  1378. $order_info = $this->model_sale_order->getOrder($this->request->get['order_id']);
  1379. if ($order_info && $order_info['customer_id']) {
  1380. $this->load->model('sale/customer');
  1381. $this->model_sale_customer->deleteTransaction($this->request->get['order_id']);
  1382. $json['success'] = $this->language->get('text_credit_removed');
  1383. } else {
  1384. $json['error'] = $this->language->get('error_action');
  1385. }
  1386. }
  1387. $this->response->setOutput(json_encode($json));
  1388. }
  1389. public function addReward() {
  1390. $this->data += $this->language->load('sale/order');
  1391. $json = array();
  1392. if (!$this->user->hasPermission('modify', 'sale/order')) {
  1393. $json['error'] = $this->language->get('error_permission');
  1394. } elseif (isset($this->request->get['order_id'])) {
  1395. $this->load->model('sale/order');
  1396. $order_info = $this->model_sale_order->getOrder($this->request->get['order_id']);
  1397. if ($order_info && $order_info['customer_id'] && ($order_info['reward'] > 0)) {
  1398. $this->load->model('sale/customer');
  1399. $reward_total = $this->model_sale_customer->getTotalCustomerRewardsByOrderId($this->request->get['order_id']);
  1400. if (!$reward_total) {
  1401. $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']);
  1402. $json['success'] = $this->language->get('text_reward_added');
  1403. } else {
  1404. $json['error'] = $this->language->get('error_action');
  1405. }
  1406. } else {
  1407. $json['error'] = $this->language->get('error_action');
  1408. }
  1409. }
  1410. $this->response->setOutput(json_encode($json));
  1411. }
  1412. public function removeReward() {
  1413. $this->data += $this->language->load('sale/order');
  1414. $json = array();
  1415. if (!$this->user->hasPermission('modify', 'sale/order')) {
  1416. $json['error'] = $this->language->get('error_permission');
  1417. } elseif (isset($this->request->get['order_id'])) {
  1418. $this->load->model('sale/order');
  1419. $order_info = $this->model_sale_order->getOrder($this->request->get['order_id']);
  1420. if ($order_info && $order_info['customer_id']) {
  1421. $this->load->model('sale/customer');
  1422. $this->model_sale_customer->deleteReward($this->request->get['order_id']);
  1423. $json['success'] = $this->language->get('text_reward_removed');
  1424. } else {
  1425. $json['error'] = $this->language->get('error_action');
  1426. }
  1427. }
  1428. $this->response->setOutput(json_encode($json));
  1429. }
  1430. public function addCommission() {
  1431. $this->data += $this->language->load('sale/order');
  1432. $json = array();
  1433. if (!$this->user->hasPermission('modify', 'sale/order')) {
  1434. $json['error'] = $this->language->get('error_permission');
  1435. } elseif (isset($this->request->get['order_id'])) {
  1436. $this->load->model('sale/order');
  1437. $order_info = $this->model_sale_order->getOrder($this->request->get['order_id']);
  1438. if ($order_info && $order_info['affiliate_id']) {
  1439. $this->load->model('sale/affiliate');
  1440. $affiliate_total = $this->model_sale_affiliate->getTotalTransactionsByOrderId($this->request->get['order_id']);
  1441. if (!$affiliate_total) {
  1442. $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']);
  1443. $json['success'] = $this->language->get('text_commission_added');
  1444. } else {
  1445. $json['error'] = $this->language->get('error_action');
  1446. }
  1447. } else {
  1448. $json['error'] = $this->language->get('error_action');
  1449. }
  1450. }
  1451. $this->response->setOutput(json_encode($json));
  1452. }
  1453. public function removeCommission() {
  1454. $this->data += $this->language->load('sale/order');
  1455. $json = array();
  1456. if (!$this->user->hasPermission('modify', 'sale/order')) {
  1457. $json['error'] = $this->language->get('error_permission');
  1458. } elseif (isset($this->request->get['order_id'])) {
  1459. $this->load->model('sale/order');
  1460. $order_info = $this->model_sale_order->getOrder($this->request->get['order_id']);
  1461. if ($order_info && $order_info['affiliate_id']) {
  1462. $this->load->model('sale/affiliate');
  1463. $this->model_sale_affiliate->deleteTransaction($this->request->get['order_id']);
  1464. $json['success'] = $this->language->get('text_commission_removed');
  1465. } else {
  1466. $json['error'] = $this->language->get('error_action');
  1467. }
  1468. }
  1469. $this->response->setOutput(json_encode($json));
  1470. }
  1471. public function history() {
  1472. $this->data += $this->language->load('sale/order');
  1473. $this->data['error'] = '';
  1474. $this->data['success'] = '';
  1475. $this->load->model('sale/order');
  1476. if ($this->request->server['REQUEST_METHOD'] == 'POST') {
  1477. if (!$this->user->hasPermission('modify', 'sale/order')) {
  1478. $this->data['error'] = $this->language->get('error_permission');
  1479. }
  1480. if (!$this->data['error']) {
  1481. $this->model_sale_order->addOrderHistory($this->request->get['order_id'], $this->request->post);
  1482. $this->data['success'] = $this->language->get('text_success');
  1483. }
  1484. }
  1485. if (isset($this->request->get['page'])) {
  1486. $page = $this->request->get['page'];
  1487. } else {
  1488. $page = 1;
  1489. }
  1490. $this->data['histories'] = array();
  1491. $results = $this->model_sale_order->getOrderHistories($this->request->get['order_id'], ($page - 1) * 10, 10);
  1492. foreach ($results as $result) {
  1493. $this->data['histories'][] = array(
  1494. 'notify' => $result['notify'] ? $this->language->get('text_yes') : $this->language->get('text_no'),
  1495. 'status' => $result['status'],
  1496. 'comment' => nl2br($result['comment']),
  1497. 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added']))
  1498. );
  1499. }
  1500. $history_total = $this->model_sale_order->getTotalOrderHistories($this->request->get['order_id']);
  1501. $pagination = new Pagination();
  1502. $pagination->total = $history_total;
  1503. $pagination->page = $page;
  1504. $pagination->limit = 10;
  1505. $pagination->text = $this->language->get('text_pagination');
  1506. $pagination->url = $this->url->link('sale/order/history', 'token=' . $this->session->data['token'] . '&order_id=' . $this->request->get['order_id'] . '&page={page}', 'SSL');
  1507. $this->data['pagination'] = $pagination->render();
  1508. $this->template = 'sale/order_history.tpl';
  1509. $this->response->setOutput($this->render());
  1510. }
  1511. public function download() {
  1512. $this->load->model('sale/order');
  1513. if (isset($this->request->get['order_option_id'])) {
  1514. $order_option_id = $this->request->get['order_option_id'];
  1515. } else {
  1516. $order_option_id = 0;
  1517. }
  1518. $option_info = $this->model_sale_order->getOrderOption($this->request->get['order_id'], $order_option_id);
  1519. if ($option_info && $option_info['type'] == 'file') {
  1520. $file = DIR_DOWNLOAD . $option_info['value'];
  1521. $mask = basename(utf8_substr($option_info['value'], 0, utf8_strrpos($option_info['value'], '.')));
  1522. if (!headers_sent()) {
  1523. if (file_exists($file)) {
  1524. header('Content-Type: application/octet-stream');
  1525. header('Content-Description: File Transfer');
  1526. header('Content-Disposition: attachment; filename="' . ($mask ? $mask : basename($file)) . '"');
  1527. header('Content-Transfer-Encoding: binary');
  1528. header('Expires: 0');
  1529. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  1530. header('Pragma: public');
  1531. header('Content-Length: ' . filesize($file));
  1532. readfile($file, 'rb');
  1533. exit;
  1534. } else {
  1535. exit('Error: Could not find file ' . $file . '!');
  1536. }
  1537. } else {
  1538. exit('Error: Headers already sent out!');
  1539. }
  1540. } else {
  1541. $this->data += $this->language->load('error/not_found');
  1542. $this->document->setTitle($this->language->get('heading_title'));
  1543. $this->data['breadcrumbs'] = array();
  1544. $this->data['breadcrumbs'][] = array(
  1545. 'text' => $this->language->get('text_home'),
  1546. 'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL')
  1547. );
  1548. $this->data['breadcrumbs'][] = array(
  1549. 'text' => $this->language->get('heading_title'),
  1550. 'href' => $this->url->link('error/not_found', 'token=' . $this->session->data['token'], 'SSL')
  1551. );
  1552. $this->template = 'error/not_found.tpl';
  1553. $this->children = array(
  1554. 'common/header',
  1555. 'common/footer'
  1556. );
  1557. $this->response->setOutput($this->render());
  1558. }
  1559. }
  1560. public function upload() {
  1561. $this->data += $this->language->load('sale/order');
  1562. $json = array();
  1563. if ($this->request->server['REQUEST_METHOD'] == 'POST') {
  1564. if (!empty($this->request->files['file']['name'])) {
  1565. $filename = html_entity_decode($this->request->files['file']['name'], ENT_QUOTES, 'UTF-8');
  1566. if ((utf8_strlen($filename) < 3) || (utf8_strlen($filename) > 128)) {
  1567. $json['error'] = $this->language->get('error_filename');
  1568. }
  1569. // Allowed file extension types
  1570. $allowed = array();
  1571. $filetypes = explode("\n", $this->config->get('config_file_extension_allowed'));
  1572. foreach ($filetypes as $filetype) {
  1573. $allowed[] = trim($filetype);
  1574. }
  1575. if (!in_array(substr(strrchr($filename, '.'), 1), $allowed)) {
  1576. $json['error'] = $this->language->get('error_filetype');
  1577. }
  1578. // Allowed file mime types
  1579. $allowed = array();
  1580. $filetypes = explode("\n", $this->config->get('config_file_mime_allowed'));
  1581. foreach ($filetypes as $filetype) {
  1582. $allowed[] = trim($filetype);
  1583. }
  1584. if (!in_array($this->request->files['file']['type'], $allowed)) {
  1585. $json['error'] = $this->language->get('error_filetype');
  1586. }
  1587. if ($this->request->files['file']['error'] != UPLOAD_ERR_OK) {
  1588. $json['error'] = $this->language->get('error_upload_' . $this->request->files['file']['error']);
  1589. }
  1590. } else {
  1591. $json['error'] = $this->language->get('error_upload');
  1592. }
  1593. if (!isset($json['error'])) {
  1594. if (is_uploaded_file($this->request->files['file']['tmp_name']) && file_exists($this->request->files['file']['tmp_name'])) {
  1595. $file = basename($filename) . '.' . md5(mt_rand());
  1596. $json['file'] = $file;
  1597. move_uploaded_file($this->request->files['file']['tmp_name'], DIR_DOWNLOAD . $file);
  1598. }
  1599. $json['success'] = $this->language->get('text_upload');
  1600. }
  1601. }
  1602. $this->response->setOutput(json_encode($json));
  1603. }
  1604. public function invoice() {
  1605. $this->data += $this->language->load('sale/order');
  1606. $this->data['title'] = $this->language->get('heading_title');
  1607. if (isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == 'on') || ($this->request->server['HTTPS'] == '1'))) {
  1608. $this->data['base'] = HTTPS_SERVER;
  1609. } else {
  1610. $this->data['base'] = HTTP_SERVER;
  1611. }
  1612. $this->data['language'] = $this->language->get('code');
  1613. $this->load->model('sale/order');
  1614. $this->load->model('setting/setting');
  1615. $this->data['orders'] = array();
  1616. $orders = array();
  1617. if (isset($this->request->post['selected'])) {
  1618. $orders = $this->request->post['selected'];
  1619. } elseif (isset($this->request->get['order_id'])) {
  1620. $orders[] = $this->request->get['order_id'];
  1621. }
  1622. foreach ($orders as $order_id) {
  1623. $order_info = $this->model_sale_order->getOrder($order_id);
  1624. if ($order_info) {
  1625. $store_info = $this->model_setting_setting->getSetting('config', $order_info['store_id']);
  1626. if ($store_info) {
  1627. $store_address = $store_info['config_address'];
  1628. $store_email = $store_info['config_email'];
  1629. $store_telephone = $store_info['config_telephone'];
  1630. $store_fax = $store_info['config_fax'];
  1631. } else {
  1632. $store_address = $this->config->get('config_address');
  1633. $store_email = $this->config->get('config_email');
  1634. $store_telephone = $this->config->get('config_telephone');
  1635. $store_fax = $this->config->get('config_fax');
  1636. }
  1637. if ($order_info['invoice_no']) {
  1638. $invoice_no = $order_info['invoice_prefix'] . $order_info['invoice_no'];
  1639. } else {
  1640. $invoice_no = '';
  1641. }
  1642. if ($order_info['shipping_address_format']) {
  1643. $format = $order_info['shipping_address_format'];
  1644. } else {
  1645. $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
  1646. }
  1647. $find = array(
  1648. '{firstname}',
  1649. '{lastname}',
  1650. '{company}',
  1651. '{address_1}',
  1652. '{address_2}',
  1653. '{city}',
  1654. '{postcode}',
  1655. '{zone}',
  1656. '{zone_code}',
  1657. '{country}'
  1658. );
  1659. $replace = array(
  1660. 'firstname' => $order_info['shipping_firstname'],
  1661. 'lastname' => $order_info['shipping_lastname'],
  1662. 'company' => $order_info['shipping_company'],
  1663. 'address_1' => $order_info['shipping_address_1'],
  1664. 'address_2' => $order_info['shipping_address_2'],
  1665. 'city' => $order_info['shipping_city'],
  1666. 'postcode' => $order_info['shipping_postcode'],
  1667. 'zone' => $order_info['shipping_zone'],
  1668. 'zone_code' => $order_info['shipping_zone_code'],
  1669. 'country' => $order_info['shipping_country']
  1670. );
  1671. $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))));
  1672. if ($order_info['payment_address_format']) {
  1673. $format = $order_info['payment_address_format'];
  1674. } else {
  1675. $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
  1676. }
  1677. $find = array(
  1678. '{firstname}',
  1679. '{lastname}',
  1680. '{company}',
  1681. '{address_1}',
  1682. '{address_2}',
  1683. '{city}',
  1684. '{postcode}',
  1685. '{zone}',
  1686. '{zone_code}',
  1687. '{country}'
  1688. );
  1689. $replace = array(
  1690. 'firstname' => $order_info['payment_firstname'],
  1691. 'lastname' => $order_info['payment_lastname'],
  1692. 'company' => $order_info['payment_company'],
  1693. 'address_1' => $order_info['payment_address_1'],
  1694. 'address_2' => $order_info['payment_address_2'],
  1695. 'city' => $order_info['payment_city'],
  1696. 'postcode' => $order_info['payment_postcode'],
  1697. 'zone' => $order_info['payment_zone'],
  1698. 'zone_code' => $order_info['payment_zone_code'],
  1699. 'country' => $order_info['payment_country']
  1700. );
  1701. $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))));
  1702. $product_data = array();
  1703. $products = $this->model_sale_order->getOrderProducts($order_id);
  1704. foreach ($products as $product) {
  1705. $option_data = array();
  1706. $options = $this->model_sale_order->getOrderOptions($order_id, $product['order_product_id']);
  1707. foreach ($options as $option) {
  1708. if ($option['type'] != 'file') {
  1709. $value = $option['value'];
  1710. } else {
  1711. $value = utf8_substr($option['value'], 0, utf8_strrpos($option['value'], '.'));
  1712. }
  1713. $option_data[] = array(
  1714. 'name' => $option['name'],
  1715. 'value' => $value
  1716. );
  1717. }
  1718. $product_data[] = array(
  1719. 'name' => $product['name'],
  1720. 'model' => $product['model'],
  1721. 'option' => $option_data,
  1722. 'quantity' => $product['quantity'],
  1723. 'price' => $this->currency->format($product['price'] + ($this->config->get('config_tax') ? $product['tax'] : 0), $order_info['currency_code'], $order_info['currency_value']),
  1724. 'total' => $this->currency->format($product['total'] + ($this->config->get('config_tax') ? ($product['tax'] * $product['quantity']) : 0), $order_info['currency_code'], $order_info['currency_value'])
  1725. );
  1726. }
  1727. $voucher_data = array();
  1728. $vouchers = $this->model_sale_order->getOrderVouchers($order_id);
  1729. foreach ($vouchers as $voucher) {
  1730. $voucher_data[] = array(
  1731. 'description' => $voucher['description'],
  1732. 'amount' => $this->currency->format($voucher['amount'], $order_info['currency_code'], $order_info['currency_value'])
  1733. );
  1734. }
  1735. $total_data = $this->model_sale_order->getOrderTotals($order_id);
  1736. $this->data['orders'][] = array(
  1737. 'order_id' => $order_id,
  1738. 'invoice_no' => $invoice_no,
  1739. 'date_added' => date($this->language->get('date_format_short'), strtotime($order_info['date_added'])),
  1740. 'store_name' => $order_info['store_name'],
  1741. 'store_url' => rtrim($order_info['store_url'], '/'),
  1742. 'store_address' => nl2br($store_address),
  1743. 'store_email' => $store_email,
  1744. 'store_telephone' => $store_telephone,
  1745. 'store_fax' => $store_fax,
  1746. 'email' => $order_info['email'],
  1747. 'telephone' => $order_info['telephone'],
  1748. 'shipping_address' => $shipping_address,
  1749. 'shipping_method' => $order_info['shipping_method'],
  1750. 'payment_address' => $payment_address,
  1751. 'payment_method' => $order_info['payment_method'],
  1752. 'product' => $product_data,
  1753. 'voucher' => $voucher_data,
  1754. 'total' => $total_data,
  1755. 'comment' => nl2br($order_info['comment'])
  1756. );
  1757. }
  1758. }
  1759. $this->template = 'sale/order_invoice.tpl';
  1760. $this->response->setOutput($this->render());
  1761. }
  1762. }
  1763. ?>