我试图将类别路径限制为仅4级,并且在我4级之后没有目录显示任何子类别。我已将产品/类别控制器中的部件代码更改为以下内容但它没有似乎更新了页面。
$parts = explode('_', (string)$this->request->get['path']);
//print_r($parts);
echo "<script>console.log( 'Debug Objects: here21' );</script>";
if(count($parts) < 4){
echo "<script>console.log( 'Debug Objects: here2' );</script>";
$category_id = (int)array_pop($parts);
foreach ($parts as $path_id) {
if (!$path) {
$path = (int)$path_id;
} else {
$path .= '_' . (int)$path_id;
}
$category_info = $this->model_catalog_category->getCategory($path_id);
if ($category_info) {
$data['breadcrumbs'][] = array(
'text' => $category_info['name'],
'href' => $this->url->link('product/category', 'path=' . $path . $url)
);
}
}
}
} else {
$category_id = 0;
}
我已经清除了仪表板中的缓存并清除了system\storage\cache
文件夹,但它仍然没有更新。任何帮助表示赞赏。谢谢
因此,如果我正确地理解了任务,那么你希望你的面包屑看起来像这样
home > category 1 > sub category 2 > sub category 3 > sub category 4 > sub cateogry 5
看起来像这样
home > category 1 > sub category 2 > sub category 3 > sub category 5
是这样,那么解决方案很简单:
$parts = explode('_', (string)$this->request->get['path']);
$category_id = (int)array_pop($parts);
//add this code - it will slice the parts array to only 3 items, leaving the 4th as the current category_id
$parts = array_slice($parts, 0, 3);
foreach ($parts as $path_id) {
如果您不希望显示最后一个痕迹物品,则需要向下滚动到第103行以查找此代码
// Set the last category breadcrumb
$data['breadcrumbs'][] = array(
'text' => $category_info['name'],
'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'])
);
您可以计算零件数组中的总项数,并决定是否显示此痕迹。随意提问,我会相应地更正我的答案。
我不会删除第一个答案,因为它可能会帮助某人。但是在得到作者的更多细节之后,这里是答案。
因此,如果您希望限制精确搜索显示在第四级和下一级,您需要执行两个步骤:
$level = count($parts);
$results = $this->model_catalog_category->getCategories($category_id);
同
if($level < 4){
$results = $this->model_catalog_category->getCategories($category_id);
}else{
$results = array();
}