Magento 2 // Show "Offer Label" on category pages // Amasty Special Promotions

417 Views Asked by At

We have a Magento 2 site running Amasty Special Promotions, the "offer label" is showing on the product pages as expected however, it's not showing on the category pages at all. How could this be added, I came across this code in the Amasty extension:

In catalog_product_view.xml

<referenceContainer name="product.info.media">
        <block before="-" class="Amasty\BannersLite\Block\Banner" name="amasty.banners.lite.label" template="label.phtml">
            <action method="setPosition">
                <argument name="position" xsi:type="string">2</argument>
            </action>
        </block>
    </referenceContainer>

In label.phtml:

<?php foreach ($block->getBanners() as $banner) : ?>
    <?php if ($block->isEnableBannerPosition() && $img = $block->getImage($banner)) : ?>
        <img class="am-banners-lite-label"
             alt="<?= $block->escapeHtml($block->getAlt($banner)) ?>"
             src="<?= $block->escapeUrl($img) ?>">
    <?php endif;?>
<?php endforeach; ?>
1

There are 1 best solutions below

0
Manisha Vasani On

"catalog_product_view" fie is layout file for product page. if you want to display on category page add file in your theme design folder "catalog_category_view.xml" :

<referenceContainer name="content">
     <block before="-" class="Amasty\BannersLite\Block\Banner" 
            name="amasty.banners.lite.label" template="label.phtml">
     <action method="setPosition">
         <argument name="position" xsi:type="string">2</argument>
     </action>
     </block>
</referenceContainer>