1: | <?php
|
2: | namespace Opencart\Catalog\Controller\Account;
|
3: | |
4: | |
5: | |
6: | |
7: |
|
8: | class Returns extends \Opencart\System\Engine\Controller {
|
9: | |
10: | |
11: |
|
12: | public function index(): void {
|
13: | $this->load->language('account/returns');
|
14: |
|
15: | if (isset($this->request->get['page'])) {
|
16: | $page = (int)$this->request->get['page'];
|
17: | } else {
|
18: | $page = 1;
|
19: | }
|
20: |
|
21: | if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
|
22: | $this->session->data['redirect'] = $this->url->link('account/returns', 'language=' . $this->config->get('config_language'));
|
23: |
|
24: | $this->response->redirect($this->url->link('account/login', 'language=' . $this->config->get('config_language'), true));
|
25: | }
|
26: |
|
27: | $limit = 10;
|
28: |
|
29: | $this->document->setTitle($this->language->get('heading_title'));
|
30: |
|
31: | $data['breadcrumbs'] = [];
|
32: |
|
33: | $data['breadcrumbs'][] = [
|
34: | 'text' => $this->language->get('text_home'),
|
35: | 'href' => $this->url->link('common/home', 'language=' . $this->config->get('config_language'))
|
36: | ];
|
37: |
|
38: | $data['breadcrumbs'][] = [
|
39: | 'text' => $this->language->get('text_account'),
|
40: | 'href' => $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'])
|
41: | ];
|
42: |
|
43: | $url = '';
|
44: |
|
45: | if (isset($this->request->get['page'])) {
|
46: | $url .= '&page=' . $this->request->get['page'];
|
47: | }
|
48: |
|
49: | $data['breadcrumbs'][] = [
|
50: | 'text' => $this->language->get('heading_title'),
|
51: | 'href' => $this->url->link('account/returns', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . $url)
|
52: | ];
|
53: |
|
54: | $data['returns'] = [];
|
55: |
|
56: | $this->load->model('account/returns');
|
57: |
|
58: | $results = $this->model_account_returns->getReturns(($page - 1) * $limit, $limit);
|
59: |
|
60: | foreach ($results as $result) {
|
61: | $data['returns'][] = [
|
62: | 'return_id' => $result['return_id'],
|
63: | 'order_id' => $result['order_id'],
|
64: | 'name' => $result['firstname'] . ' ' . $result['lastname'],
|
65: | 'status' => $result['status'],
|
66: | 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
|
67: | 'href' => $this->url->link('account/returns.info', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . '&return_id=' . $result['return_id'] . $url)
|
68: | ];
|
69: | }
|
70: |
|
71: | $return_total = $this->model_account_returns->getTotalReturns();
|
72: |
|
73: | $data['pagination'] = $this->load->controller('common/pagination', [
|
74: | 'total' => $return_total,
|
75: | 'page' => $page,
|
76: | 'limit' => $limit,
|
77: | 'url' => $this->url->link('account/returns', 'language=' . $this->config->get('config_language') . '&page={page}')
|
78: | ]);
|
79: |
|
80: | $data['results'] = sprintf($this->language->get('text_pagination'), ($return_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($return_total - $limit)) ? $return_total : ((($page - 1) * $limit) + $limit), $return_total, ceil($return_total / $limit));
|
81: |
|
82: | $data['continue'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
|
83: |
|
84: | $data['column_left'] = $this->load->controller('common/column_left');
|
85: | $data['column_right'] = $this->load->controller('common/column_right');
|
86: | $data['content_top'] = $this->load->controller('common/content_top');
|
87: | $data['content_bottom'] = $this->load->controller('common/content_bottom');
|
88: | $data['footer'] = $this->load->controller('common/footer');
|
89: | $data['header'] = $this->load->controller('common/header');
|
90: |
|
91: | $this->response->setOutput($this->load->view('account/returns_list', $data));
|
92: | }
|
93: |
|
94: | |
95: | |
96: | |
97: | |
98: |
|
99: | public function info(): ?\Opencart\System\Engine\Action {
|
100: | $this->load->language('account/returns');
|
101: |
|
102: | if (isset($this->request->get['return_id'])) {
|
103: | $return_id = (int)$this->request->get['return_id'];
|
104: | } else {
|
105: | $return_id = 0;
|
106: | }
|
107: |
|
108: | if (!$this->customer->isLogged() || (!isset($this->request->get['customer_token']) || !isset($this->session->data['customer_token']) || ($this->request->get['customer_token'] != $this->session->data['customer_token']))) {
|
109: | $this->session->data['redirect'] = $this->url->link('account/returns.info', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
|
110: |
|
111: | $this->response->redirect($this->url->link('account/login', 'language=' . $this->config->get('config_language'), true));
|
112: | }
|
113: |
|
114: | $this->load->model('account/returns');
|
115: |
|
116: | $return_info = $this->model_account_returns->getReturn($return_id);
|
117: |
|
118: | if ($return_info) {
|
119: | $this->document->setTitle($this->language->get('text_return'));
|
120: |
|
121: | $data['breadcrumbs'] = [];
|
122: |
|
123: | $data['breadcrumbs'][] = [
|
124: | 'text' => $this->language->get('text_home'),
|
125: | 'href' => $this->url->link('common/home', 'language=' . $this->config->get('config_language'))
|
126: | ];
|
127: |
|
128: | $data['breadcrumbs'][] = [
|
129: | 'text' => $this->language->get('text_account'),
|
130: | 'href' => $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'])
|
131: | ];
|
132: |
|
133: | $url = '';
|
134: |
|
135: | if (isset($this->request->get['page'])) {
|
136: | $url .= '&page=' . $this->request->get['page'];
|
137: | }
|
138: |
|
139: | $data['breadcrumbs'][] = [
|
140: | 'text' => $this->language->get('heading_title'),
|
141: | 'href' => $this->url->link('account/returns', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . $url)
|
142: | ];
|
143: |
|
144: | $data['breadcrumbs'][] = [
|
145: | 'text' => $this->language->get('text_return'),
|
146: | 'href' => $this->url->link('account/returns.info', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'] . '&return_id=' . $this->request->get['return_id'] . $url)
|
147: | ];
|
148: |
|
149: | $data['return_id'] = $return_info['return_id'];
|
150: | $data['order_id'] = $return_info['order_id'];
|
151: | $data['date_ordered'] = date($this->language->get('date_format_short'), strtotime($return_info['date_ordered']));
|
152: | $data['date_added'] = date($this->language->get('date_format_short'), strtotime($return_info['date_added']));
|
153: | $data['firstname'] = $return_info['firstname'];
|
154: | $data['lastname'] = $return_info['lastname'];
|
155: | $data['email'] = $return_info['email'];
|
156: | $data['telephone'] = $return_info['telephone'];
|
157: | $data['product'] = $return_info['product'];
|
158: | $data['model'] = $return_info['model'];
|
159: | $data['quantity'] = $return_info['quantity'];
|
160: | $data['reason'] = $return_info['reason'];
|
161: | $data['opened'] = $return_info['opened'] ? $this->language->get('text_yes') : $this->language->get('text_no');
|
162: | $data['comment'] = nl2br($return_info['comment']);
|
163: | $data['action'] = $return_info['action'];
|
164: |
|
165: | $data['histories'] = [];
|
166: |
|
167: | $results = $this->model_account_returns->getHistories($this->request->get['return_id']);
|
168: |
|
169: | foreach ($results as $result) {
|
170: | $data['histories'][] = [
|
171: | 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
|
172: | 'status' => $result['status'],
|
173: | 'comment' => nl2br($result['comment'])
|
174: | ];
|
175: | }
|
176: |
|
177: | $data['continue'] = $this->url->link('account/returns', 'language=' . $this->config->get('config_language') . $url . '&customer_token=' . $this->session->data['customer_token']);
|
178: | $data['column_left'] = $this->load->controller('common/column_left');
|
179: | $data['column_right'] = $this->load->controller('common/column_right');
|
180: | $data['content_top'] = $this->load->controller('common/content_top');
|
181: | $data['content_bottom'] = $this->load->controller('common/content_bottom');
|
182: | $data['footer'] = $this->load->controller('common/footer');
|
183: | $data['header'] = $this->load->controller('common/header');
|
184: |
|
185: | $this->response->setOutput($this->load->view('account/returns_info', $data));
|
186: | } else {
|
187: | return new \Opencart\System\Engine\Action('error/not_found');
|
188: | }
|
189: |
|
190: | return null;
|
191: | }
|
192: |
|
193: | |
194: | |
195: | |
196: | |
197: |
|
198: | public function add(): void {
|
199: | $this->load->language('account/returns');
|
200: |
|
201: | $this->document->setTitle($this->language->get('heading_title'));
|
202: |
|
203: | $data['breadcrumbs'] = [];
|
204: |
|
205: | $data['breadcrumbs'][] = [
|
206: | 'text' => $this->language->get('text_home'),
|
207: | 'href' => $this->url->link('common/home', 'language=' . $this->config->get('config_language'))
|
208: | ];
|
209: |
|
210: | $data['breadcrumbs'][] = [
|
211: | 'text' => $this->language->get('text_account'),
|
212: | 'href' => $this->url->link('account/account', 'language=' . $this->config->get('config_language'))
|
213: | ];
|
214: |
|
215: | $data['breadcrumbs'][] = [
|
216: | 'text' => $this->language->get('heading_title'),
|
217: | 'href' => $this->url->link('account/returns.add', 'language=' . $this->config->get('config_language'))
|
218: | ];
|
219: |
|
220: | $this->session->data['return_token'] = oc_token(26);
|
221: |
|
222: | $data['save'] = $this->url->link('account/returns.save', 'language=' . $this->config->get('config_language') . '&return_token=' . $this->session->data['return_token']);
|
223: |
|
224: | $this->load->model('account/order');
|
225: |
|
226: | if (isset($this->request->get['order_id'])) {
|
227: | $order_info = $this->model_account_order->getOrder($this->request->get['order_id']);
|
228: | }
|
229: |
|
230: | $this->load->model('catalog/product');
|
231: |
|
232: | if (isset($this->request->get['product_id'])) {
|
233: | $product_info = $this->model_catalog_product->getProduct($this->request->get['product_id']);
|
234: | }
|
235: |
|
236: | if (!empty($order_info)) {
|
237: | $data['order_id'] = $order_info['order_id'];
|
238: | } else {
|
239: | $data['order_id'] = '';
|
240: | }
|
241: |
|
242: | if (!empty($product_info)) {
|
243: | $data['product_id'] = $product_info['product_id'];
|
244: | } else {
|
245: | $data['product_id'] = '';
|
246: | }
|
247: |
|
248: | if (!empty($order_info)) {
|
249: | $data['date_ordered'] = date('Y-m-d', strtotime($order_info['date_added']));
|
250: | } else {
|
251: | $data['date_ordered'] = '';
|
252: | }
|
253: |
|
254: | if (!empty($order_info)) {
|
255: | $data['firstname'] = $order_info['firstname'];
|
256: | } else {
|
257: | $data['firstname'] = $this->customer->getFirstName();
|
258: | }
|
259: |
|
260: | if (!empty($order_info)) {
|
261: | $data['lastname'] = $order_info['lastname'];
|
262: | } else {
|
263: | $data['lastname'] = $this->customer->getLastName();
|
264: | }
|
265: |
|
266: | if (!empty($order_info)) {
|
267: | $data['email'] = $order_info['email'];
|
268: | } else {
|
269: | $data['email'] = $this->customer->getEmail();
|
270: | }
|
271: |
|
272: | if (!empty($order_info)) {
|
273: | $data['telephone'] = $order_info['telephone'];
|
274: | } else {
|
275: | $data['telephone'] = $this->customer->getTelephone();
|
276: | }
|
277: |
|
278: | if (!empty($product_info)) {
|
279: | $data['product'] = $product_info['name'];
|
280: | } else {
|
281: | $data['product'] = '';
|
282: | }
|
283: |
|
284: | if (!empty($product_info)) {
|
285: | $data['model'] = $product_info['model'];
|
286: | } else {
|
287: | $data['model'] = '';
|
288: | }
|
289: |
|
290: | $this->load->model('localisation/return_reason');
|
291: |
|
292: | $data['return_reasons'] = $this->model_localisation_return_reason->getReturnReasons();
|
293: |
|
294: |
|
295: | $this->load->model('setting/extension');
|
296: |
|
297: | $extension_info = $this->model_setting_extension->getExtensionByCode('captcha', $this->config->get('config_captcha'));
|
298: |
|
299: | if ($extension_info && $this->config->get('captcha_' . $this->config->get('config_captcha') . '_status') && in_array('returns', (array)$this->config->get('config_captcha_page'))) {
|
300: | $data['captcha'] = $this->load->controller('extension/' . $extension_info['extension'] . '/captcha/' . $extension_info['code']);
|
301: | } else {
|
302: | $data['captcha'] = '';
|
303: | }
|
304: |
|
305: | $this->load->model('catalog/information');
|
306: |
|
307: | $information_info = $this->model_catalog_information->getInformation($this->config->get('config_return_id'));
|
308: |
|
309: | if ($information_info) {
|
310: | $data['text_agree'] = sprintf($this->language->get('text_agree'), $this->url->link('information/information.info', 'language=' . $this->config->get('config_language') . '&information_id=' . $this->config->get('config_return_id')), $information_info['title']);
|
311: | } else {
|
312: | $data['text_agree'] = '';
|
313: | }
|
314: |
|
315: | $data['back'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language'));
|
316: |
|
317: | $data['column_left'] = $this->load->controller('common/column_left');
|
318: | $data['column_right'] = $this->load->controller('common/column_right');
|
319: | $data['content_top'] = $this->load->controller('common/content_top');
|
320: | $data['content_bottom'] = $this->load->controller('common/content_bottom');
|
321: | $data['footer'] = $this->load->controller('common/footer');
|
322: | $data['header'] = $this->load->controller('common/header');
|
323: |
|
324: | $this->response->setOutput($this->load->view('account/returns_form', $data));
|
325: | }
|
326: |
|
327: | |
328: | |
329: | |
330: | |
331: |
|
332: | public function save(): void {
|
333: | $this->load->language('account/returns');
|
334: |
|
335: | $json = [];
|
336: |
|
337: | if (!isset($this->request->get['return_token']) || !isset($this->session->data['return_token']) || ($this->request->get['return_token'] != $this->session->data['return_token'])) {
|
338: | $json['redirect'] = $this->url->link('account/returns.add', 'language=' . $this->config->get('config_language'), true);
|
339: | }
|
340: |
|
341: | if (!$json) {
|
342: | $keys = [
|
343: | 'order_id',
|
344: | 'firstname',
|
345: | 'lastname',
|
346: | 'email',
|
347: | 'telephone',
|
348: | 'product',
|
349: | 'model',
|
350: | 'reason',
|
351: | 'agree'
|
352: | ];
|
353: |
|
354: | foreach ($keys as $key) {
|
355: | if (!isset($this->request->post[$key])) {
|
356: | $this->request->post[$key] = '';
|
357: | }
|
358: | }
|
359: |
|
360: | if (!$this->request->post['order_id']) {
|
361: | $json['error']['order_id'] = $this->language->get('error_order_id');
|
362: | }
|
363: |
|
364: | if ((oc_strlen($this->request->post['firstname']) < 1) || (oc_strlen($this->request->post['firstname']) > 32)) {
|
365: | $json['error']['firstname'] = $this->language->get('error_firstname');
|
366: | }
|
367: |
|
368: | if ((oc_strlen($this->request->post['lastname']) < 1) || (oc_strlen($this->request->post['lastname']) > 32)) {
|
369: | $json['error']['lastname'] = $this->language->get('error_lastname');
|
370: | }
|
371: |
|
372: | if ((oc_strlen($this->request->post['email']) > 96) || !filter_var($this->request->post['email'], FILTER_VALIDATE_EMAIL)) {
|
373: | $json['error']['email'] = $this->language->get('error_email');
|
374: | }
|
375: |
|
376: | if ((oc_strlen($this->request->post['telephone']) < 3) || (oc_strlen($this->request->post['telephone']) > 32)) {
|
377: | $json['error']['telephone'] = $this->language->get('error_telephone');
|
378: | }
|
379: |
|
380: | if ((oc_strlen($this->request->post['product']) < 1) || (oc_strlen($this->request->post['product']) > 255)) {
|
381: | $json['error']['product'] = $this->language->get('error_product');
|
382: | }
|
383: |
|
384: | if ((oc_strlen($this->request->post['model']) < 1) || (oc_strlen($this->request->post['model']) > 64)) {
|
385: | $json['error']['model'] = $this->language->get('error_model');
|
386: | }
|
387: |
|
388: | if (empty($this->request->post['return_reason_id'])) {
|
389: | $json['error']['reason'] = $this->language->get('error_reason');
|
390: | }
|
391: |
|
392: |
|
393: | $this->load->model('setting/extension');
|
394: |
|
395: | $extension_info = $this->model_setting_extension->getExtensionByCode('captcha', $this->config->get('config_captcha'));
|
396: |
|
397: | if ($extension_info && $this->config->get('captcha_' . $this->config->get('config_captcha') . '_status') && in_array('returns', (array)$this->config->get('config_captcha_page'))) {
|
398: | $captcha = $this->load->controller('extension/' . $extension_info['extension'] . '/captcha/' . $extension_info['code'] . '.validate');
|
399: |
|
400: | if ($captcha) {
|
401: | $json['error']['captcha'] = $captcha;
|
402: | }
|
403: | }
|
404: |
|
405: | if ($this->config->get('config_return_id')) {
|
406: | $this->load->model('catalog/information');
|
407: |
|
408: | $information_info = $this->model_catalog_information->getInformation($this->config->get('config_return_id'));
|
409: |
|
410: | if ($information_info && !isset($this->request->post['agree'])) {
|
411: | $json['error']['warning'] = sprintf($this->language->get('error_agree'), $information_info['title']);
|
412: | }
|
413: | }
|
414: | }
|
415: |
|
416: | if (!$json) {
|
417: | $this->load->model('account/returns');
|
418: |
|
419: | $this->model_account_returns->addReturn($this->request->post);
|
420: |
|
421: | $json['redirect'] = $this->url->link('account/returns.success', 'language=' . $this->config->get('config_language'), true);
|
422: | }
|
423: |
|
424: | $this->response->addHeader('Content-Type: application/json');
|
425: | $this->response->setOutput(json_encode($json));
|
426: | }
|
427: |
|
428: | |
429: | |
430: | |
431: | |
432: |
|
433: | public function success(): void {
|
434: | $this->load->language('account/returns');
|
435: |
|
436: | $this->document->setTitle($this->language->get('heading_title'));
|
437: |
|
438: | $data['breadcrumbs'] = [];
|
439: |
|
440: | $data['breadcrumbs'][] = [
|
441: | 'text' => $this->language->get('text_home'),
|
442: | 'href' => $this->url->link('common/home', 'language=' . $this->config->get('config_language'))
|
443: | ];
|
444: |
|
445: | $data['breadcrumbs'][] = [
|
446: | 'text' => $this->language->get('heading_title'),
|
447: | 'href' => $this->url->link('account/returns.add', 'language=' . $this->config->get('config_language'))
|
448: | ];
|
449: |
|
450: | $data['continue'] = $this->url->link('common/home', 'language=' . $this->config->get('config_language'));
|
451: |
|
452: | $data['column_left'] = $this->load->controller('common/column_left');
|
453: | $data['column_right'] = $this->load->controller('common/column_right');
|
454: | $data['content_top'] = $this->load->controller('common/content_top');
|
455: | $data['content_bottom'] = $this->load->controller('common/content_bottom');
|
456: | $data['footer'] = $this->load->controller('common/footer');
|
457: | $data['header'] = $this->load->controller('common/header');
|
458: |
|
459: | $this->response->setOutput($this->load->view('common/success', $data));
|
460: | }
|
461: | }
|
462: | |