ControllerCatalogManufacturer   F
last analyzed

Complexity

Total Complexity 102

Size/Duplication

Total Lines 606
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 356
c 0
b 0
f 0
dl 0
loc 606
rs 2
wmc 102

9 Methods

Rating   Name   Duplication   Size   Complexity  
F getForm() 0 239 40
A autocomplete() 0 33 4
F getList() 0 153 17
A validateDelete() 0 17 4
A index() 0 9 1
D validateForm() 0 40 17
A edit() 0 31 6
A add() 0 31 6
B delete() 0 33 7

How to fix   Complexity   

Complex Class

Complex classes like ControllerCatalogManufacturer often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ControllerCatalogManufacturer, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/* 	Divine CMS - Open source CMS for widespread use.
4
    Copyright (c) 2019 Mykola Burakov ([email protected])
5
6
    See SOURCE.txt for other and additional information.
7
8
    This file is part of Divine CMS.
9
10
    This program is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
12
    the Free Software Foundation, either version 3 of the License, or
13
    (at your option) any later version.
14
15
    This program is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
    GNU General Public License for more details.
19
20
    You should have received a copy of the GNU General Public License
21
    along with this program. If not, see <http://www.gnu.org/licenses/>. */
22
23
class ControllerCatalogManufacturer extends \Divine\Engine\Core\Controller
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
24
{
25
    private $error = array();
26
27
    public function index()
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
28
    {
29
        $this->load->language('catalog/manufacturer');
30
31
        $this->document->setTitle($this->language->get('heading_title'));
32
33
        $this->load->model('catalog/manufacturer');
34
35
        $this->getList();
36
    }
37
38
    public function add()
39
    {
40
        $this->load->language('catalog/manufacturer');
41
42
        $this->document->setTitle($this->language->get('heading_title'));
43
44
        $this->load->model('catalog/manufacturer');
45
46
        if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
47
            $this->model_catalog_manufacturer->addManufacturer($this->request->post);
48
49
            $this->session->data['success'] = $this->language->get('text_success');
50
51
            $url = '';
52
53
            if (isset($this->request->get['sort'])) {
54
                $url .= '&sort=' . $this->request->get['sort'];
55
            }
56
57
            if (isset($this->request->get['order'])) {
58
                $url .= '&order=' . $this->request->get['order'];
59
            }
60
61
            if (isset($this->request->get['page'])) {
62
                $url .= '&page=' . $this->request->get['page'];
63
            }
64
65
            $this->response->redirect($this->url->link('catalog/manufacturer', 'token=' . $this->session->data['token'] . $url, true));
66
        }
67
68
        $this->getForm();
69
    }
70
71
    public function edit()
72
    {
73
        $this->load->language('catalog/manufacturer');
74
75
        $this->document->setTitle($this->language->get('heading_title'));
76
77
        $this->load->model('catalog/manufacturer');
78
79
        if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
80
            $this->model_catalog_manufacturer->editManufacturer($this->request->get['manufacturer_id'], $this->request->post);
81
82
            $this->session->data['success'] = $this->language->get('text_success');
83
84
            $url = '';
85
86
            if (isset($this->request->get['sort'])) {
87
                $url .= '&sort=' . $this->request->get['sort'];
88
            }
89
90
            if (isset($this->request->get['order'])) {
91
                $url .= '&order=' . $this->request->get['order'];
92
            }
93
94
            if (isset($this->request->get['page'])) {
95
                $url .= '&page=' . $this->request->get['page'];
96
            }
97
98
            $this->response->redirect($this->url->link('catalog/manufacturer', 'token=' . $this->session->data['token'] . $url, true));
99
        }
100
101
        $this->getForm();
102
    }
103
104
    public function delete()
