Tuesday, 19 June 2012

Blank Attribute not show in magento


For some odd reason, the Magento developers decided that an empty attribute should NOT be empty, but rather "No" or "N/A", depending on its type. This is not just annoying, but in some cases can display wrong information which means confused visitors and potentially lost sales.


Open the file /app/design/frontend/default/[theme name]/template/catalog/product/view/attribute.phtml in an editor and find the following lines:

<?php foreach ($_additional as $_data): ?>
    <tr>
        <th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
        <td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
    </tr>
<?php endforeach; ?>
Replace these lines with this:
 
<?php foreach ($_additional as $_data): ?>
    <?php $_attribute = $_product->getResource()->getAttribute($_data['code']);
    if (!is_null($_product->getData($_attribute->getAttributeCode())) && ((string)$_attribute->getFrontend()->getValue($_product) != '')) { ?>
    <tr>
        <th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
        <td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
    </tr>
    <?php } ?>
<?php endforeach; ?>

No comments:

Post a Comment

Note: only a member of this blog may post a comment.