1: <?php
2: namespace Opencart\Admin\Controller\Sale;
3: /**
4: * Class Order
5: *
6: * @package Opencart\Admin\Controller\Sale
7: */
8: class Order extends \Opencart\System\Engine\Controller {
9: /**
10: * Index
11: *
12: * @return void
13: */
14: public function index(): void {
15: $this->load->language('sale/order');
16:
17: $this->document->setTitle($this->language->get('heading_title'));
18:
19: if (isset($this->request->get['filter_order_id'])) {
20: $filter_order_id = (int)$this->request->get['filter_order_id'];
21: } else {
22: $filter_order_id = '';
23: }
24:
25: if (isset($this->request->get['filter_customer_id'])) {
26: $filter_customer_id = $this->request->get['filter_customer_id'];
27: } else {
28: $filter_customer_id = '';
29: }
30:
31: if (isset($this->request->get['filter_customer'])) {
32: $filter_customer = $this->request->get['filter_customer'];
33: } else {
34: $filter_customer = '';
35: }
36:
37: if (isset($this->request->get['filter_store_id'])) {
38: $filter_store_id = (int)$this->request->get['filter_store_id'];
39: } else {
40: $filter_store_id = '';
41: }
42:
43: if (isset($this->request->get['filter_order_status'])) {
44: $filter_order_status = $this->request->get['filter_order_status'];
45: } else {
46: $filter_order_status = '';
47: }
48:
49: if (isset($this->request->get['filter_order_status_id'])) {
50: $filter_order_status_id = (int)$this->request->get['filter_order_status_id'];
51: } else {
52: $filter_order_status_id = '';
53: }
54:
55: if (isset($this->request->get['filter_total'])) {
56: $filter_total = $this->request->get['filter_total'];
57: } else {
58: $filter_total = '';
59: }
60:
61: if (isset($this->request->get['filter_date_from'])) {
62: $filter_date_from = $this->request->get['filter_date_from'];
63: } else {
64: $filter_date_from = '';
65: }
66:
67: if (isset($this->request->get['filter_date_to'])) {
68: $filter_date_to = $this->request->get['filter_date_to'];
69: } else {
70: $filter_date_to = '';
71: }
72:
73: $url = '';
74:
75: if (isset($this->request->get['filter_order_id'])) {
76: $url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
77: }
78:
79: if (isset($this->request->get['filter_customer_id'])) {
80: $url .= '&filter_customer_id=' . (int)$this->request->get['filter_customer_id'];
81: }
82:
83: if (isset($this->request->get['filter_customer'])) {
84: $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
85: }
86:
87: if (isset($this->request->get['filter_store_id'])) {
88: $url .= '&filter_store_id=' . (int)$this->request->get['filter_store_id'];
89: }
90:
91: if (isset($this->request->get['filter_order_status'])) {
92: $url .= '&filter_order_status=' . $this->request->get['filter_order_status'];
93: }
94:
95: if (isset($this->request->get['filter_order_status_id'])) {
96: $url .= '&filter_order_status_id=' . (int)$this->request->get['filter_order_status_id'];
97: }
98:
99: if (isset($this->request->get['filter_total'])) {
100: $url .= '&filter_total=' . $this->request->get['filter_total'];
101: }
102:
103: if (isset($this->request->get['filter_date_from'])) {
104: $url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
105: }
106:
107: if (isset($this->request->get['filter_date_to'])) {
108: $url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
109: }
110:
111: if (isset($this->request->get['sort'])) {
112: $url .= '&sort=' . $this->request->get['sort'];
113: }
114:
115: if (isset($this->request->get['order'])) {
116: $url .= '&order=' . $this->request->get['order'];
117: }
118:
119: if (isset($this->request->get['page'])) {
120: $url .= '&page=' . $this->request->get['page'];
121: }
122:
123: $data['breadcrumbs'] = [];
124:
125: $data['breadcrumbs'][] = [
126: 'text' => $this->language->get('text_home'),
127: 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
128: ];
129:
130: $data['breadcrumbs'][] = [
131: 'text' => $this->language->get('heading_title'),
132: 'href' => $this->url->link('sale/order', 'user_token=' . $this->session->data['user_token'] . $url)
133: ];
134:
135: $data['add'] = $this->url->link('sale/order.info', 'user_token=' . $this->session->data['user_token'] . $url);
136: $data['delete'] = $this->url->link('sale/order.delete', 'user_token=' . $this->session->data['user_token'] . $url);
137: $data['invoice'] = $this->url->link('sale/order.invoice', 'user_token=' . $this->session->data['user_token']);
138: $data['shipping'] = $this->url->link('sale/order.shipping', 'user_token=' . $this->session->data['user_token']);
139:
140: $data['list'] = $this->getList();
141:
142: $data['stores'] = [];
143:
144: $data['stores'][] = [
145: 'store_id' => 0,
146: 'name' => $this->language->get('text_default')
147: ];
148:
149: $this->load->model('setting/store');
150:
151: $stores = $this->model_setting_store->getStores();
152:
153: foreach ($stores as $store) {
154: $data['stores'][] = [
155: 'store_id' => $store['store_id'],
156: 'name' => $store['name']
157: ];
158: }
159:
160: $this->load->model('localisation/order_status');
161:
162: $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
163:
164: $data['filter_order_id'] = $filter_order_id;
165: $data['filter_customer_id'] = $filter_customer_id;
166: $data['filter_customer'] = $filter_customer;
167: $data['filter_store_id'] = $filter_store_id;
168: $data['filter_order_status'] = $filter_order_status;
169: $data['filter_order_status_id'] = $filter_order_status_id;
170: $data['filter_total'] = $filter_total;
171: $data['filter_date_from'] = $filter_date_from;
172: $data['filter_date_to'] = $filter_date_to;
173:
174: $data['user_token'] = $this->session->data['user_token'];
175:
176: $data['header'] = $this->load->controller('common/header');
177: $data['column_left'] = $this->load->controller('common/column_left');
178: $data['footer'] = $this->load->controller('common/footer');
179:
180: $this->response->setOutput($this->load->view('sale/order', $data));
181: }
182:
183: /**
184: * List
185: *
186: * @return void
187: */
188: public function list(): void {
189: $this->load->language('sale/order');
190:
191: $this->response->setOutput($this->getList());
192: }
193:
194: /**
195: * Get List
196: *
197: * @return string
198: */
199: protected function getList(): string {
200: if (isset($this->request->get['filter_order_id'])) {
201: $filter_order_id = (int)$this->request->get['filter_order_id'];
202: } else {
203: $filter_order_id = '';
204: }
205:
206: if (isset($this->request->get['filter_customer_id'])) {
207: $filter_customer_id = $this->request->get['filter_customer_id'];
208: } else {
209: $filter_customer_id = '';
210: }
211:
212: if (isset($this->request->get['filter_customer'])) {
213: $filter_customer = $this->request->get['filter_customer'];
214: } else {
215: $filter_customer = '';
216: }
217:
218: if (isset($this->request->get['filter_store_id'])) {
219: $filter_store_id = (int)$this->request->get['filter_store_id'];
220: } else {
221: $filter_store_id = '';
222: }
223:
224: if (isset($this->request->get['filter_order_status'])) {
225: $filter_order_status = $this->request->get['filter_order_status'];
226: } else {
227: $filter_order_status = '';
228: }
229:
230: if (isset($this->request->get['filter_order_status_id'])) {
231: $filter_order_status_id = (int)$this->request->get['filter_order_status_id'];
232: } else {
233: $filter_order_status_id = '';
234: }
235:
236: if (isset($this->request->get['filter_total'])) {
237: $filter_total = $this->request->get['filter_total'];
238: } else {
239: $filter_total = '';
240: }
241:
242: if (isset($this->request->get['filter_date_from'])) {
243: $filter_date_from = $this->request->get['filter_date_from'];
244: } else {
245: $filter_date_from = '';
246: }
247:
248: if (isset($this->request->get['filter_date_to'])) {
249: $filter_date_to = $this->request->get['filter_date_to'];
250: } else {
251: $filter_date_to = '';
252: }
253:
254: if (isset($this->request->get['sort'])) {
255: $sort = (string)$this->request->get['sort'];
256: } else {
257: $sort = 'o.order_id';
258: }
259:
260: if (isset($this->request->get['order'])) {
261: $order = (string)$this->request->get['order'];
262: } else {
263: $order = 'DESC';
264: }
265:
266: if (isset($this->request->get['page'])) {
267: $page = (int)$this->request->get['page'];
268: } else {
269: $page = 1;
270: }
271:
272: $url = '';
273:
274: if (isset($this->request->get['filter_order_id'])) {
275: $url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
276: }
277:
278: if (isset($this->request->get['filter_customer_id'])) {
279: $url .= '&filter_customer_id=' . (int)$this->request->get['filter_customer_id'];
280: }
281:
282: if (isset($this->request->get['filter_customer'])) {
283: $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
284: }
285:
286: if (isset($this->request->get['filter_store_id'])) {
287: $url .= '&filter_store_id=' . (int)$this->request->get['filter_store_id'];
288: }
289:
290: if (isset($this->request->get['filter_order_status'])) {
291: $url .= '&filter_order_status=' . $this->request->get['filter_order_status'];
292: }
293:
294: if (isset($this->request->get['filter_order_status_id'])) {
295: $url .= '&filter_order_status_id=' . (int)$this->request->get['filter_order_status_id'];
296: }
297:
298: if (isset($this->request->get['filter_total'])) {
299: $url .= '&filter_total=' . $this->request->get['filter_total'];
300: }
301:
302: if (isset($this->request->get['filter_date_from'])) {
303: $url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
304: }
305:
306: if (isset($this->request->get['filter_date_to'])) {
307: $url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
308: }
309:
310: if (isset($this->request->get['sort'])) {
311: $url .= '&sort=' . $this->request->get['sort'];
312: }
313:
314: if (isset($this->request->get['order'])) {
315: $url .= '&order=' . $this->request->get['order'];
316: }
317:
318: if (isset($this->request->get['page'])) {
319: $url .= '&page=' . $this->request->get['page'];
320: }
321:
322: $data['action'] = $this->url->link('sale/order.list', 'user_token=' . $this->session->data['user_token'] . $url);
323:
324: $data['orders'] = [];
325:
326: $filter_data = [
327: 'filter_order_id' => $filter_order_id,
328: 'filter_customer_id' => $filter_customer_id,
329: 'filter_customer' => $filter_customer,
330: 'filter_store_id' => $filter_store_id,
331: 'filter_order_status' => $filter_order_status,
332: 'filter_order_status_id' => $filter_order_status_id,
333: 'filter_total' => $filter_total,
334: 'filter_date_from' => $filter_date_from,
335: 'filter_date_to' => $filter_date_to,
336: 'sort' => $sort,
337: 'order' => $order,
338: 'start' => ($page - 1) * (int)$this->config->get('config_pagination_admin'),
339: 'limit' => (int)$this->config->get('config_pagination_admin')
340: ];
341:
342: $this->load->model('sale/order');
343:
344: $results = $this->model_sale_order->getOrders($filter_data);
345:
346: foreach ($results as $result) {
347: $data['orders'][] = [
348: 'order_id' => $result['order_id'],
349: 'store_name' => $result['store_name'],
350: 'customer' => $result['customer'],
351: 'order_status' => $result['order_status'] ? $result['order_status'] : $this->language->get('text_missing'),
352: 'total' => $this->currency->format($result['total'], $result['currency_code'], $result['currency_value']),
353: 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
354: 'date_modified' => date($this->language->get('date_format_short'), strtotime($result['date_modified'])),
355: 'shipping_method' => $result['shipping_method'],
356: 'view' => $this->url->link('sale/order.info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $result['order_id'] . $url)
357: ];
358: }
359:
360: $url = '';
361:
362: if (isset($this->request->get['filter_order_id'])) {
363: $url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
364: }
365:
366: if (isset($this->request->get['filter_customer_id'])) {
367: $url .= '&filter_customer_id=' . (int)$this->request->get['filter_customer_id'];
368: }
369:
370: if (isset($this->request->get['filter_customer'])) {
371: $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
372: }
373:
374: if (isset($this->request->get['filter_store_id'])) {
375: $url .= '&filter_store_id=' . (int)$this->request->get['filter_store_id'];
376: }
377:
378: if (isset($this->request->get['filter_order_status'])) {
379: $url .= '&filter_order_status=' . $this->request->get['filter_order_status'];
380: }
381:
382: if (isset($this->request->get['filter_order_status_id'])) {
383: $url .= '&filter_order_status_id=' . (int)$this->request->get['filter_order_status_id'];
384: }
385:
386: if (isset($this->request->get['filter_total'])) {
387: $url .= '&filter_total=' . $this->request->get['filter_total'];
388: }
389:
390: if (isset($this->request->get['filter_date_from'])) {
391: $url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
392: }
393:
394: if (isset($this->request->get['filter_date_to'])) {
395: $url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
396: }
397:
398: if ($order == 'ASC') {
399: $url .= '&order=DESC';
400: } else {
401: $url .= '&order=ASC';
402: }
403:
404: $data['sort_order'] = $this->url->link('sale/order.list', 'user_token=' . $this->session->data['user_token'] . '&sort=o.order_id' . $url);
405: $data['sort_store_name'] = $this->url->link('sale/order.list', 'user_token=' . $this->session->data['user_token'] . '&sort=o.store_name' . $url);
406: $data['sort_customer'] = $this->url->link('sale/order.list', 'user_token=' . $this->session->data['user_token'] . '&sort=customer' . $url);
407: $data['sort_status'] = $this->url->link('sale/order.list', 'user_token=' . $this->session->data['user_token'] . '&sort=order_status' . $url);
408: $data['sort_total'] = $this->url->link('sale/order.list', 'user_token=' . $this->session->data['user_token'] . '&sort=o.total' . $url);
409: $data['sort_date_added'] = $this->url->link('sale/order.list', 'user_token=' . $this->session->data['user_token'] . '&sort=o.date_added' . $url);
410: $data['sort_date_modified'] = $this->url->link('sale/order.list', 'user_token=' . $this->session->data['user_token'] . '&sort=o.date_modified' . $url);
411:
412: $url = '';
413:
414: if (isset($this->request->get['filter_order_id'])) {
415: $url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
416: }
417:
418: if (isset($this->request->get['filter_customer_id'])) {
419: $url .= '&filter_customer_id=' . (int)$this->request->get['filter_customer_id'];
420: }
421:
422: if (isset($this->request->get['filter_customer'])) {
423: $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
424: }
425:
426: if (isset($this->request->get['filter_store_id'])) {
427: $url .= '&filter_store_id=' . (int)$this->request->get['filter_store_id'];
428: }
429:
430: if (isset($this->request->get['filter_order_status'])) {
431: $url .= '&filter_order_status=' . $this->request->get['filter_order_status'];
432: }
433:
434: if (isset($this->request->get['filter_order_status_id'])) {
435: $url .= '&filter_order_status_id=' . (int)$this->request->get['filter_order_status_id'];
436: }
437:
438: if (isset($this->request->get['filter_total'])) {
439: $url .= '&filter_total=' . $this->request->get['filter_total'];
440: }
441:
442: if (isset($this->request->get['filter_date_from'])) {
443: $url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
444: }
445:
446: if (isset($this->request->get['filter_date_to'])) {
447: $url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
448: }
449:
450: if (isset($this->request->get['sort'])) {
451: $url .= '&sort=' . $this->request->get['sort'];
452: }
453:
454: if (isset($this->request->get['order'])) {
455: $url .= '&order=' . $this->request->get['order'];
456: }
457:
458: $order_total = $this->model_sale_order->getTotalOrders($filter_data);
459:
460: $data['pagination'] = $this->load->controller('common/pagination', [
461: 'total' => $order_total,
462: 'page' => $page,
463: 'limit' => $this->config->get('config_pagination_admin'),
464: 'url' => $this->url->link('sale/order.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
465: ]);
466:
467: $data['results'] = sprintf($this->language->get('text_pagination'), ($order_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($order_total - $this->config->get('config_pagination_admin'))) ? $order_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $order_total, ceil($order_total / $this->config->get('config_pagination_admin')));
468:
469: $data['sort'] = $sort;
470: $data['order'] = $order;
471:
472: return $this->load->view('sale/order_list', $data);
473: }
474:
475: /**
476: * Info
477: *
478: * @throws \Exception
479: *
480: * @return void
481: */
482: public function info(): void {
483: $this->load->language('sale/order');
484:
485: if (isset($this->request->get['order_id'])) {
486: $order_id = (int)$this->request->get['order_id'];
487: } else {
488: $order_id = 0;
489: }
490:
491: $this->document->setTitle($this->language->get('heading_title'));
492:
493: $data['text_form'] = !$order_id ? $this->language->get('text_add') : sprintf($this->language->get('text_edit'), $order_id);
494:
495: $data['error_upload_size'] = sprintf($this->language->get('error_upload_size'), $this->config->get('config_file_max_size'));
496:
497: $data['config_file_max_size'] = ((int)$this->config->get('config_file_max_size') * 1024 * 1024);
498: $data['config_telephone_required'] = $this->config->get('config_telephone_required');
499:
500: $url = '';
501:
502: if (isset($this->request->get['filter_order_id'])) {
503: $url .= '&filter_order_id=' . $this->request->get['filter_order_id'];
504: }
505:
506: if (isset($this->request->get['filter_customer_id'])) {
507: $url .= '&filter_customer_id=' . (int)$this->request->get['filter_customer_id'];
508: }
509:
510: if (isset($this->request->get['filter_customer'])) {
511: $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
512: }
513:
514: if (isset($this->request->get['filter_store_id'])) {
515: $url .= '&filter_store_id=' . (int)$this->request->get['filter_store_id'];
516: }
517:
518: if (isset($this->request->get['filter_order_status'])) {
519: $url .= '&filter_order_status=' . $this->request->get['filter_order_status'];
520: }
521:
522: if (isset($this->request->get['filter_order_status_id'])) {
523: $url .= '&filter_order_status_id=' . (int)$this->request->get['filter_order_status_id'];
524: }
525:
526: if (isset($this->request->get['filter_total'])) {
527: $url .= '&filter_total=' . $this->request->get['filter_total'];
528: }
529:
530: if (isset($this->request->get['filter_date_from'])) {
531: $url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
532: }
533:
534: if (isset($this->request->get['filter_date_to'])) {
535: $url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
536: }
537:
538: if (isset($this->request->get['sort'])) {
539: $url .= '&sort=' . $this->request->get['sort'];
540: }
541:
542: if (isset($this->request->get['order'])) {
543: $url .= '&order=' . $this->request->get['order'];
544: }
545:
546: if (isset($this->request->get['page'])) {
547: $url .= '&page=' . $this->request->get['page'];
548: }
549:
550: $data['breadcrumbs'] = [];
551:
552: $data['breadcrumbs'][] = [
553: 'text' => $this->language->get('text_home'),
554: 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
555: ];
556:
557: $data['breadcrumbs'][] = [
558: 'text' => $this->language->get('heading_title'),
559: 'href' => $this->url->link('sale/order', 'user_token=' . $this->session->data['user_token'] . $url)
560: ];
561:
562: $data['shipping'] = $this->url->link('sale/order.shipping', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $order_id);
563: $data['invoice'] = $this->url->link('sale/order.invoice', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $order_id);
564: $data['back'] = $this->url->link('sale/order', 'user_token=' . $this->session->data['user_token'] . $url);
565: $data['upload'] = $this->url->link('tool/upload.upload', 'user_token=' . $this->session->data['user_token']);
566: $data['customer_add'] = $this->url->link('customer/customer.form', 'user_token=' . $this->session->data['user_token']);
567:
568: if ($order_id) {
569: $this->load->model('sale/order');
570:
571: $order_info = $this->model_sale_order->getOrder($order_id);
572: }
573:
574: if (!empty($order_info)) {
575: $data['order_id'] = $order_info['order_id'];
576: } else {
577: $data['order_id'] = '';
578: }
579:
580: // Invoice
581: if (!empty($order_info)) {
582: $data['invoice_no'] = $order_info['invoice_no'];
583: } else {
584: $data['invoice_no'] = '';
585: }
586:
587: if (!empty($order_info)) {
588: $data['invoice_prefix'] = $order_info['invoice_prefix'];
589: } else {
590: $data['invoice_prefix'] = '';
591: }
592:
593: // Customer
594: if (!empty($order_info)) {
595: $data['customer_id'] = $order_info['customer_id'];
596: } else {
597: $data['customer_id'] = 0;
598: }
599:
600: $this->load->model('customer/customer_group');
601:
602: $data['customer_groups'] = $this->model_customer_customer_group->getCustomerGroups();
603:
604: if (!empty($order_info)) {
605: $data['customer_group_id'] = $order_info['customer_group_id'];
606: } else {
607: $data['customer_group_id'] = $this->config->get('config_customer_group_id');
608: }
609:
610: if (!empty($order_info)) {
611: $data['firstname'] = $order_info['firstname'];
612: } else {
613: $data['firstname'] = '';
614: }
615:
616: if (!empty($order_info)) {
617: $data['lastname'] = $order_info['lastname'];
618: } else {
619: $data['lastname'] = '';
620: }
621:
622: if (!empty($order_info)) {
623: $data['email'] = $order_info['email'];
624: } else {
625: $data['email'] = '';
626: }
627:
628: if (!empty($order_info)) {
629: $data['telephone'] = $order_info['telephone'];
630: } else {
631: $data['telephone'] = '';
632: }
633:
634: if (!empty($order_info)) {
635: $data['account_custom_field'] = $order_info['custom_field'];
636: } else {
637: $data['account_custom_field'] = [];
638: }
639:
640: // Custom Fields
641: $data['custom_fields'] = [];
642:
643: $filter_data = [
644: 'filter_status' => 1,
645: 'sort' => 'cf.sort_order',
646: 'order' => 'ASC'
647: ];
648:
649: $this->load->model('customer/custom_field');
650:
651: $custom_fields = $this->model_customer_custom_field->getCustomFields($filter_data);
652:
653: foreach ($custom_fields as $custom_field) {
654: $data['custom_fields'][] = [
655: 'custom_field_id' => $custom_field['custom_field_id'],
656: 'custom_field_value' => $this->model_customer_custom_field->getValues($custom_field['custom_field_id']),
657: 'name' => $custom_field['name'],
658: 'value' => $custom_field['value'],
659: 'type' => $custom_field['type'],
660: 'location' => $custom_field['location'],
661: 'sort_order' => $custom_field['sort_order']
662: ];
663: }
664:
665: // Products
666: $data['order_products'] = [];
667:
668: $this->load->model('sale/order');
669: $this->load->model('sale/subscription');
670: $this->load->model('tool/upload');
671:
672: $products = $this->model_sale_order->getProducts($order_id);
673:
674: if (!empty($order_info)) {
675: $data['currency_code'] = $order_info['currency_code'];
676: $currency_value = $order_info['currency_value'];
677: } else {
678: $data['currency_code'] = $this->config->get('config_currency');
679: $currency_value = 1;
680: }
681:
682: foreach ($products as $product) {
683: $option_data = [];
684:
685: $options = $this->model_sale_order->getOptions($order_id, $product['order_product_id']);
686:
687: foreach ($options as $option) {
688: if ($option['type'] != 'file') {
689: $option_data[] = [
690: 'name' => $option['name'],
691: 'value' => $option['value'],
692: 'type' => $option['type']
693: ];
694: } else {
695: $upload_info = $this->model_tool_upload->getUploadByCode($option['value']);
696:
697: if ($upload_info) {
698: $option_data[] = [
699: 'name' => $option['name'],
700: 'value' => $upload_info['name'],
701: 'type' => $option['type'],
702: 'href' => $this->url->link('tool/upload.download', 'user_token=' . $this->session->data['user_token'] . '&code=' . $upload_info['code'])
703: ];
704: }
705: }
706: }
707:
708: $description = '';
709:
710: $subscription_info = $this->model_sale_order->getSubscription($order_id, $product['order_product_id']);
711:
712: if ($subscription_info) {
713: if ($subscription_info['trial_status']) {
714: $trial_price = $this->currency->format($subscription_info['trial_price'], $this->config->get('config_currency'));
715: $trial_cycle = $subscription_info['trial_cycle'];
716: $trial_frequency = $this->language->get('text_' . $subscription_info['trial_frequency']);
717: $trial_duration = $subscription_info['trial_duration'];
718:
719: $description .= sprintf($this->language->get('text_subscription_trial'), $trial_price, $trial_cycle, $trial_frequency, $trial_duration);
720: }
721:
722: $price = $this->currency->format($subscription_info['price'], $this->config->get('config_currency'));
723: $cycle = $subscription_info['cycle'];
724: $frequency = $this->language->get('text_' . $subscription_info['frequency']);
725: $duration = $subscription_info['duration'];
726:
727: if ($subscription_info['duration']) {
728: $description .= sprintf($this->language->get('text_subscription_duration'), $price, $cycle, $frequency, $duration);
729: } else {
730: $description .= sprintf($this->language->get('text_subscription_cancel'), $price, $cycle, $frequency);
731: }
732: }
733:
734: $subscription_info = $this->model_sale_subscription->getSubscriptionByOrderProductId($order_id, $product['order_product_id']);
735:
736: if ($subscription_info) {
737: $subscription = $this->url->link('sale/subscription.info', 'user_token=' . $this->session->data['user_token'] . '&subscription_id=' . $subscription_info['subscription_id']);
738: } else {
739: $subscription = '';
740: }
741:
742: $data['order_products'][] = [
743: 'order_product_id' => $product['order_product_id'],
744: 'product_id' => $product['product_id'],
745: 'name' => $product['name'],
746: 'model' => $product['model'],
747: 'option' => $option_data,
748: 'subscription' => $subscription,
749: 'subscription_description' => $description,
750: 'quantity' => $product['quantity'],
751: 'price' => $this->currency->format($product['price'] + ($this->config->get('config_tax') ? $product['tax'] : 0), $data['currency_code'], $currency_value),
752: 'total' => $this->currency->format($product['total'] + ($this->config->get('config_tax') ? ($product['tax'] * $product['quantity']) : 0), $data['currency_code'], $currency_value),
753: 'reward' => $product['reward']
754: ];
755: }
756:
757: // Vouchers
758: $data['order_vouchers'] = [];
759:
760: $vouchers = $this->model_sale_order->getVouchers($order_id);
761:
762: foreach ($vouchers as $voucher) {
763: $data['order_vouchers'][] = [
764: 'description' => $voucher['description'],
765: 'amount' => $this->currency->format($voucher['amount'], $data['currency_code'], $currency_value),
766: 'href' => $this->url->link('sale/voucher.form', 'user_token=' . $this->session->data['user_token'] . '&voucher_id=' . $voucher['voucher_id'])
767: ];
768: }
769:
770: // Totals
771: $data['order_totals'] = [];
772:
773: $totals = $this->model_sale_order->getTotals($order_id);
774:
775: foreach ($totals as $total) {
776: $data['order_totals'][] = [
777: 'title' => $total['title'],
778: 'text' => $this->currency->format($total['value'], $data['currency_code'], $currency_value)
779: ];
780: }
781:
782: // Delete any old session
783: if (isset($this->session->data['api_session'])) {
784: $session = new \Opencart\System\Library\Session($this->config->get('session_engine'), $this->registry);
785: $session->start($this->session->data['api_session']);
786: $session->destroy();
787: }
788:
789: if (!empty($order_info)) {
790: $store_id = $order_info['store_id'];
791: } else {
792: $store_id = 0;
793: }
794:
795: if (!empty($order_info)) {
796: $language = $order_info['language_code'];
797: } else {
798: $language = $this->config->get('config_language');
799: }
800:
801: // Create a store instance using loader class to call controllers, models, views, libraries
802: $this->load->model('setting/store');
803:
804: $store = $this->model_setting_store->createStoreInstance($store_id, $language);
805:
806: // 2. Store the new session ID so we're not creating new session on every page load
807: $this->session->data['api_session'] = $store->session->getId();
808:
809: // 3. To use the order API it requires an API ID.
810: $store->session->data['api_id'] = (int)$this->config->get('config_api_id');
811:
812: if (!empty($order_info)) {
813: // 4. Add the request vars and remove the unneeded ones
814: $store->request->get = $this->request->get;
815: $store->request->post = $this->request->post;
816:
817: // 5. Load the order data
818: $store->request->get['route'] = 'api/sale/order.load';
819: $store->request->get['language'] = $language;
820:
821: unset($store->request->get['user_token']);
822: unset($store->request->get['action']);
823:
824: $store->load->controller($store->request->get['route']);
825: }
826:
827: // Store
828: $data['stores'] = [];
829:
830: $data['stores'][] = [
831: 'store_id' => 0,
832: 'name' => $this->config->get('config_name')
833: ];
834:
835: $this->load->model('setting/store');
836:
837: $results = $this->model_setting_store->getStores();
838:
839: foreach ($results as $result) {
840: $data['stores'][] = [
841: 'store_id' => $result['store_id'],
842: 'name' => $result['name']
843: ];
844: }
845:
846: if (!empty($order_info)) {
847: $data['store_id'] = $order_info['store_id'];
848: } else {
849: $data['store_id'] = $this->config->get('config_store_id');
850: }
851:
852: // Language
853: $this->load->model('localisation/language');
854:
855: $data['languages'] = $this->model_localisation_language->getLanguages();
856:
857: if (!empty($order_info)) {
858: $data['language_code'] = $order_info['language_code'];
859: } else {
860: $data['language_code'] = $this->config->get('config_language');
861: }
862:
863: // Voucher themes
864: $this->load->model('sale/voucher_theme');
865:
866: $data['voucher_themes'] = $this->model_sale_voucher_theme->getVoucherThemes();
867:
868: // Currency
869: $this->load->model('localisation/currency');
870:
871: $data['currencies'] = $this->model_localisation_currency->getCurrencies();
872:
873: // Coupon, Voucher, Reward
874: $data['total_coupon'] = '';
875: $data['total_voucher'] = '';
876: $data['total_reward'] = 0;
877:
878: if ($order_id) {
879: $order_totals = $this->model_sale_order->getTotals($order_id);
880:
881: foreach ($order_totals as $order_total) {
882: // If coupon, voucher or reward points
883: $start = strpos($order_total['title'], '(');
884: $end = strrpos($order_total['title'], ')');
885:
886: if ($start !== false && $end !== false) {
887: $data['total_' . $order_total['code']] = substr($order_total['title'], $start + 1, $end - ($start + 1));
888: }
889: }
890: }
891:
892: // Reward Points
893: if (!empty($order_info)) {
894: $data['points'] = $this->model_sale_order->getRewardTotal($order_id);
895: } else {
896: $data['points'] = 0;
897: }
898:
899: // Reward Points
900: if (!empty($order_info)) {
901: $data['reward_total'] = $this->model_customer_customer->getTotalRewardsByOrderId($order_id);
902: } else {
903: $data['reward_total'] = 0;
904: }
905:
906: // Affiliate
907: if (!empty($order_info)) {
908: $data['affiliate_id'] = $order_info['affiliate_id'];
909: } else {
910: $data['affiliate_id'] = 0;
911: }
912:
913: if (!empty($order_info)) {
914: $data['affiliate'] = $order_info['affiliate'];
915: } else {
916: $data['affiliate'] = '';
917: }
918:
919: // Commission
920: if (!empty($order_info) && (float)$order_info['commission']) {
921: $data['commission'] = $this->currency->format($order_info['commission'], $this->config->get('config_currency'));
922: } else {
923: $data['commission'] = '';
924: }
925:
926: if (!empty($order_info)) {
927: $data['commission_total'] = $this->model_customer_customer->getTotalTransactionsByOrderId($order_id);
928: } else {
929: $data['commission_total'] = '';
930: }
931:
932: // Addresses
933: if (!empty($order_info)) {
934: $this->load->model('customer/customer');
935:
936: $data['addresses'] = $this->model_customer_customer->getAddresses($order_info['customer_id']);
937: } else {
938: $data['addresses'] = [];
939: }
940:
941: // Payment Address
942: if (!empty($order_info)) {
943: $data['payment_address_id'] = $order_info['payment_address_id'];
944: } else {
945: $data['payment_address_id'] = 0;
946: }
947:
948: if (!empty($order_info)) {
949: $data['payment_firstname'] = $order_info['payment_firstname'];
950: } else {
951: $data['payment_firstname'] = '';
952: }
953:
954: if (!empty($order_info)) {
955: $data['payment_lastname'] = $order_info['payment_lastname'];
956: } else {
957: $data['payment_lastname'] = '';
958: }
959:
960: if (!empty($order_info)) {
961: $data['payment_company'] = $order_info['payment_company'];
962: } else {
963: $data['payment_company'] = '';
964: }
965:
966: if (!empty($order_info)) {
967: $data['payment_address_1'] = $order_info['payment_address_1'];
968: } else {
969: $data['payment_address_1'] = '';
970: }
971:
972: if (!empty($order_info)) {
973: $data['payment_address_2'] = $order_info['payment_address_2'];
974: } else {
975: $data['payment_address_2'] = '';
976: }
977:
978: if (!empty($order_info)) {
979: $data['payment_city'] = $order_info['payment_city'];
980: } else {
981: $data['payment_city'] = '';
982: }
983:
984: if (!empty($order_info)) {
985: $data['payment_postcode'] = $order_info['payment_postcode'];
986: } else {
987: $data['payment_postcode'] = '';
988: }
989:
990: // Countries
991: $this->load->model('localisation/country');
992:
993: $data['countries'] = $this->model_localisation_country->getCountries();
994:
995: if (!empty($order_info)) {
996: $data['payment_country_id'] = $order_info['payment_country_id'];
997: } else {
998: $data['payment_country_id'] = 0;
999: }
1000:
1001: if (!empty($order_info)) {
1002: $data['payment_country'] = $order_info['payment_country'];
1003: } else {
1004: $data['payment_country'] = '';
1005: }
1006:
1007: if (!empty($order_info)) {
1008: $data['payment_zone_id'] = $order_info['payment_zone_id'];
1009: } else {
1010: $data['payment_zone_id'] = 0;
1011: }
1012:
1013: if (!empty($order_info)) {
1014: $data['payment_zone'] = $order_info['payment_zone'];
1015: } else {
1016: $data['payment_zone'] = '';
1017: }
1018:
1019: if (!empty($order_info)) {
1020: $data['payment_custom_field'] = $order_info['payment_custom_field'];
1021: } else {
1022: $data['payment_custom_field'] = [];
1023: }
1024:
1025: // Payment Method
1026: if (isset($order_info['payment_method']['name'])) {
1027: $data['payment_method'] = $order_info['payment_method']['name'];
1028: } else {
1029: $data['payment_method'] = '';
1030: }
1031:
1032: if (isset($order_info['payment_method']['code'])) {
1033: $data['payment_code'] = $order_info['payment_method']['code'];
1034: } else {
1035: $data['payment_code'] = '';
1036: }
1037:
1038: // Shipping Address
1039: if (!empty($order_info)) {
1040: $data['shipping_address_id'] = $order_info['shipping_address_id'];
1041: } else {
1042: $data['shipping_address_id'] = 0;
1043: }
1044:
1045: if (!empty($order_info)) {
1046: $data['shipping_firstname'] = $order_info['shipping_firstname'];
1047: } else {
1048: $data['shipping_firstname'] = '';
1049: }
1050:
1051: if (!empty($order_info)) {
1052: $data['shipping_lastname'] = $order_info['shipping_lastname'];
1053: } else {
1054: $data['shipping_lastname'] = '';
1055: }
1056:
1057: if (!empty($order_info)) {
1058: $data['shipping_company'] = $order_info['shipping_company'];
1059: } else {
1060: $data['shipping_company'] = '';
1061: }
1062:
1063: if (!empty($order_info)) {
1064: $data['shipping_address_1'] = $order_info['shipping_address_1'];
1065: } else {
1066: $data['shipping_address_1'] = '';
1067: }
1068:
1069: if (!empty($order_info)) {
1070: $data['shipping_address_2'] = $order_info['shipping_address_2'];
1071: } else {
1072: $data['shipping_address_2'] = '';
1073: }
1074:
1075: if (!empty($order_info)) {
1076: $data['shipping_city'] = $order_info['shipping_city'];
1077: } else {
1078: $data['shipping_city'] = '';
1079: }
1080:
1081: if (!empty($order_info)) {
1082: $data['shipping_postcode'] = $order_info['shipping_postcode'];
1083: } else {
1084: $data['shipping_postcode'] = '';
1085: }
1086:
1087: if (!empty($order_info)) {
1088: $data['shipping_country_id'] = $order_info['shipping_country_id'];
1089: } else {
1090: $data['shipping_country_id'] = 0;
1091: }
1092:
1093: if (!empty($order_info)) {
1094: $data['shipping_country'] = $order_info['shipping_country'];
1095: } else {
1096: $data['shipping_country'] = '';
1097: }
1098:
1099: if (!empty($order_info)) {
1100: $data['shipping_zone_id'] = $order_info['shipping_zone_id'];
1101: } else {
1102: $data['shipping_zone_id'] = 0;
1103: }
1104:
1105: if (!empty($order_info)) {
1106: $data['shipping_zone'] = $order_info['shipping_zone'];
1107: } else {
1108: $data['shipping_zone'] = '';
1109: }
1110:
1111: if (!empty($order_info)) {
1112: $data['shipping_custom_field'] = $order_info['shipping_custom_field'];
1113: } else {
1114: $data['shipping_custom_field'] = [];
1115: }
1116:
1117: // Shipping method
1118: if (isset($order_info['shipping_method']['name'])) {
1119: $data['shipping_method'] = $order_info['shipping_method']['name'];
1120: } else {
1121: $data['shipping_method'] = '';
1122: }
1123:
1124: if (isset($order_info['shipping_method']['code'])) {
1125: $data['shipping_code'] = $order_info['shipping_method']['code'];
1126: } else {
1127: $data['shipping_code'] = '';
1128: }
1129:
1130: // Comment
1131: if (!empty($order_info)) {
1132: $data['comment'] = nl2br($order_info['comment']);
1133: } else {
1134: $data['comment'] = '';
1135: }
1136:
1137: // Totals
1138: $data['order_totals'] = [];
1139:
1140: if (!empty($order_info)) {
1141: $totals = $this->model_sale_order->getTotals($order_id);
1142:
1143: foreach ($totals as $total) {
1144: $data['order_totals'][] = [
1145: 'title' => $total['title'],
1146: 'text' => $this->currency->format($total['value'], $order_info['currency_code'], $order_info['currency_value'])
1147: ];
1148: }
1149: }
1150:
1151: // Order Status
1152: $this->load->model('localisation/order_status');
1153:
1154: $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
1155:
1156: if (!empty($order_info)) {
1157: $data['order_status_id'] = $order_info['order_status_id'];
1158: } else {
1159: $data['order_status_id'] = $this->config->get('config_order_status_id');
1160: }
1161:
1162: // Additional tabs that are payment gateway specific
1163: $data['tabs'] = [];
1164:
1165: // Extension Order Tabs can be called here.
1166: $this->load->model('setting/extension');
1167:
1168: if (!empty($order_info['payment_method']['code'])) {
1169: if (isset($order_info['payment_method']['code'])) {
1170: $code = oc_substr($order_info['payment_method']['code'], 0, strpos($order_info['payment_method']['code'], '.'));
1171: } else {
1172: $code = '';
1173: }
1174:
1175: $extension_info = $this->model_setting_extension->getExtensionByCode('payment', $code);
1176:
1177: if ($extension_info && $this->user->hasPermission('access', 'extension/' . $extension_info['extension'] . '/payment/' . $extension_info['code'])) {
1178: $output = $this->load->controller('extension/' . $extension_info['extension'] . '/payment/' . $extension_info['code'] . '.order');
1179:
1180: if (!$output instanceof \Exception) {
1181: $this->load->language('extension/' . $extension_info['extension'] . '/payment/' . $extension_info['code'], 'extension');
1182:
1183: $data['tabs'][] = [
1184: 'code' => $extension_info['code'],
1185: 'title' => $this->language->get('extension_heading_title'),
1186: 'content' => $output
1187: ];
1188: }
1189: }
1190: }
1191:
1192: // Extension Order Tabs can be called here.
1193: $this->load->model('setting/extension');
1194:
1195: $extensions = $this->model_setting_extension->getExtensionsByType('fraud');
1196:
1197: foreach ($extensions as $extension) {
1198: if ($this->config->get('fraud_' . $extension['code'] . '_status')) {
1199: $this->load->language('extension/' . $extension['extension'] . '/fraud/' . $extension['code'], 'extension');
1200:
1201: $output = $this->load->controller('extension/' . $extension['extension'] . '/fraud/' . $extension['code'] . '.order');
1202:
1203: if (!$output instanceof \Exception) {
1204: $data['tabs'][] = [
1205: 'code' => $extension['extension'],
1206: 'title' => $this->language->get('extension_heading_title'),
1207: 'content' => $output
1208: ];
1209: }
1210: }
1211: }
1212:
1213: // Additional information
1214: if (!empty($order_info)) {
1215: $data['ip'] = $order_info['ip'];
1216: $data['forwarded_ip'] = $order_info['forwarded_ip'];
1217: $data['user_agent'] = $order_info['user_agent'];
1218: $data['accept_language'] = $order_info['accept_language'];
1219: $data['date_added'] = date($this->language->get('date_format_short'), strtotime($order_info['date_added']));
1220: $data['date_modified'] = date($this->language->get('date_format_short'), strtotime($order_info['date_modified']));
1221: } else {
1222: $data['ip'] = '';
1223: $data['forwarded_ip'] = '';
1224: $data['user_agent'] = '';
1225: $data['accept_language'] = '';
1226: $data['date_added'] = date($this->language->get('date_format_short'), time());
1227: $data['date_modified'] = date($this->language->get('date_format_short'), time());
1228: }
1229:
1230: // Histories
1231: $data['history'] = $this->getHistory();
1232:
1233: $data['user_token'] = $this->session->data['user_token'];
1234:
1235: $data['header'] = $this->load->controller('common/header');
1236: $data['column_left'] = $this->load->controller('common/column_left');
1237: $data['footer'] = $this->load->controller('common/footer');
1238:
1239: $this->response->setOutput($this->load->view('sale/order_info', $data));
1240: }
1241:
1242: // Method to call the store front API and return a response.
1243:
1244: /**
1245: * Call
1246: *
1247: * @return void
1248: */
1249: public function call(): void {
1250: $this->load->language('sale/order');
1251:
1252: $json = [];
1253:
1254: if (isset($this->request->get['store_id'])) {
1255: $store_id = (int)$this->request->get['store_id'];
1256: } else {
1257: $store_id = 0;
1258: }
1259:
1260: if (isset($this->request->get['language'])) {
1261: $language = $this->request->get['language'];
1262: } else {
1263: $language = $this->config->get('config_language');
1264: }
1265:
1266: if (isset($this->request->get['action'])) {
1267: $action = $this->request->get['action'];
1268: } else {
1269: $action = '';
1270: }
1271:
1272: if (isset($this->session->data['api_session'])) {
1273: $session_id = $this->session->data['api_session'];
1274: } else {
1275: $session_id = '';
1276: }
1277:
1278: if (!$this->user->hasPermission('modify', 'sale/order')) {
1279: $json['error']['warning'] = $this->language->get('error_permission');
1280: }
1281:
1282: if (!$json) {
1283: // 1. Create a store instance using loader class to call controllers, models, views, libraries
1284: $this->load->model('setting/store');
1285:
1286: $store = $this->model_setting_store->createStoreInstance($store_id, $language, $session_id);
1287:
1288: // 2. Add the request vars and remove the unneeded ones
1289: $store->request->get = $this->request->get;
1290: $store->request->post = $this->request->post;
1291:
1292: $store->request->get['route'] = 'api/' . $action;
1293:
1294: // 3. Remove the unneeded keys
1295: unset($store->request->get['action']);
1296: unset($store->request->get['user_token']);
1297:
1298: // Call the required API controller
1299: $store->load->controller($store->request->get['route']);
1300:
1301: $output = $store->response->getOutput();
1302: } else {
1303: $output = json_encode($json);
1304: }
1305:
1306: $this->response->addHeader('Content-Type: application/json');
1307: $this->response->setOutput($output);
1308: }
1309:
1310: /**
1311: * Invoice
1312: *
1313: * @return void
1314: */
1315: public function invoice(): void {
1316: $this->load->language('sale/order');
1317:
1318: $data['title'] = $this->language->get('text_invoice');
1319:
1320: $data['base'] = HTTP_SERVER;
1321: $data['direction'] = $this->language->get('direction');
1322: $data['lang'] = $this->language->get('code');
1323:
1324: // Hard coding css so they can be replaced via the events system.
1325: $data['bootstrap_css'] = 'view/stylesheet/bootstrap.css';
1326: $data['icons'] = 'view/stylesheet/fonts/fontawesome/css/all.min.css';
1327: $data['stylesheet'] = 'view/stylesheet/stylesheet.css';
1328:
1329: // Hard coding scripts so they can be replaced via the events system.
1330: $data['jquery'] = 'view/javascript/jquery/jquery-3.7.1.min.js';
1331: $data['bootstrap_js'] = 'view/javascript/bootstrap/js/bootstrap.bundle.min.js';
1332:
1333: $this->load->model('sale/order');
1334: $this->load->model('sale/subscription');
1335: $this->load->model('setting/setting');
1336: $this->load->model('tool/upload');
1337:
1338: $data['orders'] = [];
1339:
1340: $orders = [];
1341:
1342: if (isset($this->request->post['selected'])) {
1343: $orders = $this->request->post['selected'];
1344: }
1345:
1346: if (isset($this->request->get['order_id'])) {
1347: $orders[] = (int)$this->request->get['order_id'];
1348: }
1349:
1350: foreach ($orders as $order_id) {
1351: $order_info = $this->model_sale_order->getOrder($order_id);
1352:
1353: if ($order_info) {
1354: $store_info = $this->model_setting_setting->getSetting('config', $order_info['store_id']);
1355:
1356: if ($store_info) {
1357: $store_address = $store_info['config_address'];
1358: $store_email = $store_info['config_email'];
1359: $store_telephone = $store_info['config_telephone'];
1360: } else {
1361: $store_address = $this->config->get('config_address');
1362: $store_email = $this->config->get('config_email');
1363: $store_telephone = $this->config->get('config_telephone');
1364: }
1365:
1366: if ($order_info['invoice_no']) {
1367: $invoice_no = $order_info['invoice_prefix'] . $order_info['invoice_no'];
1368: } else {
1369: $invoice_no = '';
1370: }
1371:
1372: // Payment Address
1373: if ($order_info['payment_address_format']) {
1374: $format = $order_info['payment_address_format'];
1375: } else {
1376: $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
1377: }
1378:
1379: $find = [
1380: '{firstname}',
1381: '{lastname}',
1382: '{company}',
1383: '{address_1}',
1384: '{address_2}',
1385: '{city}',
1386: '{postcode}',
1387: '{zone}',
1388: '{zone_code}',
1389: '{country}'
1390: ];
1391:
1392: $replace = [
1393: 'firstname' => $order_info['payment_firstname'],
1394: 'lastname' => $order_info['payment_lastname'],
1395: 'company' => $order_info['payment_company'],
1396: 'address_1' => $order_info['payment_address_1'],
1397: 'address_2' => $order_info['payment_address_2'],
1398: 'city' => $order_info['payment_city'],
1399: 'postcode' => $order_info['payment_postcode'],
1400: 'zone' => $order_info['payment_zone'],
1401: 'zone_code' => $order_info['payment_zone_code'],
1402: 'country' => $order_info['payment_country']
1403: ];
1404:
1405: $pattern_1 = [
1406: "\r\n",
1407: "\r",
1408: "\n"
1409: ];
1410:
1411: $pattern_2 = [
1412: "/\\s\\s+/",
1413: "/\r\r+/",
1414: "/\n\n+/"
1415: ];
1416:
1417: $payment_address = str_replace($pattern_1, '<br/>', preg_replace($pattern_2, '<br/>', trim(str_replace($find, $replace, $format))));
1418:
1419: // Shipping Address
1420: if ($order_info['shipping_address_format']) {
1421: $format = $order_info['shipping_address_format'];
1422: } else {
1423: $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
1424: }
1425:
1426: $find = [
1427: '{firstname}',
1428: '{lastname}',
1429: '{company}',
1430: '{address_1}',
1431: '{address_2}',
1432: '{city}',
1433: '{postcode}',
1434: '{zone}',
1435: '{zone_code}',
1436: '{country}'
1437: ];
1438:
1439: $replace = [
1440: 'firstname' => $order_info['shipping_firstname'],
1441: 'lastname' => $order_info['shipping_lastname'],
1442: 'company' => $order_info['shipping_company'],
1443: 'address_1' => $order_info['shipping_address_1'],
1444: 'address_2' => $order_info['shipping_address_2'],
1445: 'city' => $order_info['shipping_city'],
1446: 'postcode' => $order_info['shipping_postcode'],
1447: 'zone' => $order_info['shipping_zone'],
1448: 'zone_code' => $order_info['shipping_zone_code'],
1449: 'country' => $order_info['shipping_country']
1450: ];
1451:
1452: $shipping_address = str_replace($pattern_1, '<br/>', preg_replace($pattern_2, '<br/>', trim(str_replace($find, $replace, $format))));
1453:
1454: $product_data = [];
1455:
1456: $products = $this->model_sale_order->getProducts($order_id);
1457:
1458: foreach ($products as $product) {
1459: $option_data = [];
1460:
1461: $options = $this->model_sale_order->getOptions($order_id, $product['order_product_id']);
1462:
1463: foreach ($options as $option) {
1464: if ($option['type'] != 'file') {
1465: $value = $option['value'];
1466: } else {
1467: $upload_info = $this->model_tool_upload->getUploadByCode($option['value']);
1468:
1469: if ($upload_info) {
1470: $value = $upload_info['name'];
1471: } else {
1472: $value = '';
1473: }
1474: }
1475:
1476: $option_data[] = [
1477: 'name' => $option['name'],
1478: 'value' => $value
1479: ];
1480: }
1481:
1482: // Subscription
1483: $description = '';
1484:
1485: $subscription_info = $this->model_sale_order->getSubscription($order_id, $product['order_product_id']);
1486:
1487: if ($subscription_info) {
1488: if ($subscription_info['trial_status']) {
1489: $trial_price = $this->currency->format($subscription_info['trial_price'], $this->config->get('config_currency'));
1490: $trial_cycle = $subscription_info['trial_cycle'];
1491: $trial_frequency = $this->language->get('text_' . $subscription_info['trial_frequency']);
1492: $trial_duration = $subscription_info['trial_duration'];
1493:
1494: $description .= sprintf($this->language->get('text_subscription_trial'), $trial_price, $trial_cycle, $trial_frequency, $trial_duration);
1495: }
1496:
1497: $price = $this->currency->format($subscription_info['price'], $this->config->get('config_currency'));
1498: $cycle = $subscription_info['cycle'];
1499: $frequency = $this->language->get('text_' . $subscription_info['frequency']);
1500: $duration = $subscription_info['duration'];
1501:
1502: if ($subscription_info['duration']) {
1503: $description .= sprintf($this->language->get('text_subscription_duration'), $price, $cycle, $frequency, $duration);
1504: } else {
1505: $description .= sprintf($this->language->get('text_subscription_cancel'), $price, $cycle, $frequency);
1506: }
1507: }
1508:
1509: $product_data[] = [
1510: 'name' => $product['name'],
1511: 'model' => $product['model'],
1512: 'option' => $option_data,
1513: 'subscription' => $description,
1514: 'quantity' => $product['quantity'],
1515: 'price' => $this->currency->format($product['price'] + ($this->config->get('config_tax') ? $product['tax'] : 0), $order_info['currency_code'], $order_info['currency_value']),
1516: 'total' => $this->currency->format($product['total'] + ($this->config->get('config_tax') ? ($product['tax'] * $product['quantity']) : 0), $order_info['currency_code'], $order_info['currency_value'])
1517: ];
1518: }
1519:
1520: $voucher_data = [];
1521:
1522: $vouchers = $this->model_sale_order->getVouchers($order_id);
1523:
1524: foreach ($vouchers as $voucher) {
1525: $voucher_data[] = [
1526: 'description' => $voucher['description'],
1527: 'amount' => $this->currency->format($voucher['amount'], $order_info['currency_code'], $order_info['currency_value'])
1528: ];
1529: }
1530:
1531: $total_data = [];
1532:
1533: $totals = $this->model_sale_order->getTotals($order_id);
1534:
1535: foreach ($totals as $total) {
1536: $total_data[] = [
1537: 'title' => $total['title'],
1538: 'text' => $this->currency->format($total['value'], $order_info['currency_code'], $order_info['currency_value'])
1539: ];
1540: }
1541:
1542: $data['orders'][] = [
1543: 'order_id' => $order_id,
1544: 'invoice_no' => $invoice_no,
1545: 'date_added' => date($this->language->get('date_format_short'), strtotime($order_info['date_added'])),
1546: 'store_name' => $order_info['store_name'],
1547: 'store_url' => rtrim($order_info['store_url'], '/'),
1548: 'store_address' => nl2br($store_address),
1549: 'store_email' => $store_email,
1550: 'store_telephone' => $store_telephone,
1551: 'email' => $order_info['email'],
1552: 'telephone' => $order_info['telephone'],
1553: 'shipping_address' => $shipping_address,
1554: 'shipping_method' => ($order_info['shipping_method'] ? $order_info['shipping_method']['name'] : ''),
1555: 'payment_address' => $payment_address,
1556: 'payment_method' => $order_info['payment_method']['name'],
1557: 'product' => $product_data,
1558: 'voucher' => $voucher_data,
1559: 'total' => $total_data,
1560: 'comment' => nl2br($order_info['comment'])
1561: ];
1562: }
1563: }
1564:
1565: $this->response->setOutput($this->load->view('sale/order_invoice', $data));
1566: }
1567:
1568: /**
1569: * Shipping
1570: *
1571: * @return void
1572: */
1573: public function shipping(): void {
1574: $this->load->language('sale/order');
1575:
1576: $data['title'] = $this->language->get('text_shipping');
1577:
1578: $data['base'] = HTTP_SERVER;
1579: $data['direction'] = $this->language->get('direction');
1580: $data['lang'] = $this->language->get('code');
1581:
1582: // Hard coding CSS so they can be replaced via the events system.
1583: $data['bootstrap_css'] = 'view/stylesheet/bootstrap.css';
1584: $data['icons'] = 'view/stylesheet/fonts/fontawesome/css/all.min.css';
1585: $data['stylesheet'] = 'view/stylesheet/stylesheet.css';
1586:
1587: // Hard coding scripts so they can be replaced via the events system.
1588: $data['jquery'] = 'view/javascript/jquery/jquery-3.7.1.min.js';
1589: $data['bootstrap_js'] = 'view/javascript/bootstrap/js/bootstrap.bundle.min.js';
1590:
1591: $this->load->model('sale/order');
1592: $this->load->model('catalog/product');
1593: $this->load->model('setting/setting');
1594: $this->load->model('tool/upload');
1595: $this->load->model('sale/subscription');
1596:
1597: $data['orders'] = [];
1598:
1599: $orders = [];
1600:
1601: if (isset($this->request->post['selected'])) {
1602: $orders = $this->request->post['selected'];
1603: }
1604:
1605: if (isset($this->request->get['order_id'])) {
1606: $orders[] = (int)$this->request->get['order_id'];
1607: }
1608:
1609: foreach ($orders as $order_id) {
1610: $order_info = $this->model_sale_order->getOrder($order_id);
1611:
1612: // Make sure there is a shipping method
1613: if ($order_info && $order_info['shipping_method']) {
1614: $store_info = $this->model_setting_setting->getSetting('config', $order_info['store_id']);
1615:
1616: if ($store_info) {
1617: $store_address = $store_info['config_address'];
1618: $store_email = $store_info['config_email'];
1619: $store_telephone = $store_info['config_telephone'];
1620: } else {
1621: $store_address = $this->config->get('config_address');
1622: $store_email = $this->config->get('config_email');
1623: $store_telephone = $this->config->get('config_telephone');
1624: }
1625:
1626: if ($order_info['invoice_no']) {
1627: $invoice_no = $order_info['invoice_prefix'] . $order_info['invoice_no'];
1628: } else {
1629: $invoice_no = '';
1630: }
1631:
1632: // Shipping Address
1633: if ($order_info['shipping_address_format']) {
1634: $format = $order_info['shipping_address_format'];
1635: } else {
1636: $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
1637: }
1638:
1639: $find = [
1640: '{firstname}',
1641: '{lastname}',
1642: '{company}',
1643: '{address_1}',
1644: '{address_2}',
1645: '{city}',
1646: '{postcode}',
1647: '{zone}',
1648: '{zone_code}',
1649: '{country}'
1650: ];
1651:
1652: $replace = [
1653: 'firstname' => $order_info['shipping_firstname'],
1654: 'lastname' => $order_info['shipping_lastname'],
1655: 'company' => $order_info['shipping_company'],
1656: 'address_1' => $order_info['shipping_address_1'],
1657: 'address_2' => $order_info['shipping_address_2'],
1658: 'city' => $order_info['shipping_city'],
1659: 'postcode' => $order_info['shipping_postcode'],
1660: 'zone' => $order_info['shipping_zone'],
1661: 'zone_code' => $order_info['shipping_zone_code'],
1662: 'country' => $order_info['shipping_country']
1663: ];
1664:
1665: $pattern_1 = [
1666: "\r\n",
1667: "\r",
1668: "\n"
1669: ];
1670:
1671: $pattern_2 = [
1672: "/\\s\\s+/",
1673: "/\r\r+/",
1674: "/\n\n+/"
1675: ];
1676:
1677: $shipping_address = str_replace($pattern_1, '<br/>', preg_replace($pattern_2, '<br/>', trim(str_replace($find, $replace, $format))));
1678:
1679: $product_data = [];
1680:
1681: $products = $this->model_sale_order->getProducts($order_id);
1682:
1683: foreach ($products as $product) {
1684: $option_weight = 0;
1685:
1686: $product_info = $this->model_catalog_product->getProduct($product['product_id']);
1687:
1688: if ($product_info) {
1689: $option_data = [];
1690:
1691: $options = $this->model_sale_order->getOptions($order_id, $product['order_product_id']);
1692:
1693: foreach ($options as $option) {
1694: if ($option['type'] != 'file') {
1695: $value = $option['value'];
1696: } else {
1697: $upload_info = $this->model_tool_upload->getUploadByCode($option['value']);
1698:
1699: if ($upload_info) {
1700: $value = $upload_info['name'];
1701: } else {
1702: $value = '';
1703: }
1704: }
1705:
1706: $option_data[] = [
1707: 'name' => $option['name'],
1708: 'value' => $value
1709: ];
1710:
1711: $product_option_value_info = $this->model_catalog_product->getOptionValue($product['product_id'], $option['product_option_value_id']);
1712:
1713: if (!empty($product_option_value_info['weight'])) {
1714: if ($product_option_value_info['weight_prefix'] == '+') {
1715: $option_weight += $product_option_value_info['weight'];
1716: } elseif ($product_option_value_info['weight_prefix'] == '-') {
1717: $option_weight -= $product_option_value_info['weight'];
1718: }
1719: }
1720: }
1721:
1722: $product_data[] = [
1723: 'name' => $product_info['name'],
1724: 'model' => $product_info['model'],
1725: 'option' => $option_data,
1726: 'quantity' => $product['quantity'],
1727: 'location' => $product_info['location'],
1728: 'sku' => $product_info['sku'],
1729: 'upc' => $product_info['upc'],
1730: 'ean' => $product_info['ean'],
1731: 'jan' => $product_info['jan'],
1732: 'isbn' => $product_info['isbn'],
1733: 'mpn' => $product_info['mpn'],
1734: 'weight' => $this->weight->format(($product_info['weight'] + (float)$option_weight) * $product['quantity'], $product_info['weight_class_id'], $this->language->get('decimal_point'), $this->language->get('thousand_point'))
1735: ];
1736: }
1737: }
1738:
1739: $data['orders'][] = [
1740: 'order_id' => $order_id,
1741: 'invoice_no' => $invoice_no,
1742: 'date_added' => date($this->language->get('date_format_short'), strtotime($order_info['date_added'])),
1743: 'store_name' => $order_info['store_name'],
1744: 'store_url' => rtrim($order_info['store_url'], '/'),
1745: 'store_address' => nl2br($store_address),
1746: 'store_email' => $store_email,
1747: 'store_telephone' => $store_telephone,
1748: 'email' => $order_info['email'],
1749: 'telephone' => $order_info['telephone'],
1750: 'shipping_address' => $shipping_address,
1751: 'shipping_method' => $order_info['shipping_method']['name'],
1752: 'product' => $product_data,
1753: 'comment' => nl2br($order_info['comment'])
1754: ];
1755: }
1756: }
1757:
1758: $this->response->setOutput($this->load->view('sale/order_shipping', $data));
1759: }
1760:
1761: /**
1762: * History
1763: *
1764: * @return void
1765: */
1766: public function history(): void {
1767: $this->load->language('sale/order');
1768:
1769: $this->response->setOutput($this->getHistory());
1770: }
1771:
1772: /**
1773: * Get History
1774: *
1775: * @return string
1776: */
1777: public function getHistory(): string {
1778: if (isset($this->request->get['order_id'])) {
1779: $order_id = (int)$this->request->get['order_id'];
1780: } else {
1781: $order_id = 0;
1782: }
1783:
1784: if (isset($this->request->get['page']) && $this->request->get['route'] == 'sale/order.history') {
1785: $page = (int)$this->request->get['page'];
1786: } else {
1787: $page = 1;
1788: }
1789:
1790: $limit = 10;
1791:
1792: $data['histories'] = [];
1793:
1794: $this->load->model('sale/order');
1795:
1796: $results = $this->model_sale_order->getHistories($order_id, ($page - 1) * $limit, $limit);
1797:
1798: foreach ($results as $result) {
1799: $data['histories'][] = [
1800: 'status' => $result['status'],
1801: 'comment' => nl2br($result['comment']),
1802: 'notify' => $result['notify'] ? $this->language->get('text_yes') : $this->language->get('text_no'),
1803: 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added']))
1804: ];
1805: }
1806:
1807: $history_total = $this->model_sale_order->getTotalHistories($order_id);
1808:
1809: $data['pagination'] = $this->load->controller('common/pagination', [
1810: 'total' => $history_total,
1811: 'page' => $page,
1812: 'limit' => $limit,
1813: 'url' => $this->url->link('sale/order.history', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $order_id . '&page={page}')
1814: ]);
1815:
1816: $data['results'] = sprintf($this->language->get('text_pagination'), ($history_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($history_total - $limit)) ? $history_total : ((($page - 1) * $limit) + $limit), $history_total, ceil($history_total / $limit));
1817:
1818: return $this->load->view('sale/order_history', $data);
1819: }
1820:
1821: /**
1822: * Create Invoice No
1823: *
1824: * @return void
1825: */
1826: public function createInvoiceNo(): void {
1827: $this->load->language('sale/order');
1828:
1829: $json = [];
1830:
1831: if (isset($this->request->get['order_id'])) {
1832: $order_id = (int)$this->request->get['order_id'];
1833: } else {
1834: $order_id = 0;
1835: }
1836:
1837: if (!$this->user->hasPermission('modify', 'sale/order')) {
1838: $json['error'] = $this->language->get('error_permission');
1839: }
1840:
1841: $this->load->model('sale/order');
1842:
1843: $order_info = $this->model_sale_order->getOrder($order_id);
1844:
1845: if ($order_info) {
1846: if ($order_info['invoice_no']) {
1847: $json['error'] = $this->language->get('error_invoice_no');
1848: }
1849: } else {
1850: $json['error'] = $this->language->get('error_order');
1851: }
1852:
1853: if (!$json) {
1854: $json['success'] = $this->language->get('text_success');
1855:
1856: $this->load->model('sale/order');
1857:
1858: $json['invoice_no'] = $this->model_sale_order->createInvoiceNo($order_id);
1859: }
1860:
1861: $this->response->addHeader('Content-Type: application/json');
1862: $this->response->setOutput(json_encode($json));
1863: }
1864:
1865: /**
1866: * Add Reward
1867: *
1868: * @return void
1869: */
1870: public function addReward(): void {
1871: $this->load->language('sale/order');
1872:
1873: $json = [];
1874:
1875: if (isset($this->request->get['order_id'])) {
1876: $order_id = (int)$this->request->get['order_id'];
1877: } else {
1878: $order_id = 0;
1879: }
1880:
1881: if (!$this->user->hasPermission('modify', 'sale/order')) {
1882: $json['error'] = $this->language->get('error_permission');
1883: }
1884:
1885: $this->load->model('sale/order');
1886:
1887: $order_info = $this->model_sale_order->getOrder($order_id);
1888:
1889: if ($order_info) {
1890: if (!$order_info['customer_id']) {
1891: $json['error'] = $this->language->get('error_customer');
1892: }
1893: } else {
1894: $json['error'] = $this->language->get('error_order');
1895: }
1896:
1897: $this->load->model('customer/customer');
1898:
1899: $reward_total = $this->model_customer_customer->getTotalRewardsByOrderId($order_id);
1900:
1901: if ($reward_total) {
1902: $json['error'] = $this->language->get('error_reward_add');
1903: }
1904:
1905: if (!$json) {
1906: $this->model_customer_customer->addReward($order_info['customer_id'], $this->language->get('text_order_id') . ' #' . $order_id, $order_info['reward'], $order_id);
1907:
1908: $json['success'] = $this->language->get('text_reward_add');
1909: }
1910:
1911: $this->response->addHeader('Content-Type: application/json');
1912: $this->response->setOutput(json_encode($json));
1913: }
1914:
1915: /**
1916: * Remove Reward
1917: *
1918: * @return void
1919: */
1920: public function removeReward(): void {
1921: $this->load->language('sale/order');
1922:
1923: $json = [];
1924:
1925: if (isset($this->request->get['order_id'])) {
1926: $order_id = (int)$this->request->get['order_id'];
1927: } else {
1928: $order_id = 0;
1929: }
1930:
1931: if (!$this->user->hasPermission('modify', 'sale/order')) {
1932: $json['error'] = $this->language->get('error_permission');
1933: }
1934:
1935: $this->load->model('sale/order');
1936:
1937: $order_info = $this->model_sale_order->getOrder($order_id);
1938:
1939: if (!$order_info) {
1940: $json['error'] = $this->language->get('error_order');
1941: }
1942:
1943: if (!$json) {
1944: $this->load->model('customer/customer');
1945:
1946: $this->model_customer_customer->deleteRewardByOrderId($order_id);
1947:
1948: $json['success'] = $this->language->get('text_reward_remove');
1949: }
1950:
1951: $this->response->addHeader('Content-Type: application/json');
1952: $this->response->setOutput(json_encode($json));
1953: }
1954:
1955: /**
1956: * Add Commission
1957: *
1958: * @return void
1959: */
1960: public function addCommission(): void {
1961: $this->load->language('sale/order');
1962:
1963: $json = [];
1964:
1965: if (isset($this->request->get['order_id'])) {
1966: $order_id = (int)$this->request->get['order_id'];
1967: } else {
1968: $order_id = 0;
1969: }
1970:
1971: if (!$this->user->hasPermission('modify', 'sale/order')) {
1972: $json['error'] = $this->language->get('error_permission');
1973: }
1974:
1975: $this->load->model('sale/order');
1976:
1977: $order_info = $this->model_sale_order->getOrder($order_id);
1978:
1979: if ($order_info) {
1980: $this->load->model('customer/customer');
1981:
1982: $customer_info = $this->model_customer_customer->getCustomer($order_info['affiliate_id']);
1983:
1984: if (!$customer_info) {
1985: $json['error'] = $this->language->get('error_affiliate');
1986: }
1987:
1988: $affiliate_total = $this->model_customer_customer->getTotalTransactionsByOrderId($order_id);
1989:
1990: if ($affiliate_total) {
1991: $json['error'] = $this->language->get('error_commission_add');
1992: }
1993: } else {
1994: $json['error'] = $this->language->get('error_order');
1995: }
1996:
1997: if (!$json) {
1998: $this->model_customer_customer->addTransaction($order_info['affiliate_id'], $this->language->get('text_order_id') . ' #' . $order_id, $order_info['commission'], $order_id);
1999:
2000: $json['success'] = $this->language->get('text_commission_add');
2001: }
2002:
2003: $this->response->addHeader('Content-Type: application/json');
2004: $this->response->setOutput(json_encode($json));
2005: }
2006:
2007: /**
2008: * Remove Commission
2009: *
2010: * @return void
2011: */
2012: public function removeCommission(): void {
2013: $this->load->language('sale/order');
2014:
2015: $json = [];
2016:
2017: if (isset($this->request->get['order_id'])) {
2018: $order_id = (int)$this->request->get['order_id'];
2019: } else {
2020: $order_id = 0;
2021: }
2022:
2023: if (!$this->user->hasPermission('modify', 'sale/order')) {
2024: $json['error'] = $this->language->get('error_permission');
2025: }
2026:
2027: $this->load->model('sale/order');
2028:
2029: $order_info = $this->model_sale_order->getOrder($order_id);
2030:
2031: if (!$order_info) {
2032: $json['error'] = $this->language->get('error_order');
2033: }
2034:
2035: if (!$json) {
2036: $this->load->model('customer/customer');
2037:
2038: $this->model_customer_customer->deleteTransactionByOrderId($order_id);
2039:
2040: $json['success'] = $this->language->get('text_commission_remove');
2041: }
2042:
2043: $this->response->addHeader('Content-Type: application/json');
2044: $this->response->setOutput(json_encode($json));
2045: }
2046: }
2047: