1: | <?php
|
2: | namespace Opencart\Admin\Controller\Catalog;
|
3: | |
4: | |
5: | |
6: | |
7: |
|
8: | class Information extends \Opencart\System\Engine\Controller {
|
9: | |
10: | |
11: | |
12: | |
13: |
|
14: | public function index(): void {
|
15: | $this->load->language('catalog/information');
|
16: |
|
17: | $this->document->setTitle($this->language->get('heading_title'));
|
18: |
|
19: | $url = '';
|
20: |
|
21: | if (isset($this->request->get['sort'])) {
|
22: | $url .= '&sort=' . $this->request->get['sort'];
|
23: | }
|
24: |
|
25: | if (isset($this->request->get['order'])) {
|
26: | $url .= '&order=' . $this->request->get['order'];
|
27: | }
|
28: |
|
29: | if (isset($this->request->get['page'])) {
|
30: | $url .= '&page=' . $this->request->get['page'];
|
31: | }
|
32: |
|
33: | $data['breadcrumbs'] = [];
|
34: |
|
35: | $data['breadcrumbs'][] = [
|
36: | 'text' => $this->language->get('text_home'),
|
37: | 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
38: | ];
|
39: |
|
40: | $data['breadcrumbs'][] = [
|
41: | 'text' => $this->language->get('heading_title'),
|
42: | 'href' => $this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'] . $url)
|
43: | ];
|
44: |
|
45: | $data['add'] = $this->url->link('catalog/information.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
46: | $data['delete'] = $this->url->link('catalog/information.delete', 'user_token=' . $this->session->data['user_token']);
|
47: |
|
48: | $data['list'] = $this->controller_catalog_information->getList();
|
49: |
|
50: | $data['user_token'] = $this->session->data['user_token'];
|
51: |
|
52: | $data['header'] = $this->load->controller('common/header');
|
53: | $data['column_left'] = $this->load->controller('common/column_left');
|
54: | $data['footer'] = $this->load->controller('common/footer');
|
55: |
|
56: | $this->response->setOutput($this->load->view('catalog/information', $data));
|
57: | }
|
58: |
|
59: | |
60: | |
61: | |
62: | |
63: |
|
64: | public function list(): void {
|
65: | $this->load->language('catalog/information');
|
66: |
|
67: | $this->response->setOutput($this->controller_catalog_information->getList());
|
68: | }
|
69: |
|
70: | |
71: | |
72: | |
73: | |
74: |
|
75: | protected function getList(): string {
|
76: | if (isset($this->request->get['sort'])) {
|
77: | $sort = (string)$this->request->get['sort'];
|
78: | } else {
|
79: | $sort = 'id.title';
|
80: | }
|
81: |
|
82: | if (isset($this->request->get['order'])) {
|
83: | $order = (string)$this->request->get['order'];
|
84: | } else {
|
85: | $order = 'ASC';
|
86: | }
|
87: |
|
88: | if (isset($this->request->get['page'])) {
|
89: | $page = (int)$this->request->get['page'];
|
90: | } else {
|
91: | $page = 1;
|
92: | }
|
93: |
|
94: | $url = '';
|
95: |
|
96: | if (isset($this->request->get['sort'])) {
|
97: | $url .= '&sort=' . $this->request->get['sort'];
|
98: | }
|
99: |
|
100: | if (isset($this->request->get['order'])) {
|
101: | $url .= '&order=' . $this->request->get['order'];
|
102: | }
|
103: |
|
104: | if (isset($this->request->get['page'])) {
|
105: | $url .= '&page=' . $this->request->get['page'];
|
106: | }
|
107: |
|
108: | $data['action'] = $this->url->link('catalog/information.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
109: |
|
110: | $data['informations'] = [];
|
111: |
|
112: | $filter_data = [
|
113: | 'sort' => $sort,
|
114: | 'order' => $order,
|
115: | 'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
116: | 'limit' => $this->config->get('config_pagination_admin')
|
117: | ];
|
118: |
|
119: | $this->load->model('catalog/information');
|
120: |
|
121: | $results = $this->model_catalog_information->getInformations($filter_data);
|
122: |
|
123: | foreach ($results as $result) {
|
124: | $data['informations'][] = [
|
125: | 'information_id' => $result['information_id'],
|
126: | 'title' => $result['title'],
|
127: | 'status' => $result['status'],
|
128: | 'sort_order' => $result['sort_order'],
|
129: | 'edit' => $this->url->link('catalog/information.form', 'user_token=' . $this->session->data['user_token'] . '&information_id=' . $result['information_id'] . $url)
|
130: | ];
|
131: | }
|
132: |
|
133: | $url = '';
|
134: |
|
135: | if ($order == 'ASC') {
|
136: | $url .= '&order=DESC';
|
137: | } else {
|
138: | $url .= '&order=ASC';
|
139: | }
|
140: |
|
141: | $data['sort_title'] = $this->url->link('catalog/information.list', 'user_token=' . $this->session->data['user_token'] . '&sort=id.title' . $url);
|
142: | $data['sort_sort_order'] = $this->url->link('catalog/information.list', 'user_token=' . $this->session->data['user_token'] . '&sort=i.sort_order' . $url);
|
143: |
|
144: | $url = '';
|
145: |
|
146: | if (isset($this->request->get['sort'])) {
|
147: | $url .= '&sort=' . $this->request->get['sort'];
|
148: | }
|
149: |
|
150: | if (isset($this->request->get['order'])) {
|
151: | $url .= '&order=' . $this->request->get['order'];
|
152: | }
|
153: |
|
154: | $information_total = $this->model_catalog_information->getTotalInformations();
|
155: |
|
156: | $data['pagination'] = $this->load->controller('common/pagination', [
|
157: | 'total' => $information_total,
|
158: | 'page' => $page,
|
159: | 'limit' => $this->config->get('config_pagination_admin'),
|
160: | 'url' => $this->url->link('catalog/information.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
161: | ]);
|
162: |
|
163: | $data['results'] = sprintf($this->language->get('text_pagination'), ($information_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($information_total - $this->config->get('config_pagination_admin'))) ? $information_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $information_total, ceil($information_total / $this->config->get('config_pagination_admin')));
|
164: |
|
165: | $data['sort'] = $sort;
|
166: | $data['order'] = $order;
|
167: |
|
168: | return $this->load->view('catalog/information_list', $data);
|
169: | }
|
170: |
|
171: | |
172: | |
173: | |
174: | |
175: |
|
176: | public function form(): void {
|
177: | $this->load->language('catalog/information');
|
178: |
|
179: | $this->document->setTitle($this->language->get('heading_title'));
|
180: |
|
181: | $this->document->addScript('view/javascript/ckeditor/ckeditor.js');
|
182: | $this->document->addScript('view/javascript/ckeditor/adapters/jquery.js');
|
183: |
|
184: | $data['text_form'] = !isset($this->request->get['information_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
185: |
|
186: | $url = '';
|
187: |
|
188: | if (isset($this->request->get['sort'])) {
|
189: | $url .= '&sort=' . $this->request->get['sort'];
|
190: | }
|
191: |
|
192: | if (isset($this->request->get['order'])) {
|
193: | $url .= '&order=' . $this->request->get['order'];
|
194: | }
|
195: |
|
196: | if (isset($this->request->get['page'])) {
|
197: | $url .= '&page=' . $this->request->get['page'];
|
198: | }
|
199: |
|
200: | $data['breadcrumbs'] = [];
|
201: |
|
202: | $data['breadcrumbs'][] = [
|
203: | 'text' => $this->language->get('text_home'),
|
204: | 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
205: | ];
|
206: |
|
207: | $data['breadcrumbs'][] = [
|
208: | 'text' => $this->language->get('heading_title'),
|
209: | 'href' => $this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'] . $url)
|
210: | ];
|
211: |
|
212: | $data['save'] = $this->url->link('catalog/information.save', 'user_token=' . $this->session->data['user_token']);
|
213: | $data['back'] = $this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'] . $url);
|
214: |
|
215: | if (isset($this->request->get['information_id'])) {
|
216: | $this->load->model('catalog/information');
|
217: |
|
218: | $information_info = $this->model_catalog_information->getInformation($this->request->get['information_id']);
|
219: | }
|
220: |
|
221: | if (isset($this->request->get['information_id'])) {
|
222: | $data['information_id'] = (int)$this->request->get['information_id'];
|
223: | } else {
|
224: | $data['information_id'] = 0;
|
225: | }
|
226: |
|
227: | $this->load->model('localisation/language');
|
228: |
|
229: | $data['languages'] = $this->model_localisation_language->getLanguages();
|
230: |
|
231: | if (isset($this->request->get['information_id'])) {
|
232: | $data['information_description'] = $this->model_catalog_information->getDescriptions($this->request->get['information_id']);
|
233: | } else {
|
234: | $data['information_description'] = [];
|
235: | }
|
236: |
|
237: | $data['stores'] = [];
|
238: |
|
239: | $data['stores'][] = [
|
240: | 'store_id' => 0,
|
241: | 'name' => $this->language->get('text_default')
|
242: | ];
|
243: |
|
244: | $this->load->model('setting/store');
|
245: |
|
246: | $stores = $this->model_setting_store->getStores();
|
247: |
|
248: | foreach ($stores as $store) {
|
249: | $data['stores'][] = [
|
250: | 'store_id' => $store['store_id'],
|
251: | 'name' => $store['name']
|
252: | ];
|
253: | }
|
254: |
|
255: | if (isset($this->request->get['information_id'])) {
|
256: | $data['information_store'] = $this->model_catalog_information->getStores($this->request->get['information_id']);
|
257: | } else {
|
258: | $data['information_store'] = [0];
|
259: | }
|
260: |
|
261: | if (!empty($information_info)) {
|
262: | $data['status'] = $information_info['status'];
|
263: | } else {
|
264: | $data['status'] = true;
|
265: | }
|
266: |
|
267: | if (!empty($information_info)) {
|
268: | $data['sort_order'] = $information_info['sort_order'];
|
269: | } else {
|
270: | $data['sort_order'] = '';
|
271: | }
|
272: |
|
273: | if (isset($this->request->get['information_id'])) {
|
274: | $this->load->model('design/seo_url');
|
275: |
|
276: | $data['information_seo_url'] = $this->model_design_seo_url->getSeoUrlsByKeyValue('information_id', $this->request->get['information_id']);
|
277: | } else {
|
278: | $data['information_seo_url'] = [];
|
279: | }
|
280: |
|
281: | $this->load->model('design/layout');
|
282: |
|
283: | $data['layouts'] = $this->model_design_layout->getLayouts();
|
284: |
|
285: | if (isset($this->request->get['information_id'])) {
|
286: | $data['information_layout'] = $this->model_catalog_information->getLayouts($this->request->get['information_id']);
|
287: | } else {
|
288: | $data['information_layout'] = [];
|
289: | }
|
290: |
|
291: | $data['user_token'] = $this->session->data['user_token'];
|
292: |
|
293: | $data['header'] = $this->load->controller('common/header');
|
294: | $data['column_left'] = $this->load->controller('common/column_left');
|
295: | $data['footer'] = $this->load->controller('common/footer');
|
296: |
|
297: | $this->response->setOutput($this->load->view('catalog/information_form', $data));
|
298: | }
|
299: |
|
300: | |
301: | |
302: | |
303: | |
304: |
|
305: | public function save(): void {
|
306: | $this->load->language('catalog/information');
|
307: |
|
308: | $json = [];
|
309: |
|
310: | if (!$this->user->hasPermission('modify', 'catalog/information')) {
|
311: | $json['error']['warning'] = $this->language->get('error_permission');
|
312: | }
|
313: |
|
314: | foreach ($this->request->post['information_description'] as $language_id => $value) {
|
315: | if (!oc_validate_length($value['title'], 1, 64)) {
|
316: | $json['error']['title_' . $language_id] = $this->language->get('error_title');
|
317: | }
|
318: |
|
319: | if (!oc_validate_length($value['meta_title'], 1, 255)) {
|
320: | $json['error']['meta_title_' . $language_id] = $this->language->get('error_meta_title');
|
321: | }
|
322: | }
|
323: |
|
324: | if ($this->request->post['information_seo_url']) {
|
325: | $this->load->model('design/seo_url');
|
326: |
|
327: | foreach ($this->request->post['information_seo_url'] as $store_id => $language) {
|
328: | foreach ($language as $language_id => $keyword) {
|
329: | if (!oc_validate_length($keyword, 1, 64)) {
|
330: | $json['error']['keyword_' . $store_id . '_' . $language_id] = $this->language->get('error_keyword');
|
331: | }
|
332: |
|
333: | if (!oc_validate_seo_url($keyword)) {
|
334: | $json['error']['keyword_' . $store_id . '_' . $language_id] = $this->language->get('error_keyword_character');
|
335: | }
|
336: |
|
337: | $seo_url_info = $this->model_design_seo_url->getSeoUrlByKeyword($keyword, $store_id);
|
338: |
|
339: | if ($seo_url_info && (!isset($this->request->post['information_id']) || $seo_url_info['key'] != 'information_id' || $seo_url_info['value'] != (int)$this->request->post['information_id'])) {
|
340: | $json['error']['keyword_' . $store_id . '_' . $language_id] = $this->language->get('error_keyword_exists');
|
341: | }
|
342: | }
|
343: | }
|
344: | }
|
345: |
|
346: | if (isset($json['error']) && !isset($json['error']['warning'])) {
|
347: | $json['error']['warning'] = $this->language->get('error_warning');
|
348: | }
|
349: |
|
350: | if (!$json) {
|
351: | $this->load->model('catalog/information');
|
352: |
|
353: | if (!$this->request->post['information_id']) {
|
354: | $json['information_id'] = $this->model_catalog_information->addInformation($this->request->post);
|
355: | } else {
|
356: | $this->model_catalog_information->editInformation($this->request->post['information_id'], $this->request->post);
|
357: | }
|
358: |
|
359: | $json['success'] = $this->language->get('text_success');
|
360: | }
|
361: |
|
362: | $this->response->addHeader('Content-Type: application/json');
|
363: | $this->response->setOutput(json_encode($json));
|
364: | }
|
365: |
|
366: | |
367: | |
368: | |
369: | |
370: |
|
371: | public function delete(): void {
|
372: | $this->load->language('catalog/information');
|
373: |
|
374: | $json = [];
|
375: |
|
376: | if (isset($this->request->post['selected'])) {
|
377: | $selected = $this->request->post['selected'];
|
378: | } else {
|
379: | $selected = [];
|
380: | }
|
381: |
|
382: | if (!$this->user->hasPermission('modify', 'catalog/information')) {
|
383: | $json['error'] = $this->language->get('error_permission');
|
384: | }
|
385: |
|
386: | $this->load->model('setting/store');
|
387: |
|
388: | foreach ($selected as $information_id) {
|
389: | if ($this->config->get('config_account_id') == $information_id) {
|
390: | $json['error'] = $this->language->get('error_account');
|
391: | }
|
392: |
|
393: | if ($this->config->get('config_checkout_id') == $information_id) {
|
394: | $json['error'] = $this->language->get('error_checkout');
|
395: | }
|
396: |
|
397: | if ($this->config->get('config_affiliate_id') == $information_id) {
|
398: | $json['error'] = $this->language->get('error_affiliate');
|
399: | }
|
400: |
|
401: | if ($this->config->get('config_return_id') == $information_id) {
|
402: | $json['error'] = $this->language->get('error_return');
|
403: | }
|
404: |
|
405: | $store_total = $this->model_setting_store->getTotalStoresByInformationId($information_id);
|
406: |
|
407: | if ($store_total) {
|
408: | $json['error'] = sprintf($this->language->get('error_store'), $store_total);
|
409: | }
|
410: | }
|
411: |
|
412: | if (!$json) {
|
413: | $this->load->model('catalog/information');
|
414: |
|
415: | foreach ($selected as $information_id) {
|
416: | $this->model_catalog_information->deleteInformation($information_id);
|
417: | }
|
418: |
|
419: | $json['success'] = $this->language->get('text_success');
|
420: | }
|
421: |
|
422: | $this->response->addHeader('Content-Type: application/json');
|
423: | $this->response->setOutput(json_encode($json));
|
424: | }
|
425: | }
|
426: | |