首页 文章

Opencart中的第三级类别

提问于
浏览
2

我的 category 结构是:

Electronics
    -TV
       --LG
       --ONIDA
    -Fridge
       --Whirlpool
       --Videocon
    -Music Player
       --Sony
       --LG
Furniture
    -Wooden
       --Chair
       --Bed
    -Metal
       --Chair

我的 main categoriesElectronics, Furniture ; SubcategoriesTV, Fridge etcsub-subcategoriesLG, Onida etc . 那是我 3 level categories. 我必须在 main navigation menu in Opencart 中显示这些 .

但是只显示 Opencart main category and sub categories . Third level category 不显示 .

所以 how I display the third level category. 这里我附上一张图片,告诉我的要求更清楚 .
enter image description here

我的 Opencart version2.0.3.1

EDIT

这是显示类别菜单的代码 .

catalog \ view \ theme \ default \ template \ common \ header.tpl

<ul class="nav navbar-nav">
    <?php foreach ($categories as $category) { ?>
    <?php if ($category['children']) { ?>
    <li class="dropdown"><a href="<?php echo $category['href']; ?>" class="dropdown-toggle" data-toggle="dropdown"><?php echo $category['name']; ?></a>
      <div class="dropdown-menu">
        <div class="dropdown-inner">
          <?php foreach (array_chunk($category['children'], ceil(count($category['children']) / $category['column'])) as $children) { ?>
          <ul class="list-unstyled">
            <?php foreach ($children as $child) { ?>
            <li><a href="<?php echo $child['href']; ?>"><?php echo $child['name']; ?></a></li>
            <?php } ?>
          </ul>
          <?php } ?>
        </div>
        <a href="<?php echo $category['href']; ?>" class="see-all"><?php echo $text_all; ?> <?php echo $category['name']; ?></a> </div>
    </li>
    <?php } else { ?>
    <li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a></li>
    <?php } ?>
    <?php } ?>
  </ul>

1 回答

  • 1

    注意:不建议在核心文件中进行直接更改 . 您可以使vqmod进行相同的更改 . 此处给出的更改在默认模板中进行测试,在其他自定义主题中可能会有所不同 .

    (1)打开文件 catalog/controller/common/header.php 并搜索

    $children_data = array();
    

    并在下面写下代码 after it

    $children_lv3_data = array();
    

    2)在 same file 替换

    $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_lv3 = $this->model_catalog_category->getCategories($child['category_id']);
    
    if($children_lv3)
    {    
    
        foreach ($children_lv3 as $child_lv3) 
        {
            $filter_data_lv3 = array(
            'filter_category_id'  => $child_lv3['category_id'],
            'filter_sub_category' => true
            );
    
            $children_lv3_data[] = array(
            'category_id' => $child_lv3['category_id'],
            'name'  => $child_lv3['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data_lv3) . ')' : ''),
            'href'  => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'] . '_' . $child_lv3['category_id'])
            );
        }
    
        $children_data[] = array(
                'children_lv3' => $children_lv3_data,
        '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'])
        );
    
    }
    
    else
    {
    
        $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'])
        );
    }
    

    3)打开文件 catalog/view/theme/default/template/common/header.tpl 并搜索

    <li><a href="<?php echo $child['href']; ?>"><?php echo $child['name']; ?></a></li>
    

    并在其后面放下代码

    <?php if(isset($child['children_lv3']) && count($child['children_lv3'])>0){ ?>
                                <ul> 
                                   <?php foreach ($child['children_lv3'] as $child_lv3) { ?>
                                   <li><a href="<?php echo $child_lv3['href']; ?>"><?php echo $child_lv3['name']; ?></a></li>
                                    <?php  } ?>
                                </ul>
                            <?php } ?>
    

相关问题