105
    {
106
        $this->load->language('catalog/manufacturer');
107
108
        $this->document->setTitle($this->language->get('heading_title'));
109
110
        $this->load->model('catalog/manufacturer');
111
112
        if (isset($this->request->post['selected']) && $this->validateDelete()) {
113
            foreach ($this->request->post['selected'] as $manufacturer_id) {
114
                $this->model_catalog_manufacturer->deleteManufacturer($manufacturer_id);
115
            }
116
117
            $this->session->data['success'] = $this->language->get('text_success');
118
119
            $url = '';
120
121
            if (isset($this->request->get['sort'])) {
122
                $url .= '&sort=' . $this->request->get['sort'];
123
            }
124
125
            if (isset($this->request->get['order'])) {
126
                $url .= '&order=' . $this->request->get['order'];
127
            }
128
129
            if (isset($this->request->get['page'])) {
130
                $url .= '&page=' . $this->request->get['page'];
131
            }
132
133
            $this->response->redirect($this->url->link('catalog/manufacturer', 'token=' . $this->session->data['token'] . $url, true));
134
        }
135
136
        $this->getList();
137
    }
138
139
    protected function getList()
140
    {
141
        if (isset($this->request->get['sort'])) {
142
            $sort = $this->request->get['sort'];
143
        } else {
144
            $sort = 'name';
145
        }
146
147
        if (isset($this->request->get['order'])) {
148
            $order = $this->request->get['order'];
149
        } else {
150
            $order = 'ASC';
151
        }
152
153
        if (isset($this->request->get['page'])) {
154
            $page = $this->request->get['page'];
155
        } else {
156
            $page = 1;
157
        }
158
159
        $url = '';
160
161
        if (isset($this->request->get['sort'])) {
162
            $url .= '&sort=' . $this->request->get['sort'];
163
        }
164
165
        if (isset($this->request->get['order'])) {
166
            $url .= '&order=' . $this->request->get['order'];
167
        }
168
169
        if (isset($this->request->get['page'])) {
170
            $url .= '&page=' . $this->request->get['page'];
171
        }
172
173
        $data['breadcrumbs'] = array();
0 ignored issues
show
Comprehensibility Best Practice introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.
Loading history...
174
175
        $data['breadcrumbs'][] = array(
176
            'text' => $this->language->get('text_home'),
177
            'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], true)
178
        );
179
180
        $data['breadcrumbs'][] = array(
181
            'text' => $this->language->get('heading_title'),
182
            'href' => $this->url->link('catalog/manufacturer', 'token=' . $this->session->data['token'] . $url, true)
183
        );
184
185
        $data['add'] = $this->url->link('catalog/manufacturer/add', 'token=' . $this->session->data['token'] . $url, true);
186
        $data['delete'] = $this->url->link('catalog/manufacturer/delete', 'token=' . $this->session->data['token'] . $url, true);
187
188
        $data['manufacturers'] = array();
189
190
        $filter_data = array(
191
            'sort'  => $sort,
192
            'order' => $order,
193
            'start' => ($page - 1) * $this->config->get('config_limit_admin'),
194
            'limit' => $this->config->get('config_limit_admin')
195
        );
196
197
        $manufacturer_total = $this->model_catalog_manufacturer->getTotalManufacturers();
198
199
        $results = $this->model_catalog_manufacturer->getManufacturers($filter_data);
200
201
        foreach ($results as $result) {
202
            $data['manufacturers'][] = array(
203
                'manufacturer_id' => $result['manufacturer_id'],
204
                'name'            => $result['name'],
205
                'sort_order'      => $result['sort_order'],
206
                'noindex'              => $result['noindex'],
207
                'href_shop'        => '/index.php?route=product/manufacturer/info&manufacturer_id=' . ($result['manufacturer_id']),
208
                'edit'            => $this->url->link('catalog/manufacturer/edit', 'token=' . $this->session->data['token'] . '&manufacturer_id=' . $result['manufacturer_id'] . $url, true)
209
            );
210
        }
211
212
        $data['heading_title'] = $this->language->get('heading_title');
213
214
        $data['text_list'] = $this->language->get('text_list');
215
        $data['text_no_results'] = $this->language->get('text_no_results');
216
        $data['text_confirm'] = $this->language->get('text_confirm');
217
218
        $data['column_name'] = $this->language->get('column_name');
219
        $data['column_sort_order'] = $this->language->get('column_sort_order');
220
        $data['column_noindex'] = $this->language->get('column_noindex');
221
        $data['column_action'] = $this->language->get('column_action');
222
223
        $data['button_add'] = $this->language->get('button_add');
224
        $data['button_edit'] = $this->language->get('button_edit');
225
        $data['button_shop'] = $this->language->get('button_shop');
226
        $data['button_delete'] = $this->language->get('button_delete');
227
228
        if (isset($this->error['warning'])) {
229
            $data['error_warning'] = $this->error['warning'];
230
        } else {
231
            $data['error_warning'] = '';
232
        }
233
234
        if (isset($this->session->data['success'])) {
235
            $data['success'] = $this->session->data['success'];
236
237
            unset($this->session->data['success']);
238
        } else {
239
            $data['success'] = '';
240
        }
241
242
        if (isset($this->request->post['selected'])) {
243
            $data['selected'] = (array) $this->request->post['selected'];
244
        } else {
245
            $data['selected'] = array();
246
        }
247
248
        $url = '';
249
250
        if ($order == 'ASC') {
251
            $url .= '&order=DESC';
252
        } else {
253
            $url .= '&order=ASC';
254
        }
255
256
        if (isset($this->request->get['page'])) {
257
            $url .= '&page=' . $this->request->get['page'];
258
        }
259
260
        $data['sort_name'] = $this->url->link('catalog/manufacturer', 'token=' . $this->session->data['token'] . '&sort=name' . $url, true);
261
        $data['sort_sort_order'] = $this->url->link('catalog/manufacturer', 'token=' . $this->session->data['token'] . '&sort=sort_order' . $url, true);
262
        $data['sort_noindex'] = $this->url->link('catalog/manufacturer', 'token=' . $this->session->data['token'] . '&sort=noindex' . $url, true);
263
264
        $url = '';
265
266
        if (isset($this->request->get['sort'])) {
267
            $url .= '&sort=' . $this->request->get['sort'];
268
        }
269
270
        if (isset($this->request->get['order'])) {
271
            $url .= '&order=' . $this->request->get['order'];
272
        }
273
274
        $pagination = new \Divine\Engine\Library\Pagination();
275
        $pagination->total = $manufacturer_total;
276
        $pagination->page = $page;
277
        $pagination->limit = $this->config->get('config_limit_admin');
278
        $pagination->url = $this->url->link('catalog/manufacturer', 'token=' . $this->session->data['token'] . $url . '&page={page}', true);
279
280
        $data['pagination'] = $pagination->render();
281
282
        $data['results'] = sprintf($this->language->get('text_pagination'), ($manufacturer_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($manufacturer_total - $this->config->get('config_limit_admin'))) ? $manufacturer_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $manufacturer_total, ceil($manufacturer_total / $this->config->get('config_limit_admin')));
283
284
        $data['sort'] = $sort;
285
        $data['order'] = $order;
286
287
        $data['header'] = $this->load->controller('common/header');
288
        $data['column'] = $this->load->controller('common/column_left');
289
        $data['footer'] = $this->load->controller('common/footer');
290
291
        $this->response->setOutput($this->load->view('catalog/manufacturer_list', $data));
292
    }
