是否有方法或扩展名修改类别模块,使其仅显示当前顶级类别页面的子类别。仅显示Opencart中类别模块的子类别
例如,如果我的“笔记本电脑&桌面”类别页面,侧边栏模块只会列出与“笔记本电脑&桌面”的范畴,如“苹果电脑”和“电脑”与相关联的子类别主标题“笔记本电脑&桌面”(而不是列出或显示任何其他顶级类别)。
是否有方法或扩展名修改类别模块,使其仅显示当前顶级类别页面的子类别。仅显示Opencart中类别模块的子类别
例如,如果我的“笔记本电脑&桌面”类别页面,侧边栏模块只会列出与“笔记本电脑&桌面”的范畴,如“苹果电脑”和“电脑”与相关联的子类别主标题“笔记本电脑&桌面”(而不是列出或显示任何其他顶级类别)。
以下列方式更新部分的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'])
); */
}
注:正如我前面加,只有子类别将显示你的问题的评论,并不会有任何选项来选择添加到父类别的产品。
祝你有美好的一天:)!
如果产品添加到父类别中,该怎么办? –
我们在所有父类别 – Manish
中有子类别,但是如果将产品添加到“父母”类别(如“笔记本电脑和台式机”),而不是像“Macs”和“PC”这样的子类别,则该怎么办? –