PageRenderTime 56ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/controller/sale/order.php

https://bitbucket.org/jjasko/opencart_serbian
PHP | 2086 lines | 1627 code | 452 blank | 7 comment | 373 complexity | 1c1ee3b00306f75f26ad0d971d8e4b54 MD5 | raw file
  1. <?php
  2. class ControllerSaleOrder extends Controller {
  3. private $error = array();
  4. public function index() {
  5. $this->load->language('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->load->language('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=' . $this->request->get['filter_customer'];
  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/return', 'token=' . $this->session->data['token'] . $url, 'SSL'));
  46. }
  47. $this->getForm();
  48. }
  49. public function update() {
  50. $this->load->language('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=' . $this->request->get['filter_customer'];
  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/return', 'token=' . $this->session->data['token'] . $url, 'SSL'));
  85. }
  86. $this->getForm();
  87. }
  88. public function delete() {
  89. $this->load->language('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=' . $this->request->get['filter_customer'];
  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. private 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=' . $this->request->get['filter_customer'];
  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. 'separator' => false
  208. );
  209. $this->data['breadcrumbs'][] = array(
  210. 'text' => $this->language->get('heading_title'),
  211. 'href' => $this->url->link('sale/order', 'token=' . $this->session->data['token'] . $url, 'SSL'),
  212. 'separator' => ' :: '
  213. );
  214. $this->data['invoice'] = $this->url->link('sale/order/invoice', 'token=' . $this->session->data['token'], 'SSL');
  215. $this->data['delete'] = $this->url->link('sale/order/delete', 'token=' . $this->session->data['token'] . $url, 'SSL');
  216. $this->data['orders'] = array();
  217. $data = array(
  218. 'filter_order_id' => $filter_order_id,
  219. 'filter_customer' => $filter_customer,
  220. 'filter_order_status_id' => $filter_order_status_id,
  221. 'filter_total' => $filter_total,
  222. 'filter_date_added' => $filter_date_added,
  223. 'filter_date_modified' => $filter_date_modified,
  224. 'sort' => $sort,
  225. 'order' => $order,
  226. 'start' => ($page - 1) * $this->config->get('config_admin_limit'),
  227. 'limit' => $this->config->get('config_admin_limit')
  228. );
  229. $order_total = $this->model_sale_order->getTotalOrders($data);
  230. $results = $this->model_sale_order->getOrders($data);
  231. foreach ($results as $result) {
  232. $action = array();
  233. $action[] = array(
  234. 'text' => $this->language->get('text_view'),
  235. 'href' => $this->url->link('sale/order/info', 'token=' . $this->session->data['token'] . '&order_id=' . $result['order_id'] . $url, 'SSL')
  236. );
  237. /*
  238. Commented out until I can finish the order editing system.
  239. $action[] = array(
  240. 'text' => $this->language->get('text_edit'),
  241. 'href' => $this->url->link('sale/order/update', 'token=' . $this->session->data['token'] . '&order_id=' . $result['order_id'] . $url, 'SSL')
  242. );
  243. */
  244. $this->data['orders'][] = array(
  245. 'order_id' => $result['order_id'],
  246. 'customer' => $result['customer'],
  247. 'status' => $result['status'],
  248. 'total' => $this->currency->format($result['total'], $result['currency_code'], $result['currency_value']),
  249. 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
  250. 'date_modified' => date($this->language->get('date_format_short'), strtotime($result['date_modified'])),
  251. 'selected' => isset($this->request->post['selected']) && in_array($result['order_id'], $this->request->post['selected']),
  252. 'action' => $action
  253. );
  254. }
  255. $this->data['heading_title'] = $this->language->get('heading_title');
  256. $this->data['text_no_results'] = $this->language->get('text_no_results');
  257. $this->data['text_abandoned_orders'] = $this->language->get('text_abandoned_orders');
  258. $this->data['column_order_id'] = $this->language->get('column_order_id');
  259. $this->data['column_customer'] = $this->language->get('column_customer');
  260. $this->data['column_status'] = $this->language->get('column_status');
  261. $this->data['column_total'] = $this->language->get('column_total');
  262. $this->data['column_date_added'] = $this->language->get('column_date_added');
  263. $this->data['column_date_modified'] = $this->language->get('column_date_modified');
  264. $this->data['column_action'] = $this->language->get('column_action');
  265. $this->data['button_invoice'] = $this->language->get('button_invoice');
  266. $this->data['button_delete'] = $this->language->get('button_delete');
  267. $this->data['button_filter'] = $this->language->get('button_filter');
  268. $this->data['token'] = $this->session->data['token'];
  269. if (isset($this->error['warning'])) {
  270. $this->data['error_warning'] = $this->error['warning'];
  271. } else {
  272. $this->data['error_warning'] = '';
  273. }
  274. if (isset($this->session->data['success'])) {
  275. $this->data['success'] = $this->session->data['success'];
  276. unset($this->session->data['success']);
  277. } else {
  278. $this->data['success'] = '';
  279. }
  280. $url = '';
  281. if (isset($this->request->get['filter_order_id'])) {
  282. $url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
  283. }
  284. if (isset($this->request->get['filter_customer'])) {
  285. $url .= '&filter_customer=' . $this->request->get['filter_customer'];
  286. }
  287. if (isset($this->request->get['filter_order_status_id'])) {
  288. $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id'];
  289. }
  290. if (isset($this->request->get['filter_total'])) {
  291. $url .= '&filter_total=' . $this->request->get['filter_total'];
  292. }
  293. if (isset($this->request->get['filter_date_added'])) {
  294. $url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
  295. }
  296. if (isset($this->request->get['filter_date_modified'])) {
  297. $url .= '&filter_date_modified=' . $this->request->get['filter_date_modified'];
  298. }
  299. if ($order == 'ASC') {
  300. $url .= '&order=' . 'DESC';
  301. } else {
  302. $url .= '&order=' . 'ASC';
  303. }
  304. if (isset($this->request->get['page'])) {
  305. $url .= '&page=' . $this->request->get['page'];
  306. }
  307. $this->data['sort_order'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . '&sort=o.order_id' . $url, 'SSL');
  308. $this->data['sort_customer'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . '&sort=customer' . $url, 'SSL');
  309. $this->data['sort_status'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . '&sort=status' . $url, 'SSL');
  310. $this->data['sort_total'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . '&sort=o.total' . $url, 'SSL');
  311. $this->data['sort_date_added'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . '&sort=o.date_added' . $url, 'SSL');
  312. $this->data['sort_date_modified'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . '&sort=o.date_modified' . $url, 'SSL');
  313. $url = '';
  314. if (isset($this->request->get['filter_order_id'])) {
  315. $url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
  316. }
  317. if (isset($this->request->get['filter_customer'])) {
  318. $url .= '&filter_customer=' . $this->request->get['filter_customer'];
  319. }
  320. if (isset($this->request->get['filter_order_status_id'])) {
  321. $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id'];
  322. }
  323. if (isset($this->request->get['filter_total'])) {
  324. $url .= '&filter_total=' . $this->request->get['filter_total'];
  325. }
  326. if (isset($this->request->get['filter_date_added'])) {
  327. $url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
  328. }
  329. if (isset($this->request->get['filter_date_modified'])) {
  330. $url .= '&filter_date_modified=' . $this->request->get['filter_date_modified'];
  331. }
  332. if (isset($this->request->get['sort'])) {
  333. $url .= '&sort=' . $this->request->get['sort'];
  334. }
  335. if (isset($this->request->get['order'])) {
  336. $url .= '&order=' . $this->request->get['order'];
  337. }
  338. $pagination = new Pagination();
  339. $pagination->total = $order_total;
  340. $pagination->page = $page;
  341. $pagination->limit = $this->config->get('config_admin_limit');
  342. $pagination->text = $this->language->get('text_pagination');
  343. $pagination->url = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . $url . '&page={page}', 'SSL');
  344. $this->data['pagination'] = $pagination->render();
  345. $this->data['filter_order_id'] = $filter_order_id;
  346. $this->data['filter_customer'] = $filter_customer;
  347. $this->data['filter_order_status_id'] = $filter_order_status_id;
  348. $this->data['filter_total'] = $filter_total;
  349. $this->data['filter_date_added'] = $filter_date_added;
  350. $this->data['filter_date_modified'] = $filter_date_modified;
  351. $this->load->model('localisation/order_status');
  352. $this->data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
  353. $this->data['sort'] = $sort;
  354. $this->data['order'] = $order;
  355. $this->template = 'sale/order_list.tpl';
  356. $this->children = array(
  357. 'common/header',
  358. 'common/footer'
  359. );
  360. $this->response->setOutput($this->render());
  361. }
  362. public function getForm() {
  363. $this->data['heading_title'] = $this->language->get('heading_title');
  364. $this->data['text_default'] = $this->language->get('text_default');
  365. $this->data['text_select'] = $this->language->get('text_select');
  366. $this->data['text_none'] = $this->language->get('text_none');
  367. $this->data['text_wait'] = $this->language->get('text_wait');
  368. $this->data['entry_store'] = $this->language->get('entry_store');
  369. $this->data['entry_customer'] = $this->language->get('entry_customer');
  370. $this->data['entry_customer_group'] = $this->language->get('entry_customer_group');
  371. $this->data['entry_firstname'] = $this->language->get('entry_firstname');
  372. $this->data['entry_lastname'] = $this->language->get('entry_lastname');
  373. $this->data['entry_email'] = $this->language->get('entry_email');
  374. $this->data['entry_telephone'] = $this->language->get('entry_telephone');
  375. $this->data['entry_fax'] = $this->language->get('entry_fax');
  376. $this->data['entry_order_status'] = $this->language->get('entry_order_status');
  377. $this->data['entry_comment'] = $this->language->get('entry_comment');
  378. $this->data['entry_affiliate'] = $this->language->get('entry_affiliate');
  379. $this->data['entry_address'] = $this->language->get('entry_address');
  380. $this->data['entry_company'] = $this->language->get('entry_company');
  381. $this->data['entry_address_1'] = $this->language->get('entry_address_1');
  382. $this->data['entry_address_2'] = $this->language->get('entry_address_2');
  383. $this->data['entry_city'] = $this->language->get('entry_city');
  384. $this->data['entry_postcode'] = $this->language->get('entry_postcode');
  385. $this->data['entry_zone'] = $this->language->get('entry_zone');
  386. $this->data['entry_zone_code'] = $this->language->get('entry_zone_code');
  387. $this->data['entry_country'] = $this->language->get('entry_country');
  388. $this->data['entry_product'] = $this->language->get('entry_product');
  389. $this->data['entry_option'] = $this->language->get('entry_option');
  390. $this->data['entry_quantity'] = $this->language->get('entry_quantity');
  391. $this->data['entry_shipping'] = $this->language->get('entry_shipping');
  392. $this->data['entry_payment'] = $this->language->get('entry_payment');
  393. $this->data['entry_voucher'] = $this->language->get('entry_voucher');
  394. $this->data['entry_reward'] = $this->language->get('entry_reward');
  395. $this->data['column_product'] = $this->language->get('column_product');
  396. $this->data['column_model'] = $this->language->get('column_model');
  397. $this->data['column_quantity'] = $this->language->get('column_quantity');
  398. $this->data['column_price'] = $this->language->get('column_price');
  399. $this->data['column_total'] = $this->language->get('column_total');
  400. $this->data['button_save'] = $this->language->get('button_save');
  401. $this->data['button_cancel'] = $this->language->get('button_cancel');
  402. $this->data['button_add_product'] = $this->language->get('button_add_product');
  403. $this->data['button_remove'] = $this->language->get('button_remove');
  404. $this->data['button_upload'] = $this->language->get('button_upload');
  405. $this->data['tab_order'] = $this->language->get('tab_order');
  406. $this->data['tab_payment'] = $this->language->get('tab_payment');
  407. $this->data['tab_shipping'] = $this->language->get('tab_shipping');
  408. $this->data['tab_product'] = $this->language->get('tab_product');
  409. $this->data['tab_total'] = $this->language->get('tab_total');
  410. $this->data['token'] = $this->session->data['token'];
  411. if (isset($this->error['warning'])) {
  412. $this->data['error_warning'] = $this->error['warning'];
  413. } else {
  414. $this->data['error_warning'] = '';
  415. }
  416. if (isset($this->error['firstname'])) {
  417. $this->data['error_firstname'] = $this->error['firstname'];
  418. } else {
  419. $this->data['error_firstname'] = '';
  420. }
  421. if (isset($this->error['lastname'])) {
  422. $this->data['error_lastname'] = $this->error['lastname'];
  423. } else {
  424. $this->data['error_lastname'] = '';
  425. }
  426. if (isset($this->error['email'])) {
  427. $this->data['error_email'] = $this->error['email'];
  428. } else {
  429. $this->data['error_email'] = '';
  430. }
  431. if (isset($this->error['telephone'])) {
  432. $this->data['error_telephone'] = $this->error['telephone'];
  433. } else {
  434. $this->data['error_telephone'] = '';
  435. }
  436. if (isset($this->error['shipping_firstname'])) {
  437. $this->data['error_shipping_firstname'] = $this->error['shipping_firstname'];
  438. } else {
  439. $this->data['error_shipping_firstname'] = '';
  440. }
  441. if (isset($this->error['shipping_lastname'])) {
  442. $this->data['error_shipping_lastname'] = $this->error['shipping_lastname'];
  443. } else {
  444. $this->data['error_shipping_lastname'] = '';
  445. }
  446. if (isset($this->error['shipping_address_1'])) {
  447. $this->data['error_shipping_address_1'] = $this->error['shipping_address_1'];
  448. } else {
  449. $this->data['error_shipping_address_1'] = '';
  450. }
  451. if (isset($this->error['shipping_city'])) {
  452. $this->data['error_shipping_city'] = $this->error['shipping_city'];
  453. } else {
  454. $this->data['error_shipping_city'] = '';
  455. }
  456. if (isset($this->error['shipping_postcode'])) {
  457. $this->data['error_shipping_postcode'] = $this->error['shipping_postcode'];
  458. } else {
  459. $this->data['error_shipping_postcode'] = '';
  460. }
  461. if (isset($this->error['shipping_country'])) {
  462. $this->data['error_shipping_country'] = $this->error['shipping_country'];
  463. } else {
  464. $this->data['error_shipping_country'] = '';
  465. }
  466. if (isset($this->error['shipping_zone'])) {
  467. $this->data['error_shipping_zone'] = $this->error['shipping_zone'];
  468. } else {
  469. $this->data['error_shipping_zone'] = '';
  470. }
  471. if (isset($this->error['payment_firstname'])) {
  472. $this->data['error_payment_firstname'] = $this->error['payment_firstname'];
  473. } else {
  474. $this->data['error_payment_firstname'] = '';
  475. }
  476. if (isset($this->error['payment_lastname'])) {
  477. $this->data['error_payment_lastname'] = $this->error['payment_lastname'];
  478. } else {
  479. $this->data['error_payment_lastname'] = '';
  480. }
  481. if (isset($this->error['payment_address_1'])) {
  482. $this->data['error_payment_address_1'] = $this->error['payment_address_1'];
  483. } else {
  484. $this->data['error_payment_address_1'] = '';
  485. }
  486. if (isset($this->error['payment_city'])) {
  487. $this->data['error_payment_city'] = $this->error['payment_city'];
  488. } else {
  489. $this->data['error_payment_city'] = '';
  490. }
  491. if (isset($this->error['payment_postcode'])) {
  492. $this->data['error_payment_postcode'] = $this->error['payment_postcode'];
  493. } else {
  494. $this->data['error_payment_postcode'] = '';
  495. }
  496. if (isset($this->error['payment_country'])) {
  497. $this->data['error_payment_country'] = $this->error['payment_country'];
  498. } else {
  499. $this->data['error_payment_country'] = '';
  500. }
  501. if (isset($this->error['payment_zone'])) {
  502. $this->data['error_payment_zone'] = $this->error['payment_zone'];
  503. } else {
  504. $this->data['error_payment_zone'] = '';
  505. }
  506. $url = '';
  507. if (isset($this->request->get['filter_order_id'])) {
  508. $url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
  509. }
  510. if (isset($this->request->get['filter_customer'])) {
  511. $url .= '&filter_customer=' . $this->request->get['filter_customer'];
  512. }
  513. if (isset($this->request->get['filter_order_status_id'])) {
  514. $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id'];
  515. }
  516. if (isset($this->request->get['filter_total'])) {
  517. $url .= '&filter_total=' . $this->request->get['filter_total'];
  518. }
  519. if (isset($this->request->get['filter_date_added'])) {
  520. $url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
  521. }
  522. if (isset($this->request->get['filter_date_modified'])) {
  523. $url .= '&filter_date_modified=' . $this->request->get['filter_date_modified'];
  524. }
  525. if (isset($this->request->get['sort'])) {
  526. $url .= '&sort=' . $this->request->get['sort'];
  527. }
  528. if (isset($this->request->get['order'])) {
  529. $url .= '&order=' . $this->request->get['order'];
  530. }
  531. if (isset($this->request->get['page'])) {
  532. $url .= '&page=' . $this->request->get['page'];
  533. }
  534. $this->data['breadcrumbs'] = array();
  535. $this->data['breadcrumbs'][] = array(
  536. 'text' => $this->language->get('text_home'),
  537. 'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
  538. 'separator' => false
  539. );
  540. $this->data['breadcrumbs'][] = array(
  541. 'text' => $this->language->get('heading_title'),
  542. 'href' => $this->url->link('sale/order', 'token=' . $this->session->data['token'], 'SSL'),
  543. 'separator' => ' :: '
  544. );
  545. if (!isset($this->request->get['order_id'])) {
  546. $this->data['action'] = $this->url->link('sale/order/insert', 'token=' . $this->session->data['token'] . $url, 'SSL');
  547. } else {
  548. $this->data['action'] = $this->url->link('sale/order/update', 'token=' . $this->session->data['token'] . '&order_id=' . $this->request->get['order_id'] . $url, 'SSL');
  549. }
  550. $this->data['cancel'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . $url, 'SSL');
  551. if (isset($this->request->get['order_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
  552. $order_info = $this->model_sale_order->getOrder($this->request->get['order_id']);
  553. }
  554. if (isset($this->request->post['store_id'])) {
  555. $this->data['store_id'] = $this->request->post['store_id'];
  556. } elseif (!empty($order_info)) {
  557. $this->data['store_id'] = $order_info['store_id'];
  558. } else {
  559. $this->data['store_id'] = '';
  560. }
  561. $this->load->model('setting/store');
  562. $this->data['stores'] = $this->model_setting_store->getStores();
  563. $this->data['store_url'] = HTTP_CATALOG;
  564. if (isset($this->request->post['customer_id'])) {
  565. $this->data['customer_id'] = $this->request->post['customer_id'];
  566. } elseif (!empty($order_info)) {
  567. $this->data['customer_id'] = $order_info['customer_id'];
  568. } else {
  569. $this->data['customer_id'] = '';
  570. }
  571. if (isset($this->request->post['customer'])) {
  572. $this->data['customer'] = $this->request->post['customer'];
  573. } elseif (!empty($order_info)) {
  574. $this->data['customer'] = $order_info['customer'];
  575. } else {
  576. $this->data['customer'] = '';
  577. }
  578. if (isset($this->request->post['firstname'])) {
  579. $this->data['firstname'] = $this->request->post['firstname'];
  580. } elseif (!empty($order_info)) {
  581. $this->data['firstname'] = $order_info['firstname'];
  582. } else {
  583. $this->data['firstname'] = '';
  584. }
  585. if (isset($this->request->post['lastname'])) {
  586. $this->data['lastname'] = $this->request->post['lastname'];
  587. } elseif (!empty($order_info)) {
  588. $this->data['lastname'] = $order_info['lastname'];
  589. } else {
  590. $this->data['lastname'] = '';
  591. }
  592. if (isset($this->request->post['email'])) {
  593. $this->data['email'] = $this->request->post['email'];
  594. } elseif (!empty($order_info)) {
  595. $this->data['email'] = $order_info['email'];
  596. } else {
  597. $this->data['email'] = '';
  598. }
  599. if (isset($this->request->post['telephone'])) {
  600. $this->data['telephone'] = $this->request->post['telephone'];
  601. } elseif (!empty($order_info)) {
  602. $this->data['telephone'] = $order_info['telephone'];
  603. } else {
  604. $this->data['telephone'] = '';
  605. }
  606. if (isset($this->request->post['fax'])) {
  607. $this->data['fax'] = $this->request->post['fax'];
  608. } elseif (!empty($order_info)) {
  609. $this->data['fax'] = $order_info['fax'];
  610. } else {
  611. $this->data['fax'] = '';
  612. }
  613. $this->load->model('sale/customer');
  614. if (isset($this->request->post['customer_id'])) {
  615. $this->data['addresses'] = $this->model_sale_customer->getAddresses($this->request->post['customer_id']);
  616. } elseif (!empty($order_info)) {
  617. $this->data['addresses'] = $this->model_sale_customer->getAddresses($order_info['customer_id']);
  618. } else {
  619. $this->data['addresses'] = array();
  620. }
  621. if (isset($this->request->post['shipping_firstname'])) {
  622. $this->data['shipping_firstname'] = $this->request->post['shipping_firstname'];
  623. } elseif (!empty($order_info)) {
  624. $this->data['shipping_firstname'] = $order_info['shipping_firstname'];
  625. } else {
  626. $this->data['shipping_firstname'] = '';
  627. }
  628. if (isset($this->request->post['shipping_lastname'])) {
  629. $this->data['shipping_lastname'] = $this->request->post['shipping_lastname'];
  630. } elseif (!empty($order_info)) {
  631. $this->data['shipping_lastname'] = $order_info['shipping_lastname'];
  632. } else {
  633. $this->data['shipping_lastname'] = '';
  634. }
  635. if (isset($this->request->post['shipping_company'])) {
  636. $this->data['shipping_company'] = $this->request->post['shipping_company'];
  637. } elseif (!empty($order_info)) {
  638. $this->data['shipping_company'] = $order_info['shipping_company'];
  639. } else {
  640. $this->data['shipping_company'] = '';
  641. }
  642. if (isset($this->request->post['shipping_address_1'])) {
  643. $this->data['shipping_address_1'] = $this->request->post['shipping_address_1'];
  644. } elseif (!empty($order_info)) {
  645. $this->data['shipping_address_1'] = $order_info['shipping_address_1'];
  646. } else {
  647. $this->data['shipping_address_1'] = '';
  648. }
  649. if (isset($this->request->post['shipping_address_2'])) {
  650. $this->data['shipping_address_2'] = $this->request->post['shipping_address_2'];
  651. } elseif (!empty($order_info)) {
  652. $this->data['shipping_address_2'] = $order_info['shipping_address_2'];
  653. } else {
  654. $this->data['shipping_address_2'] = '';
  655. }
  656. if (isset($this->request->post['shipping_city'])) {
  657. $this->data['shipping_city'] = $this->request->post['shipping_city'];
  658. } elseif (!empty($order_info)) {
  659. $this->data['shipping_city'] = $order_info['shipping_city'];
  660. } else {
  661. $this->data['shipping_city'] = '';
  662. }
  663. if (isset($this->request->post['shipping_postcode'])) {
  664. $this->data['shipping_postcode'] = $this->request->post['shipping_postcode'];
  665. } elseif (!empty($order_info)) {
  666. $this->data['shipping_postcode'] = $order_info['shipping_postcode'];
  667. } else {
  668. $this->data['shipping_postcode'] = '';
  669. }
  670. if (isset($this->request->post['shipping_country_id'])) {
  671. $this->data['shipping_country_id'] = $this->request->post['shipping_country_id'];
  672. } elseif (!empty($order_info)) {
  673. $this->data['shipping_country_id'] = $order_info['shipping_country_id'];
  674. } else {
  675. $this->data['shipping_country_id'] = '';
  676. }
  677. if (isset($this->request->post['shipping_zone_id'])) {
  678. $this->data['shipping_zone_id'] = $this->request->post['shipping_zone_id'];
  679. } elseif (!empty($order_info)) {
  680. $this->data['shipping_zone_id'] = $order_info['shipping_zone_id'];
  681. } else {
  682. $this->data['shipping_zone_id'] = '';
  683. }
  684. if (isset($this->request->post['shipping_method'])) {
  685. $this->data['shipping_method'] = $this->request->post['shipping_method'];
  686. } elseif (!empty($order_info)) {
  687. $this->data['shipping_method'] = $order_info['shipping_method'];
  688. } else {
  689. $this->data['shipping_method'] = '';
  690. }
  691. if (isset($this->request->post['payment_firstname'])) {
  692. $this->data['payment_firstname'] = $this->request->post['payment_firstname'];
  693. } elseif (!empty($order_info)) {
  694. $this->data['payment_firstname'] = $order_info['payment_firstname'];
  695. } else {
  696. $this->data['payment_firstname'] = '';
  697. }
  698. if (isset($this->request->post['payment_lastname'])) {
  699. $this->data['payment_lastname'] = $this->request->post['payment_lastname'];
  700. } elseif (!empty($order_info)) {
  701. $this->data['payment_lastname'] = $order_info['payment_lastname'];
  702. } else {
  703. $this->data['payment_lastname'] = '';
  704. }
  705. if (isset($this->request->post['payment_company'])) {
  706. $this->data['payment_company'] = $this->request->post['payment_company'];
  707. } elseif (!empty($order_info)) {
  708. $this->data['payment_company'] = $order_info['payment_company'];
  709. } else {
  710. $this->data['payment_company'] = '';
  711. }
  712. if (isset($this->request->post['payment_address_1'])) {
  713. $this->data['payment_address_1'] = $this->request->post['payment_address_1'];
  714. } elseif (!empty($order_info)) {
  715. $this->data['payment_address_1'] = $order_info['payment_address_1'];
  716. } else {
  717. $this->data['payment_address_1'] = '';
  718. }
  719. if (isset($this->request->post['payment_address_2'])) {
  720. $this->data['payment_address_2'] = $this->request->post['payment_address_2'];
  721. } elseif (!empty($order_info)) {
  722. $this->data['payment_address_2'] = $order_info['payment_address_2'];
  723. } else {
  724. $this->data['payment_address_2'] = '';
  725. }
  726. if (isset($this->request->post['payment_city'])) {
  727. $this->data['payment_city'] = $this->request->post['payment_city'];
  728. } elseif (!empty($order_info)) {
  729. $this->data['payment_city'] = $order_info['payment_city'];
  730. } else {
  731. $this->data['payment_city'] = '';
  732. }
  733. if (isset($this->request->post['payment_postcode'])) {
  734. $this->data['payment_postcode'] = $this->request->post['payment_postcode'];
  735. } elseif (!empty($order_info)) {
  736. $this->data['payment_postcode'] = $order_info['payment_postcode'];
  737. } else {
  738. $this->data['payment_postcode'] = '';
  739. }
  740. if (isset($this->request->post['payment_country_id'])) {
  741. $this->data['payment_country_id'] = $this->request->post['payment_country_id'];
  742. } elseif (!empty($order_info)) {
  743. $this->data['payment_country_id'] = $order_info['payment_country_id'];
  744. } else {
  745. $this->data['payment_country_id'] = '';
  746. }
  747. if (isset($this->request->post['payment_zone_id'])) {
  748. $this->data['payment_zone_id'] = $this->request->post['payment_zone_id'];
  749. } elseif (!empty($order_info)) {
  750. $this->data['payment_zone_id'] = $order_info['payment_zone_id'];
  751. } else {
  752. $this->data['payment_zone_id'] = '';
  753. }
  754. $this->load->model('localisation/country');
  755. $this->data['countries'] = $this->model_localisation_country->getCountries();
  756. if (isset($this->request->post['payment_method'])) {
  757. $this->data['payment_method'] = $this->request->post['payment_method'];
  758. } elseif (!empty($order_info)) {
  759. $this->data['payment_method'] = $order_info['payment_method'];
  760. } else {
  761. $this->data['payment_method'] = '';
  762. }
  763. if (isset($this->request->post['affiliate_id'])) {
  764. $this->data['affiliate_id'] = $this->request->post['affiliate_id'];
  765. } elseif (!empty($order_info)) {
  766. $this->data['affiliate_id'] = $order_info['affiliate_id'];
  767. } else {
  768. $this->data['affiliate_id'] = '';
  769. }
  770. if (isset($this->request->post['affiliate'])) {
  771. $this->data['affiliate'] = $this->request->post['affiliate'];
  772. } elseif (!empty($order_info)) {
  773. $this->data['affiliate'] = $order_info['affiliate_firstname'] . ' ' . $order_info['affiliate_lastname'];
  774. } else {
  775. $this->data['affiliate'] = '';
  776. }
  777. if (isset($this->request->post['order_status_id'])) {
  778. $this->data['order_status_id'] = $this->request->post['order_status_id'];
  779. } elseif (!empty($order_info)) {
  780. $this->data['order_status_id'] = $order_info['order_status_id'];
  781. } else {
  782. $this->data['order_status_id'] = '';
  783. }
  784. $this->load->model('localisation/order_status');
  785. $this->data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
  786. if (isset($this->request->post['comment'])) {
  787. $this->data['comment'] = $this->request->post['comment'];
  788. } elseif (!empty($order_info)) {
  789. $this->data['comment'] = $order_info['comment'];
  790. } else {
  791. $this->data['comment'] = '';
  792. }
  793. if (isset($this->request->post['order_product'])) {
  794. $order_products = $this->request->post['order_product'];
  795. } elseif (isset($this->request->get['order_id'])) {
  796. $order_products = $this->model_sale_order->getOrderProducts($this->request->get['order_id']);
  797. } else {
  798. $order_products = array();
  799. }
  800. $this->load->model('catalog/product');
  801. $this->document->addScript('view/javascript/jquery/ajaxupload.js');
  802. $this->data['order_products'] = array();
  803. foreach ($order_products as $order_product) {
  804. $product_info = $this->model_catalog_product->getProduct($order_product['product_id']);
  805. if ($product_info) {
  806. if (isset($this->request->post['order_product'])) {
  807. $order_option = $order_product['order_option'];
  808. } else {
  809. $order_option = $this->model_sale_order->getOrderOptions($this->request->get['order_id'], $order_product['order_product_id']);
  810. }
  811. $this->data['order_products'][] = array(
  812. 'order_product_id' => $order_product['order_product_id'],
  813. 'order_id' => $order_product['order_id'],
  814. 'product_id' => $product_info['product_id'],
  815. 'name' => $product_info['name'],
  816. 'model' => $product_info['model'],
  817. 'option' => $order_option,
  818. 'quantity' => $order_product['quantity'],
  819. 'price' => $order_product['price'],
  820. 'total' => $order_product['total'],
  821. 'tax' => $order_product['tax']
  822. );
  823. }
  824. }
  825. if (isset($this->request->post['order_total'])) {
  826. $this->data['order_totals'] = $this->request->post['order_total'];
  827. } elseif (isset($this->request->get['order_id'])) {
  828. $this->data['order_totals'] = $this->model_sale_order->getOrderTotals($this->request->get['order_id']);
  829. } else {
  830. $this->data['order_totals'] = array();
  831. }
  832. $this->template = 'sale/order_form.tpl';
  833. $this->children = array(
  834. 'common/header',
  835. 'common/footer'
  836. );
  837. $this->response->setOutput($this->render());
  838. }
  839. public function info() {
  840. $this->load->model('sale/order');
  841. if (isset($this->request->get['order_id'])) {
  842. $order_id = $this->request->get['order_id'];
  843. } else {
  844. $order_id = 0;
  845. }
  846. $order_info = $this->model_sale_order->getOrder($order_id);
  847. if ($order_info) {
  848. $this->load->language('sale/order');
  849. $this->document->setTitle($this->language->get('heading_title'));
  850. $this->data['heading_title'] = $this->language->get('heading_title');
  851. $this->data['text_order_id'] = $this->language->get('text_order_id');
  852. $this->data['text_invoice_no'] = $this->language->get('text_invoice_no');
  853. $this->data['text_invoice_date'] = $this->language->get('text_invoice_date');
  854. $this->data['text_store_name'] = $this->language->get('text_store_name');
  855. $this->data['text_store_url'] = $this->language->get('text_store_url');
  856. $this->data['text_customer'] = $this->language->get('text_customer');
  857. $this->data['text_customer_group'] = $this->language->get('text_customer_group');
  858. $this->data['text_email'] = $this->language->get('text_email');
  859. $this->data['text_ip'] = $this->language->get('text_ip');
  860. $this->data['text_telephone'] = $this->language->get('text_telephone');
  861. $this->data['text_fax'] = $this->language->get('text_fax');
  862. $this->data['text_total'] = $this->language->get('text_total');
  863. $this->data['text_reward'] = $this->language->get('text_reward');
  864. $this->data['text_order_status'] = $this->language->get('text_order_status');
  865. $this->data['text_comment'] = $this->language->get('text_comment');
  866. $this->data['text_affiliate'] = $this->language->get('text_affiliate');
  867. $this->data['text_commission'] = $this->language->get('text_commission');
  868. $this->data['text_date_added'] = $this->language->get('text_date_added');
  869. $this->data['text_date_modified'] = $this->language->get('text_date_modified');
  870. $this->data['text_firstname'] = $this->language->get('text_firstname');
  871. $this->data['text_lastname'] = $this->language->get('text_lastname');
  872. $this->data['text_company'] = $this->language->get('text_company');
  873. $this->data['text_address_1'] = $this->language->get('text_address_1');
  874. $this->data['text_address_2'] = $this->language->get('text_address_2');
  875. $this->data['text_city'] = $this->language->get('text_city');
  876. $this->data['text_postcode'] = $this->language->get('text_postcode');
  877. $this->data['text_zone'] = $this->language->get('text_zone');
  878. $this->data['text_zone_code'] = $this->language->get('text_zone_code');
  879. $this->data['text_country'] = $this->language->get('text_country');
  880. $this->data['text_shipping_method'] = $this->language->get('text_shipping_method');
  881. $this->data['text_payment_method'] = $this->language->get('text_payment_method');
  882. $this->data['text_download'] = $this->language->get('text_download');
  883. $this->data['text_wait'] = $this->language->get('text_wait');
  884. $this->data['text_create_invoice_no'] = $this->language->get('text_create_invoice_no');
  885. $this->data['text_reward_add'] = $this->language->get('text_reward_add');
  886. $this->data['text_reward_remove'] = $this->language->get('text_reward_remove');
  887. $this->data['text_commission_add'] = $this->language->get('text_commission_add');
  888. $this->data['text_commission_remove'] = $this->language->get('text_commission_remove');
  889. $this->data['text_credit_add'] = $this->language->get('text_credit_add');
  890. $this->data['text_credit_remove'] = $this->language->get('text_credit_remove');
  891. $this->data['column_product'] = $this->language->get('column_product');
  892. $this->data['column_model'] = $this->language->get('column_model');
  893. $this->data['column_quantity'] = $this->language->get('column_quantity');
  894. $this->data['column_price'] = $this->language->get('column_price');
  895. $this->data['column_total'] = $this->language->get('column_total');
  896. $this->data['column_download'] = $this->language->get('column_download');
  897. $this->data['column_filename'] = $this->language->get('column_filename');
  898. $this->data['column_remaining'] = $this->language->get('column_remaining');
  899. $this->data['entry_order_status'] = $this->language->get('entry_order_status');
  900. $this->data['entry_notify'] = $this->language->get('entry_notify');
  901. $this->data['entry_comment'] = $this->language->get('entry_comment');
  902. $this->data['button_invoice'] = $this->language->get('button_invoice');
  903. $this->data['button_cancel'] = $this->language->get('button_cancel');
  904. $this->data['button_add_history'] = $this->language->get('button_add_history');
  905. $this->data['tab_order'] = $this->language->get('tab_order');
  906. $this->data['tab_payment'] = $this->language->get('tab_payment');
  907. $this->data['tab_shipping'] = $this->language->get('tab_shipping');
  908. $this->data['tab_product'] = $this->language->get('tab_product');
  909. $this->data['tab_order_history'] = $this->language->get('tab_order_history');
  910. $this->data['token'] = $this->session->data['token'];
  911. $url = '';
  912. if (isset($this->request->get['filter_order_id'])) {
  913. $url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
  914. }
  915. if (isset($this->request->get['filter_customer'])) {
  916. $url .= '&filter_customer=' . $this->request->get['filter_customer'];
  917. }
  918. if (isset($this->request->get['filter_order_status_id'])) {
  919. $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id'];
  920. }
  921. if (isset($this->request->get['filter_total'])) {
  922. $url .= '&filter_total=' . $this->request->get['filter_total'];
  923. }
  924. if (isset($this->request->get['filter_date_added'])) {
  925. $url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
  926. }
  927. if (isset($this->request->get['filter_date_modified'])) {
  928. $url .= '&filter_date_modified=' . $this->request->get['filter_date_modified'];
  929. }
  930. if (isset($this->request->get['sort'])) {
  931. $url .= '&sort=' . $this->request->get['sort'];
  932. }
  933. if (isset($this->request->get['order'])) {
  934. $url .= '&order=' . $this->request->get['order'];
  935. }
  936. if (isset($this->request->get['page'])) {
  937. $url .= '&page=' . $this->request->get['page'];
  938. }
  939. $this->data['breadcrumbs'] = array();
  940. $this->data['breadcrumbs'][] = array(
  941. 'text' => $this->language->get('text_home'),
  942. 'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
  943. 'separator' => false
  944. );
  945. $this->data['breadcrumbs'][] = array(
  946. 'text' => $this->language->get('heading_title'),
  947. 'href' => $this->url->link('sale/order', 'token=' . $this->session->data['token'], 'SSL'),
  948. 'separator' => ' :: '
  949. );
  950. $this->data['invoice'] = $this->url->link('sale/order/invoice', 'token=' . $this->session->data['token'] . '&order_id=' . (int)$this->request->get['order_id'], 'SSL');
  951. $this->data['cancel'] = $this->url->link('sale/order', 'token=' . $this->session->data['token'] . $url, 'SSL');
  952. $this->data['order_id'] = $this->request->get['order_id'];
  953. if ($order_info['invoice_no']) {
  954. $this->data['invoice_no'] = $order_info['invoice_prefix'] . $order_info['invoice_no'];
  955. } else {
  956. $this->data['invoice_no'] = '';
  957. }
  958. $this->data['store_name'] = $order_info['store_name'];
  959. $this->data['store_url'] = $order_info['store_url'];
  960. $this->data['firstname'] = $order_info['firstname'];
  961. $this->data['lastname'] = $order_info['lastname'];
  962. if ($order_info['customer_id']) {
  963. $this->data['customer'] = $this->url->link('sale/customer/update', 'token=' . $this->session->data['token'] . '&customer_id=' . $order_info['customer_id'], 'SSL');
  964. } else {
  965. $this->data['customer'] = '';
  966. }
  967. $this->load->model('sale/customer_group');
  968. $customer_group_info = $this->model_sale_customer_group->getCustomerGroup($order_info['customer_group_id']);
  969. if ($customer_group_info) {
  970. $this->data['customer_group'] = $customer_group_info['name'];
  971. } else {
  972. $this->data['customer_group'] = '';
  973. }
  974. $this->data['email'] = $order_info['email'];
  975. $this->data['ip'] = $order_info['ip'];
  976. $this->data['telephone'] = $order_info['telephone'];
  977. $this->data['fax'] = $order_info['fax'];
  978. $this->data['comment'] = nl2br($order_info['comment']);
  979. $this->data['shipping_method'] = $order_info['shipping_method'];
  980. $this->data['payment_method'] = $order_info['payment_method'];
  981. $this->data['total'] = $this->currency->format($order_info['total'], $order_info['currency_code'], $order_info['currency_value']);
  982. $this->data['reward'] = $order_info['reward'];
  983. if ($order_info['total'] < 0) {
  984. $this->data['credit'] = $order_info['total'];
  985. } else {
  986. $this->data['credit'] = 0;
  987. }
  988. $this->load->model('sale/customer');
  989. $this->data['credit_total'] = $this->model_sale_customer->getTotalTransactionsByOrderId($this->request->get['order_id']);
  990. $this->data['reward_total'] = $this->model_sale_customer->getTotalCustomerRewardsByOrderId($this->request->get['order_id']);
  991. $this->data['affiliate_firstname'] = $order_info['affiliate_firstname'];
  992. $this->data['affiliate_lastname'] = $order_info['affiliate_lastname'];
  993. if ($order_info['affiliate_id']) {
  994. $this->data['affiliate'] = $this->url->link('sale/affiliate/update', 'token=' . $this->session->data['token'] . '&affiliate_id=' . $order_info['affiliate_id'], 'SSL');
  995. } else {
  996. $this->data['affiliate'] = '';
  997. }
  998. $this->data['commission'] = $this->currency->format($order_info['commission'], $order_info['currency_code'], $order_info['currency_value']);
  999. $this->load->model('sale/affiliate');
  1000. $this->data['commission_total'] = $this->model_sale_affiliate->getTotalTransactionsByOrderId($this->request->get['order_id']);
  1001. $this->load->model('localisation/order_status');
  1002. $order_status_info = $this->model_localisation_order_status->getOrderStatus($order_info['order_status_id']);
  1003. if ($order_status_info) {
  1004. $this->data['order_status'] = $order_status_info['name'];
  1005. } else {
  1006. $this->data['order_status'] = '';
  1007. }
  1008. $this->data['date_added'] = date($this->language->get('date_format_short'), strtotime($order_info['date_added']));
  1009. $this->data['date_modified'] = date($this->language->get('date_format_short'), strtotime($order_info['date_modified']));
  1010. $this->data['payment_firstname'] = $order_info['payment_firstname'];
  1011. $this->data['payment_lastname'] = $order_info['payment_lastname'];
  1012. $this->data['payment_company'] = $order_info['payment_company'];
  1013. $this->data['payment_address_1'] = $order_info['payment_address_1'];
  1014. $this->data['payment_address_2'] = $order_info['payment_address_2'];
  1015. $this->data['payment_city'] = $order_info['payment_city'];
  1016. $this->data['payment_postcode'] = $order_info['payment_postcode'];
  1017. $this->data['payment_zone'] = $order_info['payment_zone'];
  1018. $this->data['payment_zone_code'] = $order_info['payment_zone_code'];
  1019. $this->data['payment_country'] = $order_info['payment_country'];
  1020. $this->data['shipping_firstname'] = $order_info['shipping_firstname'];
  1021. $this->data['shipping_lastname'] = $order_info['shipping_lastname'];
  1022. $this->data['shipping_company'] = $order_info['shipping_company'];
  1023. $this->data['shipping_address_1'] = $order_info['shipping_address_1'];
  1024. $this->data['shipping_address_2'] = $order_info['shipping_address_2'];
  1025. $this->data['shipping_city'] = $order_info['shipping_city'];
  1026. $this->data['shipping_postcode'] = $order_info['shipping_postcode'];
  1027. $this->data['shipping_zone'] = $order_info['shipping_zone'];
  1028. $this->data['shipping_zone_code'] = $order_info['shipping_zone_code'];
  1029. $this->data['shipping_country'] = $order_info['shipping_country'];
  1030. $this->data['products'] = array();
  1031. $products = $this->model_sale_order->getOrderProducts($this->request->get['order_id']);
  1032. foreach ($products as $product) {
  1033. $option_data = array();
  1034. $options = $this->model_sale_order->getOrderOptions($this->request->get['order_id'], $product['order_product_id']);
  1035. foreach ($options as $option) {
  1036. if ($option['type'] != 'file') {
  1037. $option_data[] = array(
  1038. 'name' => $option['name'],
  1039. 'value' => $option['value'],
  1040. 'type' => $option['type']
  1041. );
  1042. } else {
  1043. $option_data[] = array(
  1044. 'name' => $option['name'],
  1045. 'value' => utf8_substr($option['value'], 0, strrpos($option['value'], '.')),
  1046. 'type' => $option['type'],
  1047. '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')
  1048. );
  1049. }
  1050. }
  1051. $this->data['products'][] = array(
  1052. 'order_product_id' => $product['order_product_id'],
  1053. 'product_id' => $product['product_id'],
  1054. 'name' => $product['name'],
  1055. 'model' => $product['model'],
  1056. 'option' => $option_data,
  1057. 'quantity' => $product['quantity'],
  1058. 'price' => $this->currency->format($product['price'], $order_info['currency_code'], $order_info['currency_value']),
  1059. 'total' => $this->currency->format($product['total'], $order_info['currency_code'], $order_info['currency_value']),
  1060. 'href' => $this->url->link('catalog/product/update', 'token=' . $this->session->data['token'] . '&product_id=' . $product['product_id'], 'SSL')
  1061. );
  1062. }
  1063. $this->data['totals'] = $this->model_sale_order->getOrderTotals($this->request->get['order_id']);
  1064. $this->data['downloads'] = array();
  1065. $results = $this->model_sale_order->getOrderDownloads($this->request->get['order_id']);
  1066. foreach ($results as $result) {
  1067. $this->data['downloads'][] = array(
  1068. 'name' => $result['name'],
  1069. 'filename' => $result['mask'],
  1070. 'remaining' => $result['remaining']
  1071. );
  1072. }
  1073. $this->data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
  1074. $this->data['order_status_id'] = $order_info['order_status_id'];
  1075. $this->template = 'sale/order_info.tpl';
  1076. $this->children = array(
  1077. 'common/header',
  1078. 'common/footer'
  1079. );
  1080. $this->response->setOutput($this->render());
  1081. } else {
  1082. $this->load->language('error/not_found');
  1083. $this->document->setTitle($this->language->get('heading_title'));
  1084. $this->data['heading_title'] = $this->language->get('heading_title');
  1085. $this->data['text_not_found'] = $this->language->get('text_not_found');
  1086. $this->data['breadcrumbs'] = array();
  1087. $this->data['breadcrumbs'][] = array(
  1088. 'text' => $this->language->get('text_home'),
  1089. 'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
  1090. 'separator' => false
  1091. );
  1092. $this->data['breadcrumbs'][] = array(
  1093. 'text' => $this->language->get('heading_title'),
  1094. 'href' => $this->url->link('error/not_found', 'token=' . $this->session->data['token'], 'SSL'),
  1095. 'separator' => ' :: '
  1096. );
  1097. $this->template = 'error/not_found.tpl';
  1098. $this->children = array(
  1099. 'common/header',
  1100. 'common/footer'
  1101. );
  1102. $this->response->setOutput($this->render());
  1103. }
  1104. }
  1105. private function validateForm() {
  1106. if (!$this->user->hasPermission('modify', 'sale/order')) {
  1107. $this->error['warning'] = $this->language->get('error_permission');
  1108. }
  1109. if ((utf8_strlen($this->request->post['firstname']) < 1) || (utf8_strlen($this->request->post['firstname']) > 32)) {
  1110. $this->error['firstname'] = $this->language->get('error_firstname');
  1111. }
  1112. if ((utf8_strlen($this->request->post['lastname']) < 1) || (utf8_strlen($this->request->post['lastname']) > 32)) {
  1113. $this->error['lastname'] = $this->language->get('error_lastname');
  1114. }
  1115. if ((utf8_strlen($this->request->post['email']) > 96) || (!preg_match('/^[^\@]+@.*\.[a-z]{2,6}$/i', $this->request->post['email']))) {
  1116. $this->error['email'] = $this->language->get('error_email');
  1117. }
  1118. if ((utf8_strlen($this->request->post['telephone']) < 3) || (utf8_strlen($this->request->post['telephone']) > 32)) {
  1119. $this->error['telephone'] = $this->language->get('error_telephone');
  1120. }
  1121. if ((utf8_strlen($this->request->post['shipping_firstname']) < 1) || (utf8_strlen($this->request->post['shipping_firstname']) > 32)) {
  1122. $this->error['shipping_firstname'] = $this->language->get('error_firstname');
  1123. }
  1124. if ((utf8_strlen($this->request->post['shipping_lastname']) < 1) || (utf8_strlen($this->request->post['shipping_lastname']) > 32)) {
  1125. $this->error['shipping_lastname'] = $this->language->get('error_lastname');
  1126. }
  1127. if ((utf8_strlen($this->request->post['shipping_address_1']) < 3) || (utf8_strlen($this->request->post['shipping_address_1']) > 128)) {
  1128. $this->error['shipping_address_1'] = $this->language->get('error_address_1');
  1129. }
  1130. if ((utf8_strlen($this->request->post['shipping_city']) < 3) || (utf8_strlen($this->request->post['shipping_city']) > 128)) {
  1131. $this->error['shipping_city'] = $this->language->get('error_city');
  1132. }
  1133. $this->load->model('localisation/country');
  1134. $country_info = $this->model_localisation_country->getCountry($this->request->post['shipping_country_id']);
  1135. if ($country_info && $country_info['postcode_required'] && (utf8_strlen($this->request->post['shipping_postcode']) < 2) || (utf8_strlen($this->request->post['shipping_postcode']) > 10)) {
  1136. $this->error['shipping_postcode'] = $this->language->get('error_postcode');
  1137. }
  1138. if ($this->request->post['shipping_country_id'] == '') {
  1139. $this->error['shipping_country'] = $this->language->get('error_country');
  1140. }
  1141. if ($this->request->post['shipping_zone_id'] == '') {
  1142. $this->error['shipping_zone'] = $this->language->get('error_zone');
  1143. }
  1144. if ((utf8_strlen($this->request->post['payment_firstname']) < 1) || (utf8_strlen($this->request->post['payment_firstname']) > 32)) {
  1145. $this->error['payment_firstname'] = $this->language->get('error_firstname');
  1146. }
  1147. if ((utf8_strlen($this->request->post['payment_lastname']) < 1) || (utf8_strlen($this->request->post['payment_lastname']) > 32)) {
  1148. $this->error['payment_lastname'] = $this->language->get('error_lastname');
  1149. }
  1150. if ((utf8_strlen($this->request->post['payment_address_1']) < 3) || (utf8_strlen($this->request->post['payment_address_1']) > 128)) {
  1151. $this->error['payment_address_1'] = $this->language->get('error_address_1');
  1152. }
  1153. if ((utf8_strlen($this->request->post['payment_city']) < 3) || (utf8_strlen($this->request->post['payment_city']) > 128)) {
  1154. $this->error['payment_city'] = $this->language->get('error_city');
  1155. }
  1156. $country_info = $this->model_localisation_country->getCountry($this->request->post['payment_country_id']);
  1157. if ($country_info && $country_info['postcode_required'] && (utf8_strlen($this->request->post['payment_postcode']) < 2) || (utf8_strlen($this->request->post['payment_postcode']) > 10)) {
  1158. $this->error['payment_postcode'] = $this->language->get('error_postcode');
  1159. }
  1160. if ($this->request->post['payment_country_id'] == '') {
  1161. $this->error['payment_country'] = $this->language->get('error_country');
  1162. }
  1163. if ($this->request->post['payment_zone_id'] == '') {
  1164. $this->error['payment_zone'] = $this->language->get('error_zone');
  1165. }
  1166. if ($this->error && !isset($this->error['warning'])) {
  1167. $this->error['warning'] = $this->language->get('error_warning');
  1168. }
  1169. if (!$this->error) {
  1170. return true;
  1171. } else {
  1172. return false;
  1173. }
  1174. }
  1175. private function validateDelete() {
  1176. if (!$this->user->hasPermission('modify', 'sale/order')) {
  1177. $this->error['warning'] = $this->language->get('error_permission');
  1178. }
  1179. if (!$this->error) {
  1180. return true;
  1181. } else {
  1182. return false;
  1183. }
  1184. }
  1185. public function zone() {
  1186. $output = '<option value="">' . $this->language->get('text_select') . '</option>';
  1187. $this->load->model('localisation/zone');
  1188. $results = $this->model_localisation_zone->getZonesByCountryId($this->request->get['country_id']);
  1189. foreach ($results as $result) {
  1190. $output .= '<option value="' . $result['zone_id'] . '"';
  1191. if (isset($this->request->get['zone_id']) && ($this->request->get['zone_id'] == $result['zone_id'])) {
  1192. $output .= ' selected="selected"';
  1193. }
  1194. $output .= '>' . $result['name'] . '</option>';
  1195. }
  1196. if (!$results) {
  1197. $output .= '<option value="0">' . $this->language->get('text_none') . '</option>';
  1198. }
  1199. $this->response->setOutput($output);
  1200. }
  1201. public function createInvoiceNo() {
  1202. $this->language->load('sale/order');
  1203. $json = array();
  1204. if (!$this->user->hasPermission('modify', 'sale/order')) {
  1205. $json['error'] = $this->language->get('error_permission');
  1206. } elseif (isset($this->request->get['order_id'])) {
  1207. $this->load->model('sale/order');
  1208. $invoice_no = $this->model_sale_order->createInvoiceNo($this->request->get['order_id']);
  1209. if ($invoice_no) {
  1210. $json['invoice_no'] = $invoice_no;
  1211. } else {
  1212. $json['error'] = $this->language->get('error_action');
  1213. }
  1214. }
  1215. $this->response->setOutput(json_encode($json));
  1216. }
  1217. public function addCredit() {
  1218. $this->language->load('sale/order');
  1219. $json = array();
  1220. if (!$this->user->hasPermission('modify', 'sale/order')) {
  1221. $json['error'] = $this->language->get('error_permission');
  1222. } elseif (isset($this->request->get['order_id'])) {
  1223. $this->load->model('sale/order');
  1224. $order_info = $this->model_sale_order->getOrder($this->request->get['order_id']);
  1225. if ($order_info && $order_info['customer_id']) {
  1226. $this->load->model('sale/customer');
  1227. $credit_total = $this->model_sale_customer->getTotalTransactionsByOrderId($this->request->get['order_id']);
  1228. if (!$credit_total) {
  1229. $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']);
  1230. $json['success'] = $this->language->get('text_credit_added');
  1231. } else {
  1232. $json['error'] = $this->language->get('error_action');
  1233. }
  1234. }
  1235. }
  1236. $this->response->setOutput(json_encode($json));
  1237. }
  1238. public function removeCredit() {
  1239. $this->language->load('sale/order');
  1240. $json = array();
  1241. if (!$this->user->hasPermission('modify', 'sale/order')) {
  1242. $json['error'] = $this->language->get('error_permission');
  1243. } elseif (isset($this->request->get['order_id'])) {
  1244. $this->load->model('sale/order');
  1245. $order_info = $this->model_sale_order->getOrder($this->request->get['order_id']);
  1246. if ($order_info && $order_info['customer_id']) {
  1247. $this->load->model('sale/customer');
  1248. $this->model_sale_customer->deleteTransaction($this->request->get['order_id']);
  1249. $json['success'] = $this->language->get('text_credit_removed');
  1250. } else {
  1251. $json['error'] = $this->language->get('error_action');
  1252. }
  1253. }
  1254. $this->response->setOutput(json_encode($json));
  1255. }
  1256. public function addReward() {
  1257. $this->language->load('sale/order');
  1258. $json = array();
  1259. if (!$this->user->hasPermission('modify', 'sale/order')) {
  1260. $json['error'] = $this->language->get('error_permission');
  1261. } elseif (isset($this->request->get['order_id'])) {
  1262. $this->load->model('sale/order');
  1263. $order_info = $this->model_sale_order->getOrder($this->request->get['order_id']);
  1264. if ($order_info && $order_info['customer_id']) {
  1265. $this->load->model('sale/customer');
  1266. $reward_total = $this->model_sale_customer->getTotalCustomerRewardsByOrderId($this->request->get['order_id']);
  1267. if (!$reward_total) {
  1268. $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']);
  1269. $json['success'] = $this->language->get('text_reward_added');
  1270. } else {
  1271. $json['error'] = $this->language->get('error_action');
  1272. }
  1273. } else {
  1274. $json['error'] = $this->language->get('error_action');
  1275. }
  1276. }
  1277. $this->response->setOutput(json_encode($json));
  1278. }
  1279. public function removeReward() {
  1280. $this->language->load('sale/order');
  1281. $json = array();
  1282. if (!$this->user->hasPermission('modify', 'sale/order')) {
  1283. $json['error'] = $this->language->get('error_permission');
  1284. } elseif (isset($this->request->get['order_id'])) {
  1285. $this->load->model('sale/order');
  1286. $order_info = $this->model_sale_order->getOrder($this->request->get['order_id']);
  1287. if ($order_info && $order_info['customer_id']) {
  1288. $this->load->model('sale/customer');
  1289. $this->model_sale_customer->deleteReward($this->request->get['order_id']);
  1290. $json['success'] = $this->language->get('text_reward_removed');
  1291. } else {
  1292. $json['error'] = $this->language->get('error_action');
  1293. }
  1294. }
  1295. $this->response->setOutput(json_encode($json));
  1296. }
  1297. public function addCommission() {
  1298. $this->language->load('sale/order');
  1299. $json = array();
  1300. if (!$this->user->hasPermission('modify', 'sale/order')) {
  1301. $json['error'] = $this->language->get('error_permission');
  1302. } elseif (isset($this->request->get['order_id'])) {
  1303. $this->load->model('sale/order');
  1304. $order_info = $this->model_sale_order->getOrder($this->request->get['order_id']);
  1305. if ($order_info && $order_info['affiliate_id']) {
  1306. $this->load->model('sale/affiliate');
  1307. $affiliate_total = $this->model_sale_affiliate->getTotalTransactionsByOrderId($this->request->get['order_id']);
  1308. if (!$affiliate_total) {
  1309. $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']);
  1310. $json['success'] = $this->language->get('text_commission_added');
  1311. } else {
  1312. $json['error'] = $this->language->get('error_action');
  1313. }
  1314. } else {
  1315. $json['error'] = $this->language->get('error_action');
  1316. }
  1317. }
  1318. $this->response->setOutput(json_encode($json));
  1319. }
  1320. public function removeCommission() {
  1321. $this->language->load('sale/order');
  1322. $json = array();
  1323. if (!$this->user->hasPermission('modify', 'sale/order')) {
  1324. $json['error'] = $this->language->get('error_permission');
  1325. } elseif (isset($this->request->get['order_id'])) {
  1326. $this->load->model('sale/order');
  1327. $order_info = $this->model_sale_order->getOrder($this->request->get['order_id']);
  1328. if ($order_info && $order_info['affiliate_id']) {
  1329. $this->load->model('sale/affiliate');
  1330. $this->model_sale_affiliate->deleteTransaction($this->request->get['order_id']);
  1331. $json['success'] = $this->language->get('text_commission_removed');
  1332. } else {
  1333. $json['error'] = $this->language->get('error_action');
  1334. }
  1335. }
  1336. $this->response->setOutput(json_encode($json));
  1337. }
  1338. public function history() {
  1339. $this->language->load('sale/order');
  1340. $this->load->model('sale/order');
  1341. if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->user->hasPermission('modify', 'sale/order')) {
  1342. $this->model_sale_order->addOrderHistory($this->request->get['order_id'], $this->request->post);
  1343. $this->data['success'] = $this->language->get('text_success');
  1344. } else {
  1345. $this->data['success'] = '';
  1346. }
  1347. if (($this->request->server['REQUEST_METHOD'] == 'POST') && !$this->user->hasPermission('modify', 'sale/order')) {
  1348. $this->data['error_warning'] = $this->language->get('error_permission');
  1349. } else {
  1350. $this->data['error_warning'] = '';
  1351. }
  1352. $this->data['text_no_results'] = $this->language->get('text_no_results');
  1353. $this->data['column_date_added'] = $this->language->get('column_date_added');
  1354. $this->data['column_status'] = $this->language->get('column_status');
  1355. $this->data['column_notify'] = $this->language->get('column_notify');
  1356. $this->data['column_comment'] = $this->language->get('column_comment');
  1357. if (isset($this->request->get['page'])) {
  1358. $page = $this->request->get['page'];
  1359. } else {
  1360. $page = 1;
  1361. }
  1362. $this->data['histories'] = array();
  1363. $results = $this->model_sale_order->getOrderHistories($this->request->get['order_id'], ($page - 1) * 10, 10);
  1364. foreach ($results as $result) {
  1365. $this->data['histories'][] = array(
  1366. 'notify' => $result['notify'] ? $this->language->get('text_yes') : $this->language->get('text_no'),
  1367. 'status' => $result['status'],
  1368. 'comment' => nl2br($result['comment']),
  1369. 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added']))
  1370. );
  1371. }
  1372. $history_total = $this->model_sale_order->getTotalOrderHistories($this->request->get['order_id']);
  1373. $pagination = new Pagination();
  1374. $pagination->total = $history_total;
  1375. $pagination->page = $page;
  1376. $pagination->limit = 10;
  1377. $pagination->text = $this->language->get('text_pagination');
  1378. $pagination->url = $this->url->link('sale/order/history', 'token=' . $this->session->data['token'] . '&order_id=' . $this->request->get['order_id'] . '&page={page}', 'SSL');
  1379. $this->data['pagination'] = $pagination->render();
  1380. $this->template = 'sale/order_history.tpl';
  1381. $this->response->setOutput($this->render());
  1382. }
  1383. public function download() {
  1384. $this->load->model('sale/order');
  1385. if (isset($this->request->get['order_option_id'])) {
  1386. $order_option_id = $this->request->get['order_option_id'];
  1387. } else {
  1388. $order_option_id = 0;
  1389. }
  1390. $option_info = $this->model_sale_order->getOrderOption($this->request->get['order_id'], $order_option_id);
  1391. if ($option_info && $option_info['type'] == 'file') {
  1392. $file = DIR_DOWNLOAD . $option_info['value'];
  1393. $mask = basename(utf8_substr($option_info['value'], 0, strrpos($option_info['value'], '.')));
  1394. if (!headers_sent()) {
  1395. if (file_exists($file)) {
  1396. header('Content-Description: File Transfer');
  1397. header('Content-Type: application/octet-stream');
  1398. header('Content-Disposition: attachment; filename="' . ($mask ? $mask : basename($file)) . '"');
  1399. header('Content-Transfer-Encoding: binary');
  1400. header('Expires: 0');
  1401. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  1402. header('Pragma: public');
  1403. header('Content-Length: ' . filesize($file));
  1404. readfile($file, 'rb');
  1405. exit;
  1406. } else {
  1407. exit('Error: Could not find file ' . $file . '!');
  1408. }
  1409. } else {
  1410. exit('Error: Headers already sent out!');
  1411. }
  1412. } else {
  1413. $this->load->language('error/not_found');
  1414. $this->document->setTitle($this->language->get('heading_title'));
  1415. $this->data['heading_title'] = $this->language->get('heading_title');
  1416. $this->data['text_not_found'] = $this->language->get('text_not_found');
  1417. $this->data['breadcrumbs'] = array();
  1418. $this->data['breadcrumbs'][] = array(
  1419. 'text' => $this->language->get('text_home'),
  1420. 'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
  1421. 'separator' => false
  1422. );
  1423. $this->data['breadcrumbs'][] = array(
  1424. 'text' => $this->language->get('heading_title'),
  1425. 'href' => $this->url->link('error/not_found', 'token=' . $this->session->data['token'], 'SSL'),
  1426. 'separator' => ' :: '
  1427. );
  1428. $this->template = 'error/not_found.tpl';
  1429. $this->children = array(
  1430. 'common/header',
  1431. 'common/footer'
  1432. );
  1433. $this->response->setOutput($this->render());
  1434. }
  1435. }
  1436. public function upload() {
  1437. $this->language->load('sale/order');
  1438. $json = array();
  1439. if (!empty($this->request->files['file']['name'])) {
  1440. $filename = html_entity_decode($this->request->files['file']['name'], ENT_QUOTES, 'UTF-8');
  1441. if ((strlen($filename) < 3) || (strlen($filename) > 128)) {
  1442. $json['error'] = $this->language->get('error_filename');
  1443. }
  1444. $allowed = array();
  1445. $filetypes = explode(',', $this->config->get('config_upload_allowed'));
  1446. foreach ($filetypes as $filetype) {
  1447. $allowed[] = trim($filetype);
  1448. }
  1449. if (!in_array(utf8_substr(strrchr($filename, '.'), 1), $allowed)) {
  1450. $json['error'] = $this->language->get('error_filetype');
  1451. }
  1452. if ($this->request->files['file']['error'] != UPLOAD_ERR_OK) {
  1453. $json['error'] = $this->language->get('error_upload_' . $this->request->files['file']['error']);
  1454. }
  1455. } else {
  1456. $json['error'] = $this->language->get('error_upload');
  1457. }
  1458. if (($this->request->server['REQUEST_METHOD'] == 'POST') && !isset($json['error'])) {
  1459. if (is_uploaded_file($this->request->files['file']['tmp_name']) && file_exists($this->request->files['file']['tmp_name'])) {
  1460. $file = basename($filename) . '.' . md5(rand());
  1461. $json['file'] = $file;
  1462. move_uploaded_file($this->request->files['file']['tmp_name'], DIR_DOWNLOAD . $file);
  1463. }
  1464. $json['success'] = $this->language->get('text_upload');
  1465. }
  1466. $this->response->setOutput(json_encode($json));
  1467. }
  1468. public function invoice() {
  1469. $this->load->language('sale/order');
  1470. $this->data['title'] = $this->language->get('heading_title');
  1471. if (isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == 'on') || ($this->request->server['HTTPS'] == '1'))) {
  1472. $this->data['base'] = HTTPS_SERVER;
  1473. } else {
  1474. $this->data['base'] = HTTP_SERVER;
  1475. }
  1476. $this->data['direction'] = $this->language->get('direction');
  1477. $this->data['language'] = $this->language->get('code');
  1478. $this->data['text_invoice'] = $this->language->get('text_invoice');
  1479. $this->data['text_order_id'] = $this->language->get('text_order_id');
  1480. $this->data['text_invoice_no'] = $this->language->get('text_invoice_no');
  1481. $this->data['text_invoice_date'] = $this->language->get('text_invoice_date');
  1482. $this->data['text_date_added'] = $this->language->get('text_date_added');
  1483. $this->data['text_telephone'] = $this->language->get('text_telephone');
  1484. $this->data['text_fax'] = $this->language->get('text_fax');
  1485. $this->data['text_to'] = $this->language->get('text_to');
  1486. $this->data['text_ship_to'] = $this->language->get('text_ship_to');
  1487. $this->data['column_product'] = $this->language->get('column_product');
  1488. $this->data['column_model'] = $this->language->get('column_model');
  1489. $this->data['column_quantity'] = $this->language->get('column_quantity');
  1490. $this->data['column_price'] = $this->language->get('column_price');
  1491. $this->data['column_total'] = $this->language->get('column_total');
  1492. $this->data['column_comment'] = $this->language->get('column_comment');
  1493. $this->load->model('sale/order');
  1494. $this->load->model('setting/setting');
  1495. $this->data['orders'] = array();
  1496. $orders = array();
  1497. if (isset($this->request->post['selected'])) {
  1498. $orders = $this->request->post['selected'];
  1499. } elseif (isset($this->request->get['order_id'])) {
  1500. $orders[] = $this->request->get['order_id'];
  1501. }
  1502. foreach ($orders as $order_id) {
  1503. $order_info = $this->model_sale_order->getOrder($order_id);
  1504. if ($order_info) {
  1505. $store_info = $this->model_setting_setting->getSetting('config', $order_info['store_id']);
  1506. if ($store_info) {
  1507. $store_address = $store_info['config_address'];
  1508. $store_email = $store_info['config_email'];
  1509. $store_telephone = $store_info['config_telephone'];
  1510. $store_fax = $store_info['config_fax'];
  1511. } else {
  1512. $store_address = $this->config->get('config_address');
  1513. $store_email = $this->config->get('config_email');
  1514. $store_telephone = $this->config->get('config_telephone');
  1515. $store_fax = $this->config->get('config_fax');
  1516. }
  1517. if ($order_info['invoice_no']) {
  1518. $invoice_no = $order_info['invoice_prefix'] . $order_info['invoice_no'];
  1519. } else {
  1520. $invoice_no = '';
  1521. }
  1522. if ($order_info['shipping_address_format']) {
  1523. $format = $order_info['shipping_address_format'];
  1524. } else {
  1525. $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
  1526. }
  1527. $find = array(
  1528. '{firstname}',
  1529. '{lastname}',
  1530. '{company}',
  1531. '{address_1}',
  1532. '{address_2}',
  1533. '{city}',
  1534. '{postcode}',
  1535. '{zone}',
  1536. '{zone_code}',
  1537. '{country}'
  1538. );
  1539. $replace = array(
  1540. 'firstname' => $order_info['shipping_firstname'],
  1541. 'lastname' => $order_info['shipping_lastname'],
  1542. 'company' => $order_info['shipping_company'],
  1543. 'address_1' => $order_info['shipping_address_1'],
  1544. 'address_2' => $order_info['shipping_address_2'],
  1545. 'city' => $order_info['shipping_city'],
  1546. 'postcode' => $order_info['shipping_postcode'],
  1547. 'zone' => $order_info['shipping_zone'],
  1548. 'zone_code' => $order_info['shipping_zone_code'],
  1549. 'country' => $order_info['shipping_country']
  1550. );
  1551. $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))));
  1552. if ($order_info['payment_address_format']) {
  1553. $format = $order_info['payment_address_format'];
  1554. } else {
  1555. $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
  1556. }
  1557. $find = array(
  1558. '{firstname}',
  1559. '{lastname}',
  1560. '{company}',
  1561. '{address_1}',
  1562. '{address_2}',
  1563. '{city}',
  1564. '{postcode}',
  1565. '{zone}',
  1566. '{zone_code}',
  1567. '{country}'
  1568. );
  1569. $replace = array(
  1570. 'firstname' => $order_info['payment_firstname'],
  1571. 'lastname' => $order_info['payment_lastname'],
  1572. 'company' => $order_info['payment_company'],
  1573. 'address_1' => $order_info['payment_address_1'],
  1574. 'address_2' => $order_info['payment_address_2'],
  1575. 'city' => $order_info['payment_city'],
  1576. 'postcode' => $order_info['payment_postcode'],
  1577. 'zone' => $order_info['payment_zone'],
  1578. 'zone_code' => $order_info['payment_zone_code'],
  1579. 'country' => $order_info['payment_country']
  1580. );
  1581. $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))));
  1582. $product_data = array();
  1583. $products = $this->model_sale_order->getOrderProducts($order_id);
  1584. foreach ($products as $product) {
  1585. $option_data = array();
  1586. $options = $this->model_sale_order->getOrderOptions($order_id, $product['order_product_id']);
  1587. foreach ($options as $option) {
  1588. if ($option['type'] != 'file') {
  1589. $option_data[] = array(
  1590. 'name' => $option['name'],
  1591. 'value' => $option['value']
  1592. );
  1593. } else {
  1594. $option_data[] = array(
  1595. 'name' => $option['name'],
  1596. 'value' => utf8_substr($option['value'], 0, strrpos($option['value'], '.'))
  1597. );
  1598. }
  1599. }
  1600. $product_data[] = array(
  1601. 'name' => $product['name'],
  1602. 'model' => $product['model'],
  1603. 'option' => $option_data,
  1604. 'quantity' => $product['quantity'],
  1605. 'price' => $this->currency->format($product['price'], $order_info['currency_code'], $order_info['currency_value']),
  1606. 'total' => $this->currency->format($product['total'], $order_info['currency_code'], $order_info['currency_value'])
  1607. );
  1608. }
  1609. $total_data = $this->model_sale_order->getOrderTotals($order_id);
  1610. $this->data['orders'][] = array(
  1611. 'order_id' => $order_id,
  1612. 'invoice_no' => $invoice_no,
  1613. 'date_added' => date($this->language->get('date_format_short'), strtotime($order_info['date_added'])),
  1614. 'store_name' => $order_info['store_name'],
  1615. 'store_url' => rtrim($order_info['store_url'], '/'),
  1616. 'store_address' => nl2br($store_address),
  1617. 'store_email' => $store_email,
  1618. 'store_telephone' => $store_telephone,
  1619. 'store_fax' => $store_fax,
  1620. 'email' => $order_info['email'],
  1621. 'telephone' => $order_info['telephone'],
  1622. 'shipping_address' => $shipping_address,
  1623. 'payment_address' => $payment_address,
  1624. 'product' => $product_data,
  1625. 'total' => $total_data,
  1626. 'comment' => nl2br($order_info['comment'])
  1627. );
  1628. }
  1629. }
  1630. $this->template = 'sale/order_invoice.tpl';
  1631. $this->response->setOutput($this->render());
  1632. }
  1633. }
  1634. ?>