1: | <?php
2: | namespace Opencart\Catalog\Controller\Extension\Opencart\Module;
3: | /**
4: | * Class Filter
5: | *
6: | * @package Opencart\Catalog\Controller\Extension\Opencart\Module
7: | */
8: | class Filter extends \Opencart\System\Engine\Controller {
9: | /**
10: | * Index
11: | *
12: | * @return string
13: | */
14: | public function index(): string {
15: | if (isset($this->request->get['path'])) {
16: | $parts = explode('_', (string)$this->request->get['path']);
17: | } else {
18: | $parts = [];
19: | }
20: |
21: | $category_id = (int)end($parts);
22: |
23: | $this->load->model('catalog/category');
24: |
25: | $category_info = $this->model_catalog_category->getCategory($category_id);
26: |
27: | if ($category_info) {
28: | $this->load->language('extension/opencart/module/filter');
29: |
30: | $url = '';
31: |
32: | if (isset($this->request->get['sort'])) {
33: | $url .= '&sort=' . $this->request->get['sort'];
34: | }
35: |
36: | if (isset($this->request->get['order'])) {
37: | $url .= '&order=' . $this->request->get['order'];
38: | }
39: |
40: | if (isset($this->request->get['limit'])) {
41: | $url .= '&limit=' . $this->request->get['limit'];
42: | }
43: |
44: | $data['action'] = str_replace('&amp;', '&', $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&path=' . $this->request->get['path'] . $url));
45: |
46: | if (isset($this->request->get['filter'])) {
47: | $data['filter_category'] = explode(',', $this->request->get['filter']);
48: | } else {
49: | $data['filter_category'] = [];
50: | }
51: |
52: | $this->load->model('catalog/product');
53: |
54: | $data['filter_groups'] = [];
55: |
56: | $filter_groups = $this->model_catalog_category->getFilters($category_id);
57: |
58: | if ($filter_groups) {
59: | foreach ($filter_groups as $filter_group) {
60: | $children_data = [];
61: |
62: | foreach ($filter_group['filter'] as $filter) {
63: | $filter_data = [
64: | 'filter_category_id' => $category_id,
65: | 'filter_filter' => $filter['filter_id']
66: | ];
67: |
68: | $children_data[] = [
69: | 'filter_id' => $filter['filter_id'],
70: | 'name' => $filter['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : '')
71: | ];
72: | }
73: |
74: | $data['filter_groups'][] = [
75: | 'filter_group_id' => $filter_group['filter_group_id'],
76: | 'name' => $filter_group['name'],
77: | 'filter' => $children_data
78: | ];
79: | }
80: |
81: | return $this->load->view('extension/opencart/module/filter', $data);
82: | }
83: | }
84: |
85: | return '';
86: | }
87: | }
88: |

OpenCart API API documentation generated by ApiGen dev-master