OpenCart 拆分类别在更多页面上


OpenCart Split category on more pages

我正在尝试实现以下目标:

包含类别组 1、类别组

2、类别组 3 的顶部菜单

选择 CATEGORY GROUP1 时,该组中的所有类别都将列在左栏中。

所以左栏看起来像这样:

类别

组1 类别11

类别组

1 类别12

类别

组1 类别13

选择产品时,左栏中只应显示此类别组 1,

在顶部菜单中选择类别组2时,我希望左列仅显示:

类别

组2 类别21

类别

组2 类别22

类别

组2 类别23

从此列表中选择产品时,我只希望类别组2在左栏中可见

类别组 3 也是如此。

只是无法弄清楚如何做到这一点,因为如果您将类别模块添加到布局"产品"中,每次您在产品中时它都会可见。

我尝试过拆分类别并为每个拆分添加不同的布局,示例路由页面 Page1/Page1、页面 2/页面2,这适用于仅在不同页面上显示类别,但是一旦您选择产品,它就会显示分配给产品页面的所有模块。

如何做到这一点?

开放购物车 1.5.6

我知道你想要实现什么。我知道创建一个新问题更好。这可以catalog/controller/module/category.php控制器中完成,在该控制器中检索根的类别并加载子项。将代码更改为以下内容:

class ControllerModuleCategory extends Controller {
    protected function index($setting) {
        $this->language->load('module/category');
        $this->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])) {
            $this->data['category_id'] = $parts[0];
        } else {
            $this->data['category_id'] = 0;
        }
        $categories = $this->model_catalog_category->getCategories($this->data['category_id']);
        if (isset($parts[1])) {
            $this->data['child_id'] = $parts[1];
        } else {
            $this->data['child_id'] = 0;
        }
        $this->load->model('catalog/category');
        $this->load->model('catalog/product');
        $this->data['categories'] = array();
        foreach ($categories as $category) {
            $total = $this->model_catalog_product->getTotalProducts(array('filter_category_id' => $category['category_id']));
            $children_data = array();
            if (!$this->data['category_id']) {
                $children = $this->model_catalog_category->getCategories($category['category_id']);
                foreach ($children as $child) {
                    $data = array(
                        'filter_category_id'  => $child['category_id'],
                        'filter_sub_category' => true
                    );
                    $product_total = $this->model_catalog_product->getTotalProducts($data);
                    $total += $product_total;
                    $children_data[] = array(
                        'category_id' => $child['category_id'],
                        'name'        => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $product_total . ')' : ''),
                        'href'        => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
                    );      
                }
            }
            $this->data['categories'][] = array(
                'category_id' => $category['category_id'],
                'name'        => $category['name'] . ($this->config->get('config_product_count') ? ' (' . $total . ')' : ''),
                'children'    => $children_data,
                'href'        => $this->url->link('product/category', 'path=' . $category['category_id'])
            );  
        }
        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/category.tpl')) {
            $this->template = $this->config->get('config_template') . '/template/module/category.tpl';
        } else {
            $this->template = 'default/template/module/category.tpl';
        }
        $this->render();
    }
}

如果未提供类别 ID,这应该可以按预期和以前工作......

我用一种解决方法得到了它。

我结合了这个答案:
在OpenCart中根据路由将CSS样式表添加到页面

有了这个:基于路线的产品页面上的OpenCart模块

然后我添加了一个新的布局,这样我就可以在不同的页面上拆分类别,并根据产品路径为模块添加了显示:无。

有效,但不是最好的解决方案。