每个类别/子类别的 Opencart 2.2.0 仅在类别模块中显示第三级类别

南希

这可能是重复的,但是我找到的答案并没有解决我的问题。我有这样的类别结构:类别->子类别->子子类别。在我的类别模块中,我设法显示了整个结构(类别->子类别->子子类别)。但我需要的是只Subsub类别显示为每个类别或子类别。我的category.php模块文件如下所示:

<?php
class ControllerModuleCategory extends Controller {
    public function index() {
        $this->load->language('module/category');

        $data['heading_title'] = $this->language->get('heading_title');

        if (isset($this->request->get['path'])) {
            $parts = explode('_', (string)$this->request->get['path']);
        } else {
            $parts = array();
        }

        if (isset($parts[0])) {
            $data['category_id'] = $parts[0];
        } else {
            $data['category_id'] = 0;
        }

        if (isset($parts[1])) {
            $data['child_id'] = $parts[1];
        } else {
            $data['child_id'] = 0;
        }

        $this->load->model('catalog/category');

        $this->load->model('catalog/product');

        $data['categories'] = array();

        $categories = $this->model_catalog_category->getCategories(0);

        foreach ($categories as $category) {
            $children_data = array();

            if ($category['category_id'] == $data['category_id']) {
                $children = $this->model_catalog_category->getCategories($category['category_id']);

                foreach($children as $child) {
                    $children_data_2 = array();

                    $children_2 = $this->model_catalog_category->getCategories($child['category_id']);

                    foreach ($children_2 as $child_2) {
    $filter_data = array(
        'filter_category_id'  => $child_2['category_id'],
        'filter_sub_category' => true
    );

    $children_data_2[] = array(
        'category_id' => $child_2['category_id'],
        'name'        => $child_2['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'] . '_' . $child_2['category_id'])
    );
}

                    $filter_data = array('filter_category_id' => $child['category_id'], 'filter_sub_category' => true);

                    $children_data[] = array(
                        'category_id' => $child['category_id'],
                        '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'    => $children_data_2 // insert this line

                    );
                }
            }

            $filter_data = array(
                'filter_category_id'  => $category['category_id'],
                'filter_sub_category' => true
            );

            $data['categories'][] = array(
                'category_id' => $category['category_id'],
                'name'        => $category['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
                'children'    => $children_data,
                'href'        => $this->url->link('product/category', 'path=' . $category['category_id'])
            );
        }

        return $this->load->view('module/category', $data);
    }
}

我的category.tpl模块文件如下所示:

<h3><?php echo "Potkategorije" ?></h3>
<div class="list-group">
<ul>
    <?php foreach ($categories as $category) { ?>
    <?php if ($category['category_id'] == $category_id) { ?>
    <li class="cat-active">
        <a href="<?php echo $category['href']; ?>" class="active"><?php echo $category['name']; ?></a>
    <?php } else { ?>
    <li>
        <a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a>
        <?php } ?>
        <?php if ($category['children']) { ?>
        <b class="cc"></b>
        <ul class="col-subcat">
            <?php foreach ($category['children'] as $child) { ?>
            <li>
                <?php if ($child['category_id'] == $child_id) { ?>
                <a href="<?php echo $child['href']; ?>" class="active"><?php echo $child['name']; ?></a>
                <?php } else { ?>
                <a href="<?php echo $child['href']; ?>"><?php echo $child['name']; ?></a>
                <?php } ?>
                <?php if ($child['children']) { ?>
                <b class="cc"></b>
                <ul class="col-subcat">
                    <?php foreach ($child['children'] as $child_2) { ?>
                    <li>
                        <?php if ($child_2['category_id'] == $child_id) { ?>
                        <a href="<?php echo $child_2['href']; ?>" class="active"><?php echo $child_2['name']; ?></a>
                        <?php } else { ?>
                        <a href="<?php echo $child_2['href']; ?>"><?php echo $child_2['name']; ?></a>
                        <?php } ?>
                    </li>
                    <?php } ?>
                </ul>
                <?php } ?>
            </li>
            <?php } ?>
        </ul>
        <?php } ?>
    </li>
    <?php } ?>
</ul>
</div>

如何修改文件以使其工作?感谢您的时间,thanx。

南希

感谢一个好人@Ahmed Ginani,他试图帮助我,我知道我的问题是什么。我从未定义过当前的子类别。相反,我继续一次展示整个结构。因此,我不得不修改我的两个文件(php 和 tpl),以便仅显示当前类别/子类别的子子类别。我在这里显示正确的文件。

类别.php:

