繁体   English   中英

Opencart中的第三类

[英]Third level category in Opencart

我的类别结构是:

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

在这里,我的主要类别Electronics, Furniture 子类别TV, Fridge etc子类别LG, Onida etc 那就是我有3 level categories. 我必须main navigation menu in Opencart显示这些内容。

但是在Opencart main category and sub categories仅显示main category and sub categories 不显示Third level category

因此,我如何显示第三级类别。 我在这里附上一张图片,可以更清楚地说明我的要求。 在此处输入图片说明

我的Opencart版本2.0.3.1

编辑

这是用于显示类别菜单的代码。

目录\\查看\\主题\\默认\\模板\\ 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> 

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

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

$children_data = array();

写下面的代码后,

$children_lv3_data = array();

2)在同一文件中替换

$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)打开文件目录/视图/主题/默认/模板/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 } ?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM