在Opencart中显示“相同级别”类别:2.3.0.2

问题描述 投票:0回答:1

Opencart仅在父类别页面上显示子类别。

就像我们有食品类别。披萨,面食,饮料,餐后甜点是食品类别的子类别。因此,当我们单击“食品”类别时,在“精确搜索”标题下显示了“比萨饼”,“意大利面”,“饮料”,“ Deseret”子类别。

但是当我单击Pizza时,它不会显示任何(同级或同级)类别。因此,我试图在Pizza子类别页面上获得Pasta,Drinks,Deseret子类别。

有人可以指导我如何获得此。在此先感谢

php opencart opencart2.x opencart-module opencart2.3
1个回答
0
投票

您最好的选择是创建一个新模块,而不是将其包含在模板中。

首先复制标准“类别”模块的所有前端文件,其中包括以下文件,请根据您自己的定义重命名它们,例如sibling_category随身携带category

\catalog\view\theme\default\template\extension\module\category.tpl
\catalog\controller\extension\module\category.php
\catalog\language\en-gb\extension\module\category.php

我们这里不需要模型,因为ModelCatalogCategory类已经具有所需的功能。

所以现在您需要更改控制器逻辑,编辑新创建的sibling_category.php控制器文件。我们在这里所做的是获取当前类别数据,提取父类别的ID(parent_id),然后获取parent_id或“兄弟姐妹”的所有子代]

<?php
class ControllerExtensionModuleSiblingCategory extends Controller {
    public function index() {
        $this->load->language('extension/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;
        }

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

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

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

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

        $siblings = $this->model_catalog_category->getCategories($category['parent_id']);

        foreach ($siblings as $category) {

            $data['sibling_categories'][] = array(
                'category_id' => $category['category_id'],
                'name'        => $category['name'] ,
                'href'        => $this->url->link('product/category', 'path=' . $category['category_id'])
            );
        }

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

现在您只需要根据需要使用sibling_category.tpl变量编辑视图文件($sibling_categories

© www.soinside.com 2019 - 2024. All rights reserved.