Search code examples
phpprestashopsmarty

Prestashop display product categories and subcategories


On the product page I want to display all categories and subcategories to which the product is assigned. Something like this: -Category 1 --Sub1 --Sub2 -Category 2 --Sub3 --Sub4

My current code is:

{foreach from=$product_categories item=product_category}
                    {if $product_category.id_category != 2}
                        <li >
                            <a href="{$link->getCategoryLink($product_category.id_category, $product_category.link_rewrite)}"
                            title="{$product_category.name}">{$product_category.name}</a>
                        </li>   
                    {/if}
                {/foreach}

But its print all categories in every line without category tree.


Solution

  • You need to use a nested function to generate a tree and then you can display it at the page, like what Prestashop did in the Blockcategories module.

    Why don't you use this module (Blockcategories) as a pattern?