Jump to content

[SOLVED] if is child of category ID 4?


Recommended Posts

I need a bit of code that will insert a bit of text before the price on the products list template and the product template.
The text simply says "price per pair"
This applies to all products in category ID 4 and works well if i use

{if $category->id AND $category->active}
      {if $category->id_category == 4} Price per pair: {/if}
{/if}



The problem is the category now has 30+ subcategories, so how can I apply smarty to check if is child/subcat of ID 4?
Instead of repeating above 30 times plus for every ID ....?

Thanks in advance

Link to comment
Share on other sites

If the category structure is only one deep, then you can just check the $category->parent_id value and test for it being '4'.

{if $category->id AND $category->active}
      {if ($category->id_category == 4) OR ($category->id_parent ==4)} Price per pair: {/if}
{/if} 



I think :D

Paul

  • Like 1
Link to comment
Share on other sites

Thanks Paul that worked and thankfully they are only nested 1 deep. I think it would still work if they were 2 or 3 deep but would mean more parent IDs added to the array.

Do you know of a list of all smarty prestashop variables for reference?
Thanks

Link to comment
Share on other sites

Cool, see that wasn't too bad :)

Unfortunately it isn't really as simple as having a list of variables..... The way this works is that the core code OR any installed modules pass variables from the PHP code to the smarty engine on a per page basis, so just because a variable is available at a point on any given page in one case, the same may not be true earlier in the page or on another page. In this case it has passed a product object, so you can use any of the properties of that object in your theme (it could have only passed a subset of the properties though, in which case the above might not have worked).

If you want to know what properties a product/category etc. has though you can look at the database tables, as the fields in there will likely (but may not) be available when the object is passed to a smarty template file in the theme.

Hope this makes some sort of sense.

Paul

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