【问题标题】:Third level category in OpencartOpencart 中的第三级类别
【发布时间】:2017-12-30 21:38:12
【问题描述】:

我的类别结构是:

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 中只显示。 Third level category 不显示。

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

我的 Opencart 版本2.0.3.1

编辑

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

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> 

【问题讨论】:

  • 显示这些类别的代码在哪里?
  • opencart 中仅提供显示two level category。我不知道要更改哪些页面/页面才能使其正常工作。如果任何与Opencart 合作的人可以帮助我..
  • @AlanMachado,我添加了代码。请检查...

标签: php opencart categories opencart2.x


【解决方案1】:

注意:不建议直接在内核中进行更改 文件。您可以对 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) 打开文件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 } ?>

【讨论】:

  • 经过长时间的搜索和研究,我得到了解决方案。但是我会尝试您的答案..感谢您的快速回答并 +1...而且它非常有用..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-04
  • 2019-11-25
  • 2014-01-19
  • 1970-01-01
  • 2020-03-23
  • 1970-01-01
相关资源
最近更新 更多