Skip to content
Simon Sprankel edited this page Jan 22, 2021 · 1 revision

Admin config:

Navigate to Admin -> Catalog -> Product Badges in order to create sample badges.

Please create a badge that is active and it's rules are matching visible products in Catalog List View.

Frontend and template modifications:

Product list:

In beginning of catalog/product/list.phtml you have to add:

#!php

/** @var CustomGento_ProductBadges_Helper_Data $_badgesHelper */
$_badgesHelper = Mage::helper('customgento_productbadges');
$_badgesHelper->initProductBadgeCollection($_productCollection);

Below list.phtml you have to add the actual code that renders the badges per products:

#!php
<?php
    /**
     * Rendering product badges for Product List Page
     */
     echo $_badgesHelper->generateBadgesHtml($_product);
?>

Product Details Page:

In beginning of catalog/product/view/media.phtml you have to add:

#!php
/** @var CustomGento_ProductBadges_Helper_Data $_badgesHelper */
$_badgesHelper = Mage::helper('customgento_productbadges');

At the end of div with class "product-image-gallery" we have to call

#!php
$_badgesHelper->generateSingleProductBadgesHtml($_product)

The template file should look like this:

#!php
<div class="product-image product-image-zoom">
    <div class="product-image-gallery">
        <img id="image-main"
             class="gallery-image visible"
             src="<?php echo $this->helper('catalog/image')->init($_product, 'image') ?>"
             alt="<?php echo $this->escapeHtml($this->getImageLabel()) ?>"
             title="<?php echo $this->escapeHtml($this->getImageLabel()); ?>" />

        <?php $i=0; foreach ($this->getGalleryImages() as $_image): ?>
            <?php if ($this->isGalleryImageVisible($_image)): ?>
            <img id="image-<?php echo $i; ?>"
                 class="gallery-image"
                 src="<?php echo $this->getGalleryImageUrl($_image); ?>"
                 data-zoom-image="<?php echo  $this->getGalleryImageUrl($_image); ?>" />
            <?php endif; ?>
        <?php $i++; endforeach; ?>
        <?php
            /**
             * Rendering product badges for PDP
             */
            echo $_badgesHelper->generateSingleProductBadgesHtml($_product);
        ?>
    </div>
</div>
Clone this wiki locally