Neo9686 Posted December 9, 2023 Share Posted December 9, 2023 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 More sharing options...
RMK_Code Posted December 9, 2023 Share Posted December 9, 2023 <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 More sharing options...
RMK_Code Posted December 9, 2023 Share Posted December 9, 2023 <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 More sharing options...
Neo9686 Posted December 10, 2023 Author Share Posted December 10, 2023 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 More sharing options...
RMK_Code Posted December 12, 2023 Share Posted December 12, 2023 (edited) Hello, In the first code, did you replace {if $cat > 2} with the number you need? If it doesn't work, I'm sorry I can't help you better. Maybe you need a module for that. Edited December 12, 2023 by RMK_Code (see edit history) Link to comment Share on other sites More sharing options...
Neo9686 Posted December 12, 2023 Author Share Posted December 12, 2023 (edited) Hello RMK. If I use 59 instead of 2 I manage to exclude numbers from 1 to 59, but this is a single step. Not every category is a subcategory of ID 59, and I don't want to show all the subcategories till the end of the path. Thank you again. Edited December 12, 2023 by Neo9686 (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now