Jump to content

Discontinued on all Images in specific Category


justmeagain

Recommended Posts

  • justmeagain changed the title to Discontinued on all Images in specific Category

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:

obrazek.png.0408ffde53fea892e89576942170bc9e.png

If you also want to do it with a module, that's no problem either.

Edited by ps8moduly.cz (see edit history)
Link to comment
Share on other sites

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

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

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

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:

obrazek.thumb.png.3172033be5ec69e4eacb461fc2702f6b.png

 

In category:

obrazek.png.f8ce514ebbab14154e85602a3f23bf05.png

In product detail:

obrazek.png.bfaef89878d1cc8b91ed7e3cf8bffa39.png

Edited by ps8moduly.cz (see edit history)
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...