0

I have created a attribute newsale with two value New and sale with Catalog Input Type for Store Owner as dropdown and added it to a attribute set. And then I have added images into the media with same name as the added value (new.png, sale.png)

My code at frontend to call the attribute in product category page is:

<div class="product-badge"> 
    <span> 
         <?php
           $Feature = explode(",",$_product->getResource()
           ->getAttribute('newsale')->getFrontend()
           ->getValue($_product));
            foreach($Feature as $key => $value): ?>
              <a href="<?php echo $_product->getProductUrl() ?>" ?>
                  <?php echo "<img src='".Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA)."/wysiwyg/".trim($value).".png'/>"; ?>
             </a>
            <?php endforeach; ?>
    </span>
</div> 

My problem here is even when I didn't select any value for this attribute at admin panel, a broken image is getting displayed.

Help me to resolve this issue.

1 Answer 1

1

Try below code:

<div class="product-badge"> 
    <span> 
         <?php
           $Feature = explode(",",$_product->getResource()
           ->getAttribute('newsale')->getFrontend()
           ->getValue($_product));
            foreach($Feature as $key => $value): ?>
            <?php if($value == 'New' || $value =='sale') {?>
              <a href="<?php echo $_product->getProductUrl() ?>" ?>
                  <?php echo "<img src='".Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA)."/wysiwyg/".trim($value).".png'/>"; ?>
             </a>
             <?php } ?>
            <?php endforeach; ?>
    </span>
</div> 
2
  • Thank you so much. It worked. But only sale is displayed. New is not getting displayed when selected. kindly help
    – Ramya
    Commented May 26, 2016 at 13:06
  • check the value of new For exp : It's New Or new may be it's case sensitive
    – Arunendra
    Commented May 26, 2016 at 13:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.