zoukankan      html  css  js  c++  java
  • opencart3调用三级菜单level 3 sub categories

      Opencart 3的menu菜单默认只调用一级和二级菜单,但很多电商网站类目复杂,三级菜单一般都是需要的,甚至更深,那么如何调用三级菜单level 3 sub categories呢?ytkah有一些思路可以参考一下。

    opencart3调用三级菜单level 3 sub categories

      打开Catalog/controller/common/menu.php文件,修改成如下代码

    <?php
    class ControllerCommonMenu extends Controller {
        public function index() {
            $this->load->language('common/menu');
    
            // Menu
            $this->load->model('catalog/category');
    
            $this->load->model('catalog/product');
    
            $data['categories'] = array();
    
            $categories = $this->model_catalog_category->getCategories(0);
    
            foreach ($categories as $category) {
                if ($category['top']) {
                    // Level 2
                    $children_data = array();
    
                    $children = $this->model_catalog_category->getCategories($category['category_id']);
    
                    foreach ($children as $child) {
    
                        // Level 3
                        $grandchildren_data = array();
    
                        $grandchildren = $this->model_catalog_category->getCategories($child['category_id']);
    
                        foreach ($grandchildren as $grandchild) {
    
                            $grandchild_filter_data = array(
                                'filter_category_id'  => $grandchild['category_id'],
                                'filter_sub_category' => true
                            );
    
                            $grandchildren_data[] = array(
                                'name'  => $grandchild['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($grandchild_filter_data) . ')' : ''),
                                'href'  => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $grandchild['category_id'])
                            );
                        }
    
    
                        $filter_data = array(
                            'filter_category_id'  => $child['category_id'],
                            'filter_sub_category' => true
                        );
    
                        $children_data[] = array(
                            'name'  => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
                            'href'  => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id']),
                            'children' => $grandchildren_data,
                        );
                    }
    
                    // Level 1
                    $data['categories'][] = array(
                        'name'     => $category['name'],
                        'children' => $children_data,
                        'column'   => $category['column'] ? $category['column'] : 1,
                        'href'     => $this->url->link('product/category', 'path=' . $category['category_id'])
                    );
                }
            }
    
            return $this->load->view('common/menu', $data);
        }
    }
    

      然后还要在前端调用catalogview hemedefault emplatecommonmenu.twig

      需要代码的伙伴联系ytkah

  • 相关阅读:
    HDOJ 5414 CRB and String 模拟
    Python标准库:内置函数all(iterable)
    Can not find a java.io.InputStream with the name [downloadFile] in the invocation stack.
    关于TabLayout+ViewPager组合实现多页面滑动
    互联网产品经理应该具备的技能(需求篇)
    【Android】利用自己定义View的重绘实现拖动移动,获取组件的尺寸
    mybatis自己主动生成mapper,dao,映射文件
    Java解析注解
    如日中天的Uber到底是用什么开发语言做到的?
    [Swift]LeetCode1002. 查找常用字符 | Find Common Characters
  • 原文地址:https://www.cnblogs.com/ytkah/p/10641405.html
Copyright © 2011-2022 走看看