1: <?php
2: namespace Opencart\Admin\Controller\Extension\Opencart\Module;
3: /**
4: * Class Special
5: *
6: * @package Opencart\Admin\Controller\Extension\Opencart\Module
7: */
8: class Special 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/special');
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/special', '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/special', '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/special.save', 'user_token=' . $this->session->data['user_token']);
45: } else {
46: $data['save'] = $this->url->link('extension/opencart/module/special.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: if (isset($module_info['axis'])) {
64: $data['axis'] = $module_info['axis'];
65: } else {
66: $data['axis'] = '';
67: }
68:
69: if (isset($module_info['limit'])) {
70: $data['limit'] = $module_info['limit'];
71: } else {
72: $data['limit'] = 5;
73: }
74:
75: if (isset($module_info['width'])) {
76: $data['width'] = $module_info['width'];
77: } else {
78: $data['width'] = 200;
79: }
80:
81: if (isset($module_info['height'])) {
82: $data['height'] = $module_info['height'];
83: } else {
84: $data['height'] = 200;
85: }
86:
87: if (isset($module_info['status'])) {
88: $data['status'] = $module_info['status'];
89: } else {
90: $data['status'] = '';
91: }
92:
93: if (isset($this->request->get['module_id'])) {
94: $data['module_id'] = (int)$this->request->get['module_id'];
95: } else {
96: $data['module_id'] = 0;
97: }
98:
99: $data['header'] = $this->load->controller('common/header');
100: $data['column_left'] = $this->load->controller('common/column_left');
101: $data['footer'] = $this->load->controller('common/footer');
102:
103: $this->response->setOutput($this->load->view('extension/opencart/module/special', $data));
104: }
105:
106: /**
107: * Save
108: *
109: * @return void
110: */
111: public function save(): void {
112: $this->load->language('extension/opencart/module/special');
113:
114: $json = [];
115:
116: if (!$this->user->hasPermission('modify', 'extension/opencart/module/special')) {
117: $json['error']['warning'] = $this->language->get('error_permission');
118: }
119:
120: if ((oc_strlen($this->request->post['name']) < 3) || (oc_strlen($this->request->post['name']) > 64)) {
121: $json['error']['name'] = $this->language->get('error_name');
122: }
123:
124: if (!$this->request->post['width']) {
125: $json['error']['width'] = $this->language->get('error_width');
126: }
127:
128: if (!$this->request->post['height']) {
129: $json['error']['height'] = $this->language->get('error_height');
130: }
131:
132: if (!$json) {
133: $this->load->model('setting/module');
134:
135: if (!$this->request->post['module_id']) {
136: $json['module_id'] = $this->model_setting_module->addModule('opencart.special', $this->request->post);
137: } else {
138: $this->model_setting_module->editModule($this->request->post['module_id'], $this->request->post);
139: }
140:
141: $this->cache->delete('product');
142:
143: $json['success'] = $this->language->get('text_success');
144: }
145:
146: $this->response->addHeader('Content-Type: application/json');
147: $this->response->setOutput(json_encode($json));
148: }
149: }
150: