Asu34 Posted December 9, 2022 Share Posted December 9, 2022 Hi there, I am trying to set up a condition for displaying a field on the products belonging to a category (and if the latter is active)... This field would be present on the list of products. Am on PS 1.7... I have for the moment only a partial solution with {if in_array(99 , Product::getProductCategories($product->id|intval))} My field {/if} But I miss the other condition which is that this category must be activated. Do you have an idea ? I thank you in advance Link to comment Share on other sites More sharing options...
QuickUpdate.net Posted December 19, 2022 Share Posted December 19, 2022 (edited) Should be something like: $category = new Category(99); if ($category->active) { your code here } Edited December 19, 2022 by QuickUpdate.net (see edit history) Link to comment Share on other sites More sharing options...
Mediacom87 Posted December 19, 2022 Share Posted December 19, 2022 Il y a 2 heures, QuickUpdate.net a dit : Should be something like: $category = new Category(99); if ($category->active) { your code here } Hi, attention, you propose PHP code while the request is about smarty code in the TPL of the theme. Link to comment Share on other sites More sharing options...
QuickUpdate.net Posted December 19, 2022 Share Posted December 19, 2022 (edited) Then this code should be added in the controller displaying the tpl and assigning a tpl variable that will act as a condition to display the content, eg (pseudocode for example): $category = new Category(99); if ($category->active) { $smarty->assign("displayfield", true); } And in TPL: {if displayfield && in_array(99 , Product::getProductCategories($product->id|intval))} My field {/if} Edited December 19, 2022 by QuickUpdate.net (see edit history) Link to comment Share on other sites More sharing options...
Mediacom87 Posted December 19, 2022 Share Posted December 19, 2022 il y a 5 minutes, QuickUpdate.net a dit : Then this code should be added in the controller displaying the tpl and assigning a tpl variable that will act as a condition to display the content. Exactly, that's why I created this as an override with PrestaShop cache management to avoid too much slowdown during successive tests to this forum member. 1 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