0

I have created a multiselect attribute named feature and have associated an image for every option created for that attribute. And I have displayed this attribute value inside the product collateral tab. As far in the product collateral tab, If the attribute displayed inside it don't have any value, that particular tab will be hidden. But with this feature attribute, even when no option is selected it is displaying broken image.

The code to fetch an image for each option of the feature attribute is :

    <?php       
   $_prodID = Mage::registry('current_product')->getId();
   $_product = Mage::getModel('catalog/product')->load($_prodID );

?>

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

I think this feature.phtml is reponsible for that broken image to get displayed even when no value is selected. What should be done to fix this issue.Please kindly help me.

1

You can check a statement where if $value exist

<?php       
   $_prodID = Mage::registry('current_product')->getId();
   $_product = Mage::getModel('catalog/product')->load($_prodID );

?>

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

This should fix your broken images, although it wont hide your tab itself.

Hope this helps.

  • Yeas the broken images are gone now. But the tab is empty.I want the collateral tab to get hidden when it. I think Its default function is to do that but for this attribute it is not hiding. – Ramya Jun 16 '16 at 9:10
  • If you just want to hide it then I would suggest to have css inside the if condition, which will hide it. I know it's not the best option but tab doesn't depends upon the product, which is why you cannot hide it based on attribute. – Adarsh Khatri Jun 16 '16 at 10:00
  • can we hide the tab when it is empty using css? – Ramya Jun 16 '16 at 10:03
  • How does your tab looks like? Can you show me with the html nodes? – Adarsh Khatri Jun 16 '16 at 10:06
  • I have used collateral tab which will be default in details page. – Ramya Jun 16 '16 at 12:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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