Magento Themes and Magento Extensions

Stop Empty Attributes Showing as ‘No’ in Magento

Share

If you don’t complete and attribute for a product in Magento it displays as ‘No’ rather than just hiding them. This means attributes that aren’t relevant for a product will still appear confusing the user. There is a simple fix for this:

OpenĀ  /app/design/frontend/default/YOUR THEME/template/catalog/product/view/attribute.phtmland change this:

<?php foreach ($_additional as $_data): ?>
<tr>
<th><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
<td><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
</tr>
<?php endforeach; ?>

for 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><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
<td><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
</tr>
<?php } ?>
<?php endforeach; ?>

Comments are closed.