是否有一种方法或扩展可以修改类别模块,因此它只显示当前顶级类别页面的子类别。
例如,如果我在“笔记本电脑和台式机”类别页面上,侧边栏模块将仅列出与“笔记本电脑和台式机”类别相关联的子类别,例如“Macs”和“PC”标题为“笔记本电脑和桌面”(并未列出或显示任何其他顶级类别)。
答案 0 :(得分:1)
按以下方式更新foreach
中的catalog/controller/module/category.php
部分,仅显示左列中的子类别。
$cur_category_id = $this->data['category_id']; // new code
foreach ($categories as $category) {
$children_data = array();
$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
);
$children_data[] = array(
'category_id' => $child['category_id'],
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($data) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
if($cur_category_id && $cur_category_id == $category['category_id']){
$this->data['heading_title'] = $category['name'];
$this->data['categories'][] = array(
'category_id' => $child['category_id'],
'children' => array(),
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($data) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}
}
$data = array(
'filter_category_id' => $category['category_id'],
'filter_sub_category' => true
);
/*
$this->data['categories'][] = array(
'category_id' => $category['category_id'],
'name' => $category['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($data) . ')' : ''),
'children' => $children_data,
'href' => $this->url->link('product/category', 'path=' . $category['category_id'])
); */
}
注意:由于我之前在您的问题中添加了评论,因此只会显示子类别,并且不会有任何选项来选择添加到父类别的产品。
度过愉快的一天:) !!