1: <?php
2: namespace Opencart\Admin\Controller\Extension\Opencart\Module;
3: /**
4: * Class Featured
5: *
6: * @package Opencart\Admin\Controller\Extension\Opencart\Module
7: */
8: class Featured extends \Opencart\System\Engine\Controller {
9: /**
10: * Index
11: *
12: * @return void
13: */
14: public function index(): void {
15: $this->load->language('extension/opencart/module/featured');
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=module')
29: ];
30:
31: if (!isset($this->request->get['module_id'])) {
32: $data['breadcrumbs'][] = [
33: 'text' => $this->language->get('heading_title'),
34: 'href' => $this->url->link('extension/opencart/module/featured', 'user_token=' . $this->session->data['user_token'])
35: ];
36: } else {
37: $data['breadcrumbs'][] = [
38: 'text' => $this->language->get('heading_title'),
39: 'href' => $this->url->link('extension/opencart/module/featured', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'])
40: ];
41: }
42:
43: if (!isset($this->request->get['module_id'])) {
44: $data['save'] = $this->url->link('extension/opencart/module/featured.save', 'user_token=' . $this->session->data['user_token']);
45: } else {
46: $data['save'] = $this->url->link('extension/opencart/module/featured.save', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id']);
47: }
48:
49: $data['back'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module');
50:
51: if (isset($this->request->get['module_id'])) {
52: $this->load->model('setting/module');
53:
54: $module_info = $this->model_setting_module->getModule($this->request->get['module_id']);
55: }
56:
57: if (isset($module_info['name'])) {
58: $data['name'] = $module_info['name'];
59: } else {
60: $data['name'] = '';
61: }
62:
63: $this->load->model('catalog/product');
64:
65: $data['products'] = [];
66:
67: if (!empty($module_info['product'])) {
68: $products = $module_info['product'];
69: } else {
70: $products = [];
71: }
72:
73: foreach ($products as $product_id) {
74: $product_info = $this->model_catalog_product->getProduct($product_id);
75:
76: if ($product_info) {
77: $data['products'][] = [
78: 'product_id' => $product_info['product_id'],
79: 'name' => $product_info['name']
80: ];
81: }
82: }
83:
84: if (!empty($module_info['axis'])) {
85: $data['axis'] = $module_info['axis'];
86: } else {
87: $data['axis'] = '';
88: }
89:
90: if (isset($module_info['width'])) {
91: $data['width'] = $module_info['width'];
92: } else {
93: $data['width'] = 200;
94: }
95:
96: if (isset($module_info['height'])) {
97: $data['height'] = $module_info['height'];
98: } else {
99: $data['height'] = 200;
100: }
101:
102: if (isset($module_info['status'])) {
103: $data['status'] = $module_info['status'];
104: } else {
105: $data['status'] = '';
106: }
107:
108: if (isset($this->request->get['module_id'])) {
109: $data['module_id'] = (int)$this->request->get['module_id'];
110: } else {
111: $data['module_id'] = 0;
112: }
113:
114: $data['user_token'] = $this->session->data['user_token'];
115:
116: $data['header'] = $this->load->controller('common/header');
117: $data['column_left'] = $this->load->controller('common/column_left');
118: $data['footer'] = $this->load->controller('common/footer');
119:
120: $this->response->setOutput($this->load->view('extension/opencart/module/featured', $data));
121: }
122:
123: /**
124: * Save
125: *
126: * @return void
127: */
128: public function save(): void {
129: $this->load->language('extension/opencart/module/featured');
130:
131: $json = [];
132:
133: if (!$this->user->hasPermission('modify', 'extension/opencart/module/featured')) {
134: $json['error']['warning'] = $this->language->get('error_permission');
135: }
136:
137: if ((oc_strlen($this->request->post['name']) < 3) || (oc_strlen($this->request->post['name']) > 64)) {
138: $json['error']['name'] = $this->language->get('error_name');
139: }
140:
141: if (!$this->request->post['width']) {
142: $json['error']['width'] = $this->language->get('error_width');
143: }
144:
145: if (!$this->request->post['height']) {
146: $json['error']['height'] = $this->language->get('error_height');
147: }
148:
149: if (!$json) {
150: $this->load->model('setting/module');
151:
152: if (!$this->request->post['module_id']) {
153: $json['module_id'] = $this->model_setting_module->addModule('opencart.featured', $this->request->post);
154: } else {
155: $this->model_setting_module->editModule($this->request->post['module_id'], $this->request->post);
156: }
157:
158: $json['success'] = $this->language->get('text_success');
159: }
160:
161: $this->response->addHeader('Content-Type: application/json');
162: $this->response->setOutput(json_encode($json));
163: }
164: }
165: