1: | <?php
2: | namespace Opencart\Admin\Controller\Extension\Opencart\Report;
3: | /**
4: | * Class Customer Order
5: | *
6: | * @package Opencart\Admin\Controller\Extension\Opencart\Report
7: | */
8: | class CustomerOrder extends \Opencart\System\Engine\Controller {
9: | /**
10: | * Index
11: | *
12: | * @return void
13: | */
14: | public function index(): void {
15: | $this->load->language('extension/opencart/report/customer_order');
16: |
17: | $this->document->setTitle($this->language->get('heading_title'));
18: |
19: | $data['breadcrumbs'] = [];
20: |
21: | $data['breadcrumbs'][] = [
22: | 'text' => $this->language->get('text_home'),
23: | 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
24: | ];
25: |
26: | $data['breadcrumbs'][] = [
27: | 'text' => $this->language->get('text_extension'),
28: | 'href' => $this->url->link('marketplace/opencart/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report')
29: | ];
30: |
31: | $data['breadcrumbs'][] = [
32: | 'text' => $this->language->get('heading_title'),
33: | 'href' => $this->url->link('extension/opencart/report/customer_order', 'user_token=' . $this->session->data['user_token'])
34: | ];
35: |
36: | $data['save'] = $this->url->link('extension/opencart/report/customer_order.save', 'user_token=' . $this->session->data['user_token']);
37: | $data['back'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report');
38: |
39: | $data['report_customer_order_status'] = $this->config->get('report_customer_order_status');
40: | $data['report_customer_order_sort_order'] = $this->config->get('report_customer_order_sort_order');
41: |
42: | $data['header'] = $this->load->controller('common/header');
43: | $data['column_left'] = $this->load->controller('common/column_left');
44: | $data['footer'] = $this->load->controller('common/footer');
45: |
46: | $this->response->setOutput($this->load->view('extension/opencart/report/customer_order_form', $data));
47: | }
48: |
49: | /**
50: | * Save
51: | *
52: | * @return void
53: | */
54: | public function save(): void {
55: | $this->load->language('extension/opencart/report/customer_order');
56: |
57: | $json = [];
58: |
59: | if (!$this->user->hasPermission('modify', 'extension/opencart/report/customer_order')) {
60: | $json['error'] = $this->language->get('error_permission');
61: | }
62: |
63: | if (!$json) {
64: | $this->load->model('setting/setting');
65: |
66: | $this->model_setting_setting->editSetting('report_customer_order', $this->request->post);
67: |
68: | $json['success'] = $this->language->get('text_success');
69: | }
70: |
71: | $this->response->addHeader('Content-Type: application/json');
72: | $this->response->setOutput(json_encode($json));
73: | }
74: |
75: | /**
76: | * Report
77: | *
78: | * @return void
79: | */
80: | public function report(): void {
81: | $this->load->language('extension/opencart/report/customer_order');
82: |
83: | $data['list'] = $this->getReport();
84: |
85: | $this->load->model('localisation/order_status');
86: |
87: | $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
88: |
89: | $data['user_token'] = $this->session->data['user_token'];
90: |
91: | $this->response->setOutput($this->load->view('extension/opencart/report/customer_order', $data));
92: | }
93: |
94: | /**
95: | * List
96: | *
97: | * @return void
98: | */
99: | public function list(): void {
100: | $this->load->language('extension/opencart/report/customer_order');
101: |
102: | $this->response->setOutput($this->getReport());
103: | }
104: |
105: | /**
106: | * Get Report
107: | *
108: | * @return string
109: | */
110: | public function getReport(): string {
111: | if (isset($this->request->get['filter_date_start'])) {
112: | $filter_date_start = $this->request->get['filter_date_start'];
113: | } else {
114: | $filter_date_start = '';
115: | }
116: |
117: | if (isset($this->request->get['filter_date_end'])) {
118: | $filter_date_end = $this->request->get['filter_date_end'];
119: | } else {
120: | $filter_date_end = '';
121: | }
122: |
123: | if (isset($this->request->get['filter_customer'])) {
124: | $filter_customer = $this->request->get['filter_customer'];
125: | } else {
126: | $filter_customer = '';
127: | }
128: |
129: | if (isset($this->request->get['filter_order_status_id'])) {
130: | $filter_order_status_id = (int)$this->request->get['filter_order_status_id'];
131: | } else {
132: | $filter_order_status_id = 0;
133: | }
134: |
135: | if (isset($this->request->get['page'])) {
136: | $page = (int)$this->request->get['page'];
137: | } else {
138: | $page = 1;
139: | }
140: |
141: | $data['customers'] = [];
142: |
143: | $filter_data = [
144: | 'filter_date_start' => $filter_date_start,
145: | 'filter_date_end' => $filter_date_end,
146: | 'filter_customer' => $filter_customer,
147: | 'filter_order_status_id' => $filter_order_status_id,
148: | 'start' => ($page - 1) * $this->config->get('config_pagination'),
149: | 'limit' => $this->config->get('config_pagination')
150: | ];
151: |
152: | $this->load->model('extension/opencart/report/customer');
153: |
154: | $customer_total = $this->model_extension_opencart_report_customer->getTotalOrders($filter_data);
155: |
156: | $results = $this->model_extension_opencart_report_customer->getOrders($filter_data);
157: |
158: | foreach ($results as $result) {
159: | $data['customers'][] = [
160: | 'customer' => $result['customer'],
161: | 'email' => $result['email'],
162: | 'customer_group' => $result['customer_group'],
163: | 'status' => ($result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled')),
164: | 'orders' => $result['orders'],
165: | 'products' => $result['products'],
166: | 'total' => $this->currency->format($result['total'], $this->config->get('config_currency')),
167: | 'edit' => $this->url->link('customer/customer.form', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $result['customer_id'])
168: | ];
169: | }
170: |
171: | $url = '';
172: |
173: | if (isset($this->request->get['filter_date_start'])) {
174: | $url .= '&filter_date_start=' . $this->request->get['filter_date_start'];
175: | }
176: |
177: | if (isset($this->request->get['filter_date_end'])) {
178: | $url .= '&filter_date_end=' . $this->request->get['filter_date_end'];
179: | }
180: |
181: | if (isset($this->request->get['filter_customer'])) {
182: | $url .= '&filter_customer=' . urlencode($this->request->get['filter_customer']);
183: | }
184: |
185: | if (isset($this->request->get['filter_order_status_id'])) {
186: | $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id'];
187: | }
188: |
189: | $data['pagination'] = $this->load->controller('common/pagination', [
190: | 'total' => $customer_total,
191: | 'page' => $page,
192: | 'limit' => $this->config->get('config_pagination'),
193: | 'url' => $this->url->link('extension/opencart/report/customer_order.report', 'user_token=' . $this->session->data['user_token'] . '&code=customer_order' . $url . '&page={page}')
194: | ]);
195: |
196: | $data['results'] = sprintf($this->language->get('text_pagination'), ($customer_total) ? (($page - 1) * $this->config->get('config_pagination')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination')) > ($customer_total - $this->config->get('config_pagination'))) ? $customer_total : ((($page - 1) * $this->config->get('config_pagination')) + $this->config->get('config_pagination')), $customer_total, ceil($customer_total / $this->config->get('config_pagination')));
197: |
198: | $data['filter_date_start'] = $filter_date_start;
199: | $data['filter_date_end'] = $filter_date_end;
200: | $data['filter_customer'] = $filter_customer;
201: | $data['filter_order_status_id'] = $filter_order_status_id;
202: |
203: | $data['user_token'] = $this->session->data['user_token'];
204: |
205: | return $this->load->view('extension/opencart/report/customer_order_list', $data);
206: | }
207: | }
208: |

OpenCart API API documentation generated by ApiGen dev-master