Prestashop subcategories menu inside a subcategory

一个人想着一个人 提交于 2021-01-27 21:14:05

问题


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}

Any ideas?

Thanks so much


回答1:


as always i don't give you a full code, but i tell you how to do it. in smarty you need to create a function that takes as param number of parent category, and in this function you need to use Category::getChildren( $id_category );then in smarty you need only take a loop through the smarty function.

regards

and sorry for my English.




回答2:


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

And add this:

<?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();
    }
}

?>

And in product-list.tpl file:

<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>

via Get sibling categories in category.tpl for the current category in prestashop



来源:https://stackoverflow.com/questions/15939260/prestashop-subcategories-menu-inside-a-subcategory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!