0

I have created an Multiselect attribute featuredetail in magento 1.9.2.4. Then mapping is done with an image for every attribute value.

My phtml file for calling this attribute is:

<div class="feature">   

    <?php
    $Feature = explode(",",$_product->getResource()
    ->getAttribute('featuredetail')->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/feature/detail/".trim($value).".png'/>"; ?>
        </a>
    <?php echo $value; ?>
  <?php endforeach; ?> 
</div>

Then I called this attribute to be displayed in product-collateral tab in product details page. When value is not entered for any attribute that is included inside the product collateral tab, the tab should be hidden. So I modified the product-collateral tab code in view.phtml like this:

<div class="product-collateral toggle-content tabs">
    <?php if ($detailedInfoGroup = $this->getChildGroup('detailed_info', 'getChildHtml')):?>
        <dl id="collateral-tabs" class="collateral-tabs">
            <?php foreach ($detailedInfoGroup as $alias => $html):?>
            <?php  

                    **if(trim($html)=="") continue;** 
            ?>
                <dt class="tab"><span><?php echo $this->escapeHtml($this->getChildData($alias, 'title')) ?></span></dt>
                <dd class="tab-container">
                    <div class="tab-content"><?php echo $html ?></div>
                </dd>
            <?php endforeach;?>
        </dl>
    <?php endif; ?>
</div>

This modified code is working well for the description attribute. But for the multiselect attribute with mapped image, when no value is selected for this attribute it is displaying broken image instead of hiding the tab.

What modification should be done to resolve this?

1 Answer 1

0

Change

<a 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>

to

$imagePath = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA)."wysiwyg/feature/detail/".trim($value).".png ;
if (file_exists($imagePath)) {
<a href="<?php echo $_product->getProductUrl() ?>" ?>
            <?php echo "<img src='". $imagePath ."'/>"; ?>
        </a>
}


Basically you need to put a file exists check.

6
  • When I put the above code rest of the code is changing to grey color and not working. Please help
    – Ramya
    Commented May 27, 2016 at 12:25
  • Basically before img tag, you need to place a file_exists check on the img src Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA)."wysiwyg/feature/detail/".trim($value).".png' Commented May 27, 2016 at 12:32
  • May be I did some mistake in the syntax as I haven't checked the code. Commented May 27, 2016 at 12:33
  • Is this syntax correct? $imagePath = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA)."wysiwyg/feature/detail/".trim($value).".png ; This is the line affecting the rest.
    – Ramya
    Commented May 27, 2016 at 12:35
  • I am not sure if the syntax is 100% correct as I didn't executed the code on my machine. I just used the above code and provide you the logic. Commented May 30, 2016 at 4:04

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.