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

OpenCart API API documentation generated by ApiGen dev-master