OpenCart在更多页面上拆分类别

时间:2013-11-15 15:50:04

标签: php opencart

我正在努力实现以下目标:

包含CATEGORY GROUP1,CATEGORY GROUP2,CATEGORY GROUP3的顶级菜单

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

所以左栏看起来像这样:

CATEGORY GROUP1 category11

CATEGORY GROUP1 category12

CATEGORY GROUP1 category13

并且在选择产品时,只有此CATEGORY GROUP1应在左栏中可见

在顶层菜单中选择CATEGORY GROUP2时,我希望左栏仅显示:

CATEGORY GROUP2类别21

CATEGORY GROUP2类别22

CATEGORY GROUP2 Category23

当从此列表中选择产品时,我只希望CATEGORY GROUP2在左栏中可见

与CATEGORY GROUP 3相同。

无法弄清楚如何执行此操作,因为如果您将类别模块添加到布局“产品”,则每次您在产品中时都会显示它。

我尝试过Split Categorys并为每个分割添加不同的布局, 示例路由page1 / page1,page2 / page2,这适用于仅在不同页面上显示类别,但只要您选择产品,它就会显示所有与产品页面对应的模块。

如何做到这一点?

OpenCart 1.5.6

2 个答案:

答案 0 :(得分:0)

我明白你想要达到的目标。我知道创建一个新问题更好。这可以在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,这应该像预期的那样工作......

答案 1 :(得分:0)

我得到了解决方法。

我把这个答案结合起来:
Adding CSS stylesheet to pages based on route in OpenCart

用这个: OpenCart module on product page based on route

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

有效但不是最好的溶剂。