Opencart 3限制类别路径

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

我试图将类别路径限制为仅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文件夹,但它仍然没有更新。任何帮助表示赞赏。谢谢

opencart-3
1个回答
0
投票

因此,如果我正确地理解了任务,那么你希望你的面包屑看起来像这样

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'])
);

您可以计算零件数组中的总项数,并决定是否显示此痕迹。随意提问,我会相应地更正我的答案。


我不会删除第一个答案,因为它可能会帮助某人。但是在得到作者的更多细节之后,这里是答案。

因此,如果您希望限制精确搜索显示在第四级和下一级,您需要执行两个步骤:

  1. 计算水平。在第67行添加
$level = count($parts);
  1. 当级别超过限制时添加if语句。在第139行更换
$results = $this->model_catalog_category->getCategories($category_id);

if($level < 4){
    $results = $this->model_catalog_category->getCategories($category_id);
}else{
    $results = array();
}
© www.soinside.com 2019 - 2024. All rights reserved.