293
294
    protected function getForm()
295
    {
296
        $data['heading_title'] = $this->language->get('heading_title');
0 ignored issues
show
Comprehensibility Best Practice introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.
Loading history...
297
298
        $data['text_form'] = !isset($this->request->get['manufacturer_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
299
        $data['text_enabled'] = $this->language->get('text_enabled');
300
        $data['text_disabled'] = $this->language->get('text_disabled');
301
        $data['text_default'] = $this->language->get('text_default');
302
        $data['text_percent'] = $this->language->get('text_percent');
303
        $data['text_amount'] = $this->language->get('text_amount');
304
305
        $data['entry_name'] = $this->language->get('entry_name');
306
        $data['entry_description'] = $this->language->get('entry_description');
307
        $data['entry_description_bottom'] = $this->language->get('entry_description_bottom');
308
        $data['entry_meta_title'] = $this->language->get('entry_meta_title');
309
        $data['entry_meta_h1'] = $this->language->get('entry_meta_h1');
310
        $data['entry_meta_description'] = $this->language->get('entry_meta_description');
311
        $data['entry_keyword'] = $this->language->get('entry_keyword');
312
        $data['entry_image'] = $this->language->get('entry_image');
313
        $data['entry_sort_order'] = $this->language->get('entry_sort_order');
314
        $data['entry_noindex'] = $this->language->get('entry_noindex');
315
        $data['entry_customer_group'] = $this->language->get('entry_customer_group');
316
        $data['entry_layout'] = $this->language->get('entry_layout');
317
        $data['entry_related_mn'] = $this->language->get('entry_related_mn');
318
        $data['entry_related_article'] = $this->language->get('entry_related_article');
319
320
        $data['help_keyword'] = $this->language->get('help_keyword');
321
        $data['help_noindex'] = $this->language->get('help_noindex');
322
323
        $data['button_save'] = $this->language->get('button_save');
324
        $data['button_cancel'] = $this->language->get('button_cancel');
325
326
        $data['tab_general'] = $this->language->get('tab_general');
327
        $data['tab_data'] = $this->language->get('tab_data');
328
        $data['tab_related'] = $this->language->get('tab_related');
329
        $data['tab_design'] = $this->language->get('tab_design');
330
331
        if (isset($this->error['warning'])) {
332
            $data['error_warning'] = $this->error['warning'];
333
        } else {
334
            $data['error_warning'] = '';
335
        }
336
337
        if (isset($this->error['name'])) {
338
            $data['error_name'] = $this->error['name'];
339
        } else {
340
            $data['error_name'] = '';
341
        }
342
343
        if (isset($this->error['meta_title'])) {
344
            $data['error_meta_title'] = $this->error['meta_title'];
345
        } else {
346
            $data['error_meta_title'] = array();
347
        }
348
349
        if (isset($this->error['meta_h1'])) {
350
            $data['error_meta_h1'] = $this->error['meta_h1'];
351
        } else {
352
            $data['error_meta_h1'] = array();
353
        }
354
355
        if (isset($this->error['keyword'])) {
356
            $data['error_keyword'] = $this->error['keyword'];
357
        } else {
358
            $data['error_keyword'] = '';
359
        }
360
361
        $url = '';
362
363
        if (isset($this->request->get['sort'])) {
364
            $url .= '&sort=' . $this->request->get['sort'];
365
        }
366
367
        if (isset($this->request->get['order'])) {
368
            $url .= '&order=' . $this->request->get['order'];
369
        }
370
371
        if (isset($this->request->get['page'])) {
372
            $url .= '&page=' . $this->request->get['page'];
373
        }
374
375
        $data['breadcrumbs'] = array();
376
377
        $data['breadcrumbs'][] = array(
378
            'text' => $this->language->get('text_home'),
379
            'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], true)
380
        );
381
382
        $data['breadcrumbs'][] = array(
383
            'text' => $this->language->get('heading_title'),
384
            'href' => $this->url->link('catalog/manufacturer', 'token=' . $this->session->data['token'] . $url, true)
385
        );
386
387
        if (!isset($this->request->get['manufacturer_id'])) {
388
            $data['action'] = $this->url->link('catalog/manufacturer/add', 'token=' . $this->session->data['token'] . $url, true);
389
        } else {
390
            $data['action'] = $this->url->link('catalog/manufacturer/edit', 'token=' . $this->session->data['token'] . '&manufacturer_id=' . $this->request->get['manufacturer_id'] . $url, true);
391
        }
392
393
        $data['cancel'] = $this->url->link('catalog/manufacturer', 'token=' . $this->session->data['token'] . $url, true);
394
395
        if (isset($this->request->get['manufacturer_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
396
            $manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($this->request->get['manufacturer_id']);
397
        }
398
399
        $data['token'] = $this->session->data['token'];
400
401
        $this->load->model('localisation/language');
402
        $data['languages'] = $this->model_localisation_language->getLanguages();
403
404
        if (isset($this->request->post['manufacturer_description'])) {
405
            $data['manufacturer_description'] = $this->request->post['manufacturer_description'];
406
        } elseif (isset($this->request->get['manufacturer_id'])) {
407
            $data['manufacturer_description'] = $this->model_catalog_manufacturer->getManufacturerDescriptions($this->request->get['manufacturer_id']);
408
        } else {
409
            $data['manufacturer_description'] = array();
410
        }
411
412
        if (isset($this->request->post['name'])) {
413
            $data['name'] = $this->request->post['name'];
414
        } elseif (!empty($manufacturer_info)) {
415
            $data['name'] = $manufacturer_info['name'];
416
        } else {
417
            $data['name'] = '';
418
        }
419
420
        if (!empty($manufacturer_info)) {
421
            $data['heading_title'] = $data['name'] = $manufacturer_info['name'];
422
        } else {
423
            $data['heading_title'] = $this->language->get('heading_title');
424
        }
425
426
        if (isset($this->request->post['keyword'])) {
427
            $data['keyword'] = $this->request->post['keyword'];
428
        } elseif (!empty($manufacturer_info)) {
429
            $data['keyword'] = $manufacturer_info['keyword'];
430
        } else {
431
            $data['keyword'] = '';
432
        }
433
434
        if (isset($this->request->post['image'])) {
435
            $data['image'] = $this->request->post['image'];
436
        } elseif (!empty($manufacturer_info)) {
437
            $data['image'] = $manufacturer_info['image'];
438
        } else {
439
            $data['image'] = '';
440
        }
441
442
443
444
        if (isset($this->request->post['image']) && is_file($_SERVER['DOCUMENT_ROOT'] . '/public_html/assets/images/' . $this->request->post['image'])) {
445
            $data['thumb'] = '/public_html/assets/images/' . $this->request->post['image'];
446
        } elseif (!empty($manufacturer_info) && is_file($_SERVER['DOCUMENT_ROOT'] . '/public_html/assets/images/' . $manufacturer_info['image'])) {
447
            $data['thumb'] = '/public_html/assets/images/' . $manufacturer_info['image'];
448
        } else {
449
            $data['thumb'] = '/public_html/assets/images/no_image.png';
450
        }
451
452
        $data['placeholder'] = '/public_html/assets/images/no_image.png';
453
454
        if (isset($this->request->post['noindex'])) {
455
            $data['noindex'] = $this->request->post['noindex'];
456
        } elseif (!empty($manufacturer_info)) {
457
            $data['noindex'] = $manufacturer_info['noindex'];
458
        } else {
459
            $data['noindex'] = 1;
460
        }
461
462
        if (isset($this->request->post['manufacturer_layout'])) {
463
            $data['manufacturer_layout'] = $this->request->post['manufacturer_layout'];
464
        } elseif (isset($this->request->get['manufacturer_id'])) {
465
            $data['manufacturer_layout'] = $this->model_catalog_manufacturer->getManufacturerLayouts($this->request->get['manufacturer_id']);
466
        } else {
467
            $data['manufacturer_layout'] = array();
468
        }
469
470
        $this->load->model('design/layout');
471
472
        $data['layouts'] = $this->model_design_layout->getLayouts();
473
474
        if (isset($this->request->post['sort_order'])) {
475
            $data['sort_order'] = $this->request->post['sort_order'];
476
        } elseif (!empty($manufacturer_info)) {
477
            $data['sort_order'] = $manufacturer_info['sort_order'];
478
        } else {
479
            $data['sort_order'] = '';
480
        }
481
482
        if (isset($this->request->post['product_related'])) {
483
            $products = $this->request->post['product_related'];
484
        } elseif (isset($manufacturer_info)) {
485
            $products = $this->model_catalog_manufacturer->getProductRelated($this->request->get['manufacturer_id']);
486
        } else {
487
            $products = array();
488
        }
489
490
        $data['product_related'] = array();
491
492
        $this->load->model('catalog/product');
493
494
        foreach ($products as $product_id) {
495
            $related_info = $this->model_catalog_product->getProduct($product_id);
496
497
            if ($related_info) {
498
                $data['product_related'][] = array(
499
                    'product_id' => $related_info['product_id'],
500
                    'name'       => $related_info['name']
501
                );
502
            }
503
        }
504
505
        if (isset($this->request->post['article_related'])) {
506
            $articles = $this->request->post['article_related'];
507
        } elseif (isset($manufacturer_info)) {
508
            $articles = $this->model_catalog_manufacturer->getArticleRelated($this->request->get['manufacturer_id']);
509
        } else {
510
            $articles = array();
511
        }
512
513
        $data['article_related'] = array();
514
515
        $this->load->model('blog/article');
516
517
        foreach ($articles as $article_id) {
518
            $related_info = $this->model_blog_article->getArticle($article_id);
519
520
            if ($related_info) {
521
                $data['article_related'][] = array(
522
                    'article_id' => $related_info['article_id'],
523
                    'name'       => $related_info['name']
524
                );
525
            }
526
        }
527
528
        $data['header'] = $this->load->controller('common/header');
529
        $data['column'] = $this->load->controller('common/column_left');
530
        $data['footer'] = $this->load->controller('common/footer');
531
532
        $this->response->setOutput($this->load->view('catalog/manufacturer_form', $data));
533
    }
534
535
    protected function validateForm()
536
    {
537
        if (!$this->user->hasPermission('modify', 'catalog/manufacturer')) {
538
            $this->error['warning'] = $this->language->get('error_permission');
539
        }
540
541
        if ((\voku\helper\UTF8::strlen($this->request->post['name']) < 2) || (\voku\helper\UTF8::strlen($this->request->post['name']) > 64)) {
542
            $this->error['name'] = $this->language->get('error_name');
543
        }
544
545
        foreach ($this->request->post['manufacturer_description'] as $language_id => $value) {
546
            if ((\voku\helper\UTF8::strlen($value['meta_title']) < 0) || (\voku\helper\UTF8::strlen($value['meta_title']) > 255)) {
547
                $this->error['meta_title'][$language_id] = $this->language->get('error_meta_title');
548
                $this->error['warning'] = $this->language->get('error_warning');
549
            }
550
551
            if ((\voku\helper\UTF8::strlen($value['meta_h1']) < 0) || (\voku\helper\UTF8::strlen($value['meta_h1']) > 255)) {
552
                $this->error['meta_h1'][$language_id] = $this->language->get('error_meta_h1');
553
                $this->error['warning'] = $this->language->get('error_warning');
554
            }
555
        }
556
        if ($this->error && !isset($this->error['warning'])) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->error of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
557
            $this->error['warning'] = $this->language->get('error_warning');
558
        }
559
560
        if (\voku\helper\UTF8::strlen($this->request->post['keyword']) > 0) {
561
            $this->load->model('catalog/url_alias');
562
563
            $url_alias_info = $this->model_catalog_url_alias->getUrlAlias($this->request->post['keyword']);
564
565
            if ($url_alias_info && isset($this->request->get['manufacturer_id']) && $url_alias_info['query'] != 'manufacturer_id=' . $this->request->get['manufacturer_id']) {
566
                $this->error['keyword'] = sprintf($this->language->get('error_keyword'));
567
            }
568
569
            if ($url_alias_info && !isset($this->request->get['manufacturer_id'])) {
570
                $this->error['keyword'] = sprintf($this->language->get('error_keyword'));
571
            }
572
        }
573
574
        return !$this->error;
575
    }
576
577
    protected function validateDelete()
578
    {
579
        if (!$this->user->hasPermission('modify', 'catalog/manufacturer')) {
580
            $this->error['warning'] = $this->language->get('error_permission');
581
        }
582
583
        $this->load->model('catalog/product');
584
585
        foreach ($this->request->post['selected'] as $manufacturer_id) {
586
            $product_total = $this->model_catalog_product->getTotalProductsByManufacturerId($manufacturer_id);
587
588
            if ($product_total) {
589
                $this->error['warning'] = sprintf($this->language->get('error_product'), $product_total);
590
            }
591
        }
592
593
        return !$this->error;
594
    }
595
596
    public function autocomplete()
597
    {
598
        $json = array();
599
600
        if (isset($this->request->get['filter_name'])) {
601
            $this->load->model('catalog/manufacturer');
602
603
            $filter_data = array(
604
                'filter_name' => $this->request->get['filter_name'],
605
                'start'       => 0,
606
                'limit'       => 5
607
            );
608
609
            $results = $this->model_catalog_manufacturer->getManufacturers($filter_data);
610
611
            foreach ($results as $result) {
612
                $json[] = array(
613
                    'manufacturer_id' => $result['manufacturer_id'],
614
                    'name'            => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8'))
615
                );
616
            }
617
        }
618
619
        $sort_order = array();
620
621
        foreach ($json as $key => $value) {
622
            $sort_order[$key] = $value['name'];
623
        }
624
625
        array_multisort($sort_order, SORT_ASC, $json);
626
627
        $this->response->addHeader('Content-Type: application/json');
628
        $this->response->setOutput(json_encode($json));
629
    }
630
}
631