子类别中的 Prestashop 子类别菜单 [英] Prestashop subcategories menu inside a subcategory

查看:69
本文介绍了子类别中的 Prestashop 子类别菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在所有子类别中显示 prestashop 类别的子类别菜单.默认情况下,您只能看到一个类别内的子类别菜单,而无法看到子类别的兄弟"子类别.

I am trying to show the subcategories menu of prestashop categories inside all subcategories. By default you only can see the subcategories menu inside a category but you cant see the "brother" subcategories of a subcategory.

我想我只需要让这段代码在子类别内工作,因为这段代码在类别内工作得很好:

I think I only need to make this code to work inside a subcategory because this code works well inside a category:

{foreach from=$subcategories item=subcategory}
<li >    <a href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'htmlall':'UTF-8'}"
class="cat_name">{$subcategory.name|escape:'htmlall':'UTF-8'}</a>
</li>    {/foreach}

有什么想法吗?

非常感谢

推荐答案

为了开始,我会在/override/controllers/中创建一个覆盖文件,命名为 CategoryController.php

For to start i would have created a override file in /override/controllers/, named CategoryController.php

并添加:

<?php

class CategoryController extends CategoryControllerCore
{
    public function displayContent()
    {
        // Get the global smarty object.
        global $smarty;

        // Get current category's parent.
        $parent_category = new Category($this->category->id_parent, self::$cookie->id_lang);

        // Get parent category's subcategories (which is current category's siblings, including it self).
        $category_siblings = $parent_category->getSubCategories((int)self::$cookie->id_lang)

        /* Assign your siblings array to smarty. */
        $smarty->assign(
            array(
                "category_siblings" => $category_siblings
            )
        );

        /* This we run the normal displayContent, but pass the siblings array to
           category.tpl */
        parent::displayContent();
    }
}

?>

product-list.tpl 文件中:

<ul>
    {foreach from=$category_siblings item=elemento}
         <a href="{$link->getCategoryLink($elemento.id_category, $elemento.link_rewrite)|escape:'htmlall':'UTF-8'}" class="cat_name"> <li {if $category->id == $elemento.id_category}class="active"{/if}> {$elemento.name} </li> </a>
    {/foreach}
</ul>

通过获取prestashop 中当前类别的 category.tpl 中的兄弟类别

这篇关于子类别中的 Prestashop 子类别菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