1

Hide Empty Value Attribute in Magento Product Additional Information (Frontend)

February 3, 2012 Magento

The lastest Magento 1.5 and 1.6 – by default – will show empty value attribute (especially empty dropdown value attributes) in the frontend – in product detail page (product additional information). The empty Magento dropdown attribute will show as “No” or “N/A”. I may assume that this is not what the store owner expected to provide product additional information to their buyers/visitors since it will cause question mark.

How to hide empty value attribute (empty value of Magento dropdown attribute) in Magento frontend or in product additional information?
Edit your template file named as “attributes.phtml”.
File path:

/app/design/frontend/default/default/template/catalog/product/view

Please note that “attributes.phtml” location of file path will be base on your theme and any active Magento extension that you are using. Example if you are using easytabs Magento extension then location of file path will be:

/app/design/frontend/default/default/template/easytabs

or

/app/design/frontend/[your theme]/[your theme]/template/easytabs

If you have found “attributes.phtml”, find and replace following coding:

FIND:
————————————————————————————————————————

<?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; ?>

————————————————————————————————————————

REPLACE:
————————————————————————————————————————

<?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; ?>

————————————————————————————————————————

Hope it will work and easy solution in your end. Good luck with your Magento attribute coding.

Incoming search terms:

697
Thanks!
An error occurred!

Related posts:

  1. How to Solve Magento Error 503 Service Unavailable
  2. How to Set Up Comment URL Open in New Window for WordPress
  3. Magmi is Magento Mass Importer

Comments (1)

 

  1. holodoktor says:

    Hi,

    thanks for your post. Your hint for the existence of $_data['code'] was very helpful.

    One question: Why not directly testing $_product->getData($_data['code'])? It works fine for me. :)

Leave a Reply

Ultrabook notebook tipis harga murah terbaik

Sepeda Motor Injeksi Irit Harga Terbaik Cuma Honda

Honda PGM-FI Sepeda Motor Injeksi