justmeagain Posted December 27, 2023 Share Posted December 27, 2023 (edited) Hi Just wondering if someone knows where & how to do this on PS 8.1.2 Want to show it on all products in the Discontinued category. Still want New to appear on New products - so not a simple overwrite. Cheers in advance Edited December 27, 2023 by justmeagain Spelling mistake (see edit history) Link to comment Share on other sites More sharing options...
ps8modules Posted December 28, 2023 Share Posted December 28, 2023 (edited) Hello. If you want to change it directly in the TPL, it is not a problem to add the condition. ./themes/your_theme/templates/catalog/_partials/product-flags.tpl Sample for category id 3: {block name='product_flags'} <ul class="product-flags js-product-flags"> {if $category.id == '3'} <li class="product-flag new">{l s='discountinued' d='Shop.Theme.Catalog'}</li> {/if} {foreach from=$product.flags item=flag} <li class="product-flag {$flag.type}">{$flag.label}</li> {/foreach} </ul> {/block} result: If you also want to do it with a module, that's no problem either. Edited December 28, 2023 by ps8moduly.cz (see edit history) Link to comment Share on other sites More sharing options...
ps8modules Posted December 28, 2023 Share Posted December 28, 2023 If you want to use it for more categories, just a small modification is enough. Sample for categories 3, 4, 5: {block name='product_flags'} <ul class="product-flags js-product-flags"> {if in_array($category.id, ['3', '4', '5'])} <li class="product-flag new">{l s='discountinued' d='Shop.Theme.Catalog'}</li> {/if} {foreach from=$product.flags item=flag} <li class="product-flag {$flag.type}">{$flag.label}</li> {/foreach} </ul> {/block} Link to comment Share on other sites More sharing options...
justmeagain Posted December 28, 2023 Author Share Posted December 28, 2023 Thanks but doesn't work......completely. If I do as you say then visit Catalog > Discontinued - the page loads and all the products do indeed have 'Discontinued' on the image However when I then try to actually select a product to view it I get a white page, turning on debug mode and reloading the page I get this error message ( ! ) Fatal error: Uncaught Error: Cannot use object of type Category as array in /var/www/html/mysite.co.uk/var/cache/dev/smarty/compile/classiclayouts_layout_full_width_tpl/bd/4f/cf/bd4fcf9092a6c0ce691d69ee4d766859ace81aee_2.file.product-flags.tpl.php on line 43 ( ! ) Error: Cannot use object of type Category as array in /var/www/html/mysite.co.uk/var/cache/dev/smarty/compile/classiclayouts_layout_full_width_tpl/bd/4f/cf/bd4fcf9092a6c0ce691d69ee4d766859ace81aee_2.file.product-flags.tpl.php on line 43 Cheers PHP version: 8.1.27 PrestaShop version: 8.1.2 Current theme in use: classic Link to comment Share on other sites More sharing options...
ps8modules Posted December 28, 2023 Share Posted December 28, 2023 (edited) Just edit the condition. Sample is valid for category page only. {if isset($category) && $category.id == '3'} Edited December 28, 2023 by ps8moduly.cz (see edit history) Link to comment Share on other sites More sharing options...
justmeagain Posted December 28, 2023 Author Share Posted December 28, 2023 I must be doing something wrong {block name='product_flags'} <ul class="product-flags js-product-flags"> {if isset($category) && $category.id == '138'} <li class="product-flag new">{l s='discountinued' d='Shop.Theme.Catalog'}</li> {/if} {foreach from=$product.flags item=flag} <li class="product-flag {$flag.type}">{$flag.label}</li> {/foreach} </ul> {/block} Produces same result ( ! ) Fatal error: Uncaught Error: Cannot use object of type Category as array in /var/www/html/mysite.co.uk/var/cache/dev/smarty/compile/classiclayouts_layout_full_width_tpl/bd/4f/cf/bd4fcf9092a6c0ce691d69ee4d766859ace81aee_2.file.product-flags.tpl.php on line 43 ( ! ) Error: Cannot use object of type Category as array in /var/www/html/mysite.co.uk/var/cache/dev/smarty/compile/classiclayouts_layout_full_width_tpl/bd/4f/cf/bd4fcf9092a6c0ce691d69ee4d766859ace81aee_2.file.product-flags.tpl.php on line 43 Link to comment Share on other sites More sharing options...
ps8modules Posted December 28, 2023 Share Posted December 28, 2023 (edited) Oh, I wrote this from my mobile phone. Now I'm at the computer and I'm giving you the example with multiple categories. You can only leave one category there. {block name='product_flags'} <ul class="product-flags js-product-flags"> {if $page.page_name == 'category' && isset($category['id']) && in_array($category.id, ['3', '138'])} <li class="product-flag new">{l s='discountinued' d='Shop.Theme.Catalog'}</li> {else if in_array($page.page_name,['product', 'index']) && in_array($product.id_category_default, ['3', '138'])} <li class="product-flag new">{l s='discountinued' d='Shop.Theme.Catalog'}</li> {/if} {foreach from=$product.flags item=flag} <li class="product-flag {$flag.type}">{$flag.label}</li> {/foreach} </ul> {/block} In Home: In category: In product detail: Edited December 28, 2023 by ps8moduly.cz (see edit history) Link to comment Share on other sites More sharing options...
ps8modules Posted December 28, 2023 Share Posted December 28, 2023 If it already works for you, you can like me by clicking the gray heart below my posts 😏 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