Jump to content

[SOLVED] if product is in category A or in category B or in category C, then do this


ajnglagla

Recommended Posts

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 by vekia (see edit history)
Link to comment
Share on other sites

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}
  • Like 1
Link to comment
Share on other sites

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 by ajnglagla (see edit history)
Link to comment
Share on other sites

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

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

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