1: | <?php
|
2: | namespace Opencart\Catalog\Controller\Common;
|
3: | |
4: | |
5: | |
6: | |
7: |
|
8: | class Menu extends \Opencart\System\Engine\Controller {
|
9: | |
10: | |
11: |
|
12: | public function index(): string {
|
13: | $this->load->language('common/menu');
|
14: |
|
15: |
|
16: | $this->load->model('catalog/category');
|
17: |
|
18: | $this->load->model('catalog/product');
|
19: |
|
20: | $data['categories'] = [];
|
21: |
|
22: | $categories = $this->model_catalog_category->getCategories(0);
|
23: |
|
24: | foreach ($categories as $category) {
|
25: |
|
26: | $children_data = [];
|
27: |
|
28: | $children = $this->model_catalog_category->getCategories($category['category_id']);
|
29: |
|
30: | foreach ($children as $child) {
|
31: | $filter_data = [
|
32: | 'filter_category_id' => $child['category_id'],
|
33: | 'filter_sub_category' => true
|
34: | ];
|
35: |
|
36: | $children_data[] = [
|
37: | 'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
|
38: | 'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&path=' . $category['category_id'] . '_' . $child['category_id'])
|
39: | ];
|
40: | }
|
41: |
|
42: |
|
43: | $data['categories'][] = [
|
44: | 'name' => $category['name'],
|
45: | 'children' => $children_data,
|
46: | 'column' => $category['column'] ? $category['column'] : 1,
|
47: | 'href' => $this->url->link('product/category', 'language=' . $this->config->get('config_language') . '&path=' . $category['category_id'])
|
48: | ];
|
49: | }
|
50: |
|
51: | return $this->load->view('common/menu', $data);
|
52: | }
|
53: | }
|
54: | |