<?php
class ControllerModuleCategory extends Controller {
    public function index() {
        $this->load->language('module/category');

        $data['heading_title'] = $this->language->get('heading_title');

        if (isset($this->request->get['path'])) {
            $parts = explode('_', (string)$this->request->get['path']);
        } else {
            $parts = array();
        }

        if (isset($parts[0])) {
            $data['category_id'] = $parts[0];
        } else {
            $data['category_id'] = 0;
        }

        if (isset($parts[1])) {
            $data['child_id'] = $parts[1];
        } else {
            $data['child_id'] = 0;
        }



        $this->load->model('catalog/category');

        $this->load->model('catalog/product');

        $data['categories'] = array();

        $categories = $this->model_catalog_category->getCategories(0);

        foreach ($categories as $category) {
            $children_data = array();

            if ($category['category_id'] == $data['category_id']) {
                $children = $this->model_catalog_category->getCategories($category['category_id']);

                foreach($children as $child) {
                    $children_data_2 = array();

                    $children_2 = $this->model_catalog_category->getCategories($child['category_id']);

                    foreach ($children_2 as $child_2) {
    $filter_data = array(
        'filter_category_id'  => $child_2['category_id'],
        'filter_sub_category' =>  true
    );

    $children_data_2[] = array(
        'category_id' => $child_2['category_id'],
        'name'        => $child_2['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'] . '_' . $child_2['category_id']),

    );
}

                    $filter_data = array('filter_category_id' => $child['category_id'], 'filter_sub_category' => true);

                    $children_data[] = array(
                        'category_id' => $child['category_id'],
                        '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'    => $children_data_2 // insert this line


                    );
                }
            }

            $filter_data = array(
                'filter_category_id'  => $category['category_id'],
                'filter_sub_category' => true
            );

            $data['categories'][] = array(
                'category_id' => $category['category_id'],
                'name'        => $category['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
                'children'    => $children_data,
                'href'        => $this->url->link('product/category', 'path=' . $category['category_id'])
            );
        }

        return $this->load->view('module/category', $data);
    }
}

类别.tpl:

<div class="list-group">
 <ul id="menu">
    <?php foreach ($categories as $category) : 

        if (!empty($category['children'])) : 
        echo '<h3 style="margin-top:54px;">Potkategorije</h3>';
            echo '<ul>';
            foreach ($category['children'] as $category_level2) :
                if (!empty($category_level2['children']) && $category_level2['category_id'] == $child_id) :
                    echo '<ul>';
                    foreach ($category_level2['children'] as $category_level3) :
                        echo '<li style="list-style-type: none"><a href="'.$category_level3['href'].'">'.$category_level3['name'].'</a></li>';
                    endforeach;
                    echo '</ul>';
                endif;
                echo '</li>';
            endforeach;
            echo '</ul>';
        endif;
        echo '</li>';
    endforeach;
    echo '</ul>';
    ?>
</div>

我真的希望这对某人有所帮助,干杯!

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

将2个类别合并为1个类别,其中一个类别是另一个类别的子类别,这是什么?

来自分类Dev

在每个类别页面上显示子类别

来自分类Dev

从数据库生成带有主类别和子类别的web2py下拉菜单

来自分类Dev

WordPress当前类别的子类别列表

来自分类Dev

在Opencart的类别模块中仅显示子类别

来自分类Dev

在每个类别中选择前2行

来自分类Dev

选择属于2个不同类别的产品

来自分类Dev

多个类别的T检验(> 2)

来自分类Dev

搜索与相应类别的商品symfony2?

来自分类Dev

子类别的Crashlytics

来自分类Dev

类别和子类别的类图

来自分类Dev

没有型号类别的改装2

来自分类Dev

在每个类别中选择2行

来自分类Dev

子类别的SuppressWarnings

来自分类Dev

在搜索页面上显示2个类别的wordpress

来自分类Dev

如何计算每个类别和子类别的产品?

来自分类Dev

查询以获取每个类别+子类别的相等行数

来自分类Dev

在Opencart的类别模块中仅显示子类别

来自分类Dev

多个类别的T检验(> 2)

来自分类Dev

Opencart 2.x-如果类别为空,则显示特色模块

来自分类Dev

在opencart 2中获得第三级类别

来自分类Dev

Opencart类别末尾缺货显示

来自分类Dev

没有型号类别的改装2

来自分类Dev

在Magento 2中以编程方式更改类别的“ is_active”

来自分类Dev

如何在Opencart 2中创建单独的模板以输出类别?

来自分类Dev

opencart在搜索结果页面中显示每个产品的类别

来自分类Dev

如何从3个类别的数据帧的前2个类别中删除1行?

来自分类Dev

如何在每个类别的加载页面中仅获取 2 个产品

来自分类Dev

查找基于2个类别的平均值并计算