1: | <?php
|
2: | namespace Opencart\Admin\Controller\Extension\Opencart\Report;
|
3: | |
4: | |
5: | |
6: | |
7: |
|
8: | class Marketing extends \Opencart\System\Engine\Controller {
|
9: | |
10: | |
11: | |
12: | |
13: |
|
14: | public function index(): void {
|
15: | $this->load->language('extension/opencart/report/marketing');
|
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/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/marketing', 'user_token=' . $this->session->data['user_token'])
|
34: | ];
|
35: |
|
36: | $data['save'] = $this->url->link('extension/opencart/report/marketing.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_marketing_status'] = $this->config->get('report_marketing_status');
|
40: | $data['report_marketing_sort_order'] = $this->config->get('report_marketing_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/marketing_form', $data));
|
47: | }
|
48: |
|
49: | |
50: | |
51: | |
52: | |
53: |
|
54: | public function save(): void {
|
55: | $this->load->language('extension/opencart/report/marketing');
|
56: |
|
57: | $json = [];
|
58: |
|
59: | if (!$this->user->hasPermission('modify', 'extension/opencart/report/marketing')) {
|
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_marketing', $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: | |
77: | |
78: | |
79: |
|
80: | public function report(): void {
|
81: | $this->load->language('extension/opencart/report/marketing');
|
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/marketing', $data));
|
92: | }
|
93: |
|
94: | |
95: | |
96: | |
97: | |
98: |
|
99: | public function list(): void {
|
100: | $this->load->language('extension/opencart/report/marketing');
|
101: |
|
102: | $this->response->setOutput($this->getReport());
|
103: | }
|
104: |
|
105: | |
106: | |
107: | |
108: | |
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_order_status_id'])) {
|
124: | $filter_order_status_id = (int)$this->request->get['filter_order_status_id'];
|
125: | } else {
|
126: | $filter_order_status_id = 0;
|
127: | }
|
128: |
|
129: | if (isset($this->request->get['page'])) {
|
130: | $page = (int)$this->request->get['page'];
|
131: | } else {
|
132: | $page = 1;
|
133: | }
|
134: |
|
135: | $data['marketings'] = [];
|
136: |
|
137: | $filter_data = [
|
138: | 'filter_date_start' => $filter_date_start,
|
139: | 'filter_date_end' => $filter_date_end,
|
140: | 'filter_order_status_id' => $filter_order_status_id,
|
141: | 'start' => ($page - 1) * $this->config->get('config_pagination'),
|
142: | 'limit' => $this->config->get('config_pagination')
|
143: | ];
|
144: |
|
145: | $this->load->model('extension/opencart/report/marketing');
|
146: |
|
147: | $marketing_total = $this->model_extension_opencart_report_marketing->getTotalMarketing($filter_data);
|
148: |
|
149: | $results = $this->model_extension_opencart_report_marketing->getMarketing($filter_data);
|
150: |
|
151: | foreach ($results as $result) {
|
152: | $data['marketings'][] = [
|
153: | 'campaign' => $result['campaign'],
|
154: | 'code' => $result['code'],
|
155: | 'clicks' => $result['clicks'],
|
156: | 'orders' => $result['orders'],
|
157: | 'total' => $this->currency->format((float)$result['total'], $this->config->get('config_currency')),
|
158: | 'save' => $this->url->link('marketing/marketing/edit', 'user_token=' . $this->session->data['user_token'] . '&marketing_id=' . $result['marketing_id'])
|
159: | ];
|
160: | }
|
161: |
|
162: | $url = '';
|
163: |
|
164: | if (isset($this->request->get['filter_date_start'])) {
|
165: | $url .= '&filter_date_start=' . $this->request->get['filter_date_start'];
|
166: | }
|
167: |
|
168: | if (isset($this->request->get['filter_date_end'])) {
|
169: | $url .= '&filter_date_end=' . $this->request->get['filter_date_end'];
|
170: | }
|
171: |
|
172: | if (isset($this->request->get['filter_order_status_id'])) {
|
173: | $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id'];
|
174: | }
|
175: |
|
176: | $data['pagination'] = $this->load->controller('common/pagination', [
|
177: | 'total' => $marketing_total,
|
178: | 'page' => $page,
|
179: | 'limit' => $this->config->get('config_pagination'),
|
180: | 'url' => $this->url->link('extension/opencart/report/marketing.report', 'user_token=' . $this->session->data['user_token'] . '&code=marketing' . $url . '&page={page}')
|
181: | ]);
|
182: |
|
183: | $data['results'] = sprintf($this->language->get('text_pagination'), ($marketing_total) ? (($page - 1) * $this->config->get('config_pagination')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination')) > ($marketing_total - $this->config->get('config_pagination'))) ? $marketing_total : ((($page - 1) * $this->config->get('config_pagination')) + $this->config->get('config_pagination')), $marketing_total, ceil($marketing_total / $this->config->get('config_pagination')));
|
184: |
|
185: | $data['filter_date_start'] = $filter_date_start;
|
186: | $data['filter_date_end'] = $filter_date_end;
|
187: | $data['filter_order_status_id'] = $filter_order_status_id;
|
188: |
|
189: | $data['user_token'] = $this->session->data['user_token'];
|
190: |
|
191: | return $this->load->view('extension/opencart/report/marketing_list', $data);
|
192: | }
|
193: | }
|
194: | |