Jump to content

Product categories in the product Description (or Product Details)


Neo9686

Recommended Posts

Hello, I'm trying to write a code in the template to reach a specific goal: I need the list of the product's categories, but I need to "filter" them somehow.

What I need is to view just some of them, specifically the ones that are direct subfolders of Category ID 59. I just managed to have a list of all of them, filtering them just by ID (it will not work, the ID's are mixed so I can't use a simple < or > method). I couldn't find any variable that contains useful info's such as the parent category, the depth level... Just ID, Name, nothing useful for my goal.

Can someone help me? I'm running Prestashop 1.7.8.8, Themevolty theme. I'm not posting the code I tried because I think it's a dead end, it's better to start from scratch but if you think it will be useful I'll post it right away.

Thank you in advance.

Link to comment
Share on other sites

<ul class="productcats">
  {foreach from=Product::getProductCategories($product.id) item=cat}
	{if $cat > 2}
		{assign var='current_cat' value=Category::getCategoryInformations(array($cat))}
		<li><a href="{$link->getCategoryLink({$cat})}" title="{$current_cat[{$cat}]['name']}">{$current_cat[{$cat}]['name']}</a></li>
	{/if}
  {/foreach}
</ul>

I don't know if I've understood your request correctly, but you can try this code .

Link to comment
Share on other sites

<ul class="productcats">
    {foreach from=Product::getProductCategories($product.id) item=cat}
        {assign var='current_cat' value=Category::getCategoryInformations(array($cat))}
        {if $current_cat[$cat]['id_parent'] == 59}
            <li><a href="{$link->getCategoryLink({$cat})}" title="{$current_cat[$cat]['name']}">{$current_cat[$cat]['name']}</a></li>
        {/if}
    {/foreach}
</ul>

Or this ?

Link to comment
Share on other sites

Hello RMK, thank you very much. The first version you posted is very similar (if not identical) to the one I tried at first. It works but it shows all 9 categories of the product. From there, I couldn't find how to "filter" the result: checking the parent category or the category depth seemed not to work since the information seems to be unavailable in any array I checked. Or I couldnt find it anyhow, at least.

The second code does not give any result instead. I suspect that this condition

{if $current_cat[$cat]['id_parent'] == 59}

is not working at all, since the category's parent ID is not an available info so it seems to always return a "FALSE" result.

Thank you very much for the help, much appreciated.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...