ajnglagla Posted April 21, 2014 Share Posted April 21, 2014 (edited) I am trying to show a text on product page when the current displayed product belongs to specific categories. If product is in category A, or in category B, or in category C... Then echo "text". I am using 1.5.3 How can i check if product is in category A or in category B or in category C, then do this? Edited April 21, 2014 by vekia (see edit history) Link to comment Share on other sites More sharing options...
ajnglagla Posted April 21, 2014 Author Share Posted April 21, 2014 I found a solution here http://www.prestashop.com/forums/topic/139200-display-categories-to-which-product-belongs-in-product-detail-page/ Link to comment Share on other sites More sharing options...
vekia Posted April 21, 2014 Share Posted April 21, 2014 you can achieve this without core change {assign var='associated' value=0} {foreach Product::getProductCategories($smarty.get.id_product) as $category} {if in_array($category, 5)} {assign var='associated' value=1} {/if} {/foreach} {if $associated==1} {l s='product associated'} {/if} 1 Link to comment Share on other sites More sharing options...
ajnglagla Posted April 21, 2014 Author Share Posted April 21, 2014 (edited) Thank you Vekia Edited April 21, 2014 by ajnglagla (see edit history) Link to comment Share on other sites More sharing options...
ajnglagla Posted April 21, 2014 Author Share Posted April 21, 2014 (edited) I did like that; but i have a problem. How can i show a text if one product is not belong any of these categories? I have added "else" but its pringting 3 times {foreach from=$product->moi_categories_names item=moi_category_name} {if $moi_category_name=="Category A"} This product belong to Category A and {elseif $moi_category_name=="Category B"} This product belong to Category B and {elseif $moi_category_name=="Category C"} This product belong to Category C and {/if} {/foreach} you can achieve this without core change {assign var='associated' value=0} {foreach Product::getProductCategories($smarty.get.id_product) as $category} {if in_array($category, 5)} {assign var='associated' value=1} {/if} {/foreach} {if $associated==1} {l s='product associated'} {/if} Edited April 21, 2014 by ajnglagla (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted April 21, 2014 Share Posted April 21, 2014 code you use doesnt allow to do that. you have to change it. at least to: add {assign var='associated' value=1} to each if condition then after foreach loop add: {if $associated==1} {l s='product associated'} {else} {l s='product not associated'} {/if} Link to comment Share on other sites More sharing options...
ajnglagla Posted April 21, 2014 Author Share Posted April 21, 2014 Thank you Vekia, its working great code you use doesnt allow to do that. you have to change it. at least to: add {assign var='associated' value=1} to each if condition then after foreach loop add: {if $associated==1} {l s='product associated'} {else} {l s='product not associated'} {/if} Link to comment Share on other sites More sharing options...
vekia Posted April 21, 2014 Share Posted April 21, 2014 you're welcome :-) glad to hear that i could help you a little :-) i marked topic title and [solved] 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