1: <?php
2: namespace Opencart\Catalog\Controller\Account;
3: /**
4: * Class Tracking
5: *
6: * @package Opencart\Catalog\Controller\Account
7: */
8: class Tracking extends \Opencart\System\Engine\Controller {
9: /**
10: * @return void
11: */
12: public function index(): void {
13: 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']))) {
14: $this->session->data['redirect'] = $this->url->link('account/tracking', 'language=' . $this->config->get('config_language'));
15:
16: $this->response->redirect($this->url->link('account/login', 'language=' . $this->config->get('config_language'), true));
17: }
18:
19: if (!$this->config->get('config_affiliate_status')) {
20: $this->response->redirect($this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'], true));
21: }
22:
23: $this->load->model('account/affiliate');
24:
25: $affiliate_info = $this->model_account_affiliate->getAffiliate($this->customer->getId());
26:
27: if (!$affiliate_info) {
28: $this->response->redirect($this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'], true));
29: }
30:
31: $this->load->language('account/tracking');
32:
33: $this->document->setTitle($this->language->get('heading_title'));
34:
35: $data['breadcrumbs'] = [];
36:
37: $data['breadcrumbs'][] = [
38: 'text' => $this->language->get('text_home'),
39: 'href' => $this->url->link('common/home', 'language=' . $this->config->get('config_language'))
40: ];
41:
42: $data['breadcrumbs'][] = [
43: 'text' => $this->language->get('text_account'),
44: 'href' => $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'])
45: ];
46:
47: $data['breadcrumbs'][] = [
48: 'text' => $this->language->get('heading_title'),
49: 'href' => $this->url->link('account/tracking', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token'])
50: ];
51:
52: $data['text_description'] = sprintf($this->language->get('text_description'), $this->config->get('config_name'));
53:
54: $data['code'] = $affiliate_info['tracking'];
55:
56: $data['continue'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language') . '&customer_token=' . $this->session->data['customer_token']);
57:
58: $data['language'] = $this->config->get('config_language');
59:
60: $data['customer_token'] = $this->session->data['customer_token'];
61:
62: $data['column_left'] = $this->load->controller('common/column_left');
63: $data['column_right'] = $this->load->controller('common/column_right');
64: $data['content_top'] = $this->load->controller('common/content_top');
65: $data['content_bottom'] = $this->load->controller('common/content_bottom');
66: $data['footer'] = $this->load->controller('common/footer');
67: $data['header'] = $this->load->controller('common/header');
68:
69: $this->response->setOutput($this->load->view('account/tracking', $data));
70: }
71:
72: /**
73: * Autocomplete
74: *
75: * @return void
76: */
77: public function autocomplete(): void {
78: $json = [];
79:
80: if (isset($this->request->get['search'])) {
81: $search = $this->request->get['search'];
82: } else {
83: $search = '';
84: }
85:
86: if (isset($this->request->get['tracking'])) {
87: $tracking = $this->request->get['tracking'];
88: } else {
89: $tracking = '';
90: }
91:
92: 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']))) {
93: $this->session->data['redirect'] = $this->url->link('account/password', 'language=' . $this->config->get('config_language'));
94:
95: $json['redirect'] = $this->url->link('account/login', 'language=' . $this->config->get('config_language'), true);
96: }
97:
98: if (!$json) {
99: $filter_data = [
100: 'filter_search' => $search,
101: 'start' => 0,
102: 'limit' => 5
103: ];
104:
105: $this->load->model('catalog/product');
106:
107: $results = $this->model_catalog_product->getProducts($filter_data);
108:
109: foreach ($results as $result) {
110: $json[] = [
111: 'name' => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')),
112: 'link' => str_replace('&amp;', '&', $this->url->link('product/product', 'language=' . $this->config->get('config_language') . '&product_id=' . $result['product_id'] . '&tracking=' . $tracking))
113: ];
114: }
115: }
116:
117: $this->response->addHeader('Content-Type: application/json');
118: $this->response->setOutput(json_encode($json));
119: }
120: }
121: