28Jan/1126
Empty Attributes Showing as “No” or “N/A”? Here’s a Quick Fix!
The Problem
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.
The Fix
Fortunately, there is a quick fix that will solve the problem until the Magento developers fix this bug. 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; ?>
Save the file, upload it to your server and refresh the cache. Your "empty" attributes will now be hidden!
January 29th, 2011 - 15:20
Exact path would be : /app/design/frontend/default/[theme name]/CATALOG/template/product/view/attribute.phtml
Thanks for the fix!
January 31st, 2011 - 08:58
Thanks! I fixed the path.
February 1st, 2011 - 16:05
thx a lot! nice fix
February 3rd, 2011 - 09:28
If you are using Template masters easytabs extension you are going to find the attribute file in the extension folder in the design folder.
February 4th, 2011 - 11:20
great, good fix! Thank you!
February 5th, 2011 - 02:56
Thanks for this fix. Never thought that there would be so much trouble updating Magento to 1.4.2…
February 18th, 2011 - 11:22
Amazing! Thank you so much.
February 18th, 2011 - 17:37
Thanks! This fixed an annoying little quirk.
February 25th, 2011 - 15:58
I’m using the Magento Classic theme (f002) and there is no such file (Magento version 1.5.0.1). Any idea what to do? Thanks!
March 7th, 2011 - 09:30
Thx alot, works fine 4 me
March 16th, 2011 - 03:55
daghang salamat…it works!
March 21st, 2011 - 12:54
We use the version 1.5.0.1 and i can’t find the file attribute.phtml.
Anyone has fix it in the version 1.5.0.1?
March 21st, 2011 - 14:58
If you do not find the file in your theme, then look for it here:
/app/design/frontend/default/default/template/catalog/product/view/attributes.phtml
or if that fails, go here:
/app/design/frontend/base/default/template/catalog/product/view/attributes.phtml
March 29th, 2011 - 05:31
Thanks for the fix, resolved an annoying problem (ver 1.5.0.1).
April 6th, 2011 - 15:01
I tried to find this file but I think I don’t have anything like this…
the only file is media.phtml
Using magento (ver 1.5.0.1)
April 6th, 2011 - 15:05
April 17th, 2011 - 20:09
Thanks so much for the post!!! Great Fix!
May 4th, 2011 - 11:50
Do you have a similar solution for the product Compare Products page?
It is still displaying “No” for my blank attributes on the product comparison page. I tried copying and pasting your if statement into app/design/frontend/default/[my theme]/template/catalog/product/compare/list.phtml (around line 83), but it didn’t work.
Any help would be appreciated.
Using Magento 1.5.0.1
May 4th, 2011 - 12:17
Matt,
use the following code to remove the empty attributes on the product compare page. (using app/design/frontend/default/[my theme]/template/catalog/product/compare/list.phtml) On line 86, add the following:
if (!is_null($_item->getData($_attribute->getAttributeCode())) && ((string)$_attribute->getFrontend()->getValue($_item) != '')):It should look like so:
< ?php foreach($this->getItems() as $_item):
if (!is_null($_item->getData($_attribute->getAttributeCode())) && ((string)$_attribute->getFrontend()->getValue($_item) != '')): ?>
< ?php if($_i++%10==0): ?>
…
< ?php endif; ?>
< ?php endforeach; ?>
May 4th, 2011 - 14:19
Thanks Dave!!! It worked like a charm.
Hey, just in case anybody has trouble figuring out where to put these snippets of code, here is the whole tag from line 85 of app/design/frontend/default/[my theme]/template/catalog/product/compare/list.phtml. (I’m probably not the only one out there that just wants a whole block of code from a forum when I’m working late at night or against a tight deadline, so hopefully, this will make someone’s day…)
<?php foreach($this->getItems() as $_item): ?>
<?php /* begin if empty attribute check */ ?>
<?php if (!is_null($_item->getData($_attribute->getAttributeCode())) && ((string)$_attribute->getFrontend()->getValue($_item) != ”)): ?>
<?php if($_i++%10==0): ?>
<th><span class="nobr"><?php echo $_attribute->getStoreLabel() ?></span></th>
<?php endif; ?>
<td>
<?php switch ($_attribute->getAttributeCode()) {
case "price": ?>
<?php echo $this->getPriceHtml($_item, true, ‘-compare-list-’ . $_attribute->getCode()) ?>
<?php break;
case "small_image": ?>
<img src="<?php echo $this->helper(‘catalog/image’)->init($_item, ‘small_image’)->resize(125, 125); ?>" width="125" height="125" alt="<?php echo $this->htmlEscape($_item->getName()) ?>" title="<?php echo $this->htmlEscape($_item->getName()) ?>" />
<?php break;
case "date":
echo substr($this->getProductAttributeValue($_item, $_attribute),0,10);
break;
default: ?>
<?php echo $this->helper(‘catalog/output’)->productAttribute($_item, $this->getProductAttributeValue($_item, $_attribute), $_attribute->getCode()) ?>
<?php break;
} ?>
</td>
<?php /* end if empty attribute check */ ?>
<?php endif; ?>
<?php endforeach; ?>
May 19th, 2011 - 11:23
Or you could simply try this in the Attributes.php
Instead of :
elseif ((string)$value == ”) {
$value = Mage::helper(‘catalog’)->__(‘No’);
Place this:
elseif ((string)$value == ”) {
//$value = Mage::helper(‘catalog’)->__(‘No’); Comment out this line of code and add continue;.
continue;
June 14th, 2011 - 06:41
Just want to say – your solution ROCKS!
Thank you!
June 14th, 2011 - 19:05
Exactly what I needed, thanks! Note to those copying MattBill’s code, be sure to replace the smart quotes with regular quotes (‘). Works as pasted otherwise.
June 22nd, 2011 - 06:22
Super! worked first time, saved much time!
August 14th, 2011 - 15:10
Many Thanks, that realy help saved me many time. It worked with magento 1.5.10
August 31st, 2011 - 09:31
Supa Thank to you !
Your snippet is really usefull, I use it on my product page, compare page, I even customize it to only display “no empty” attributs and grouped them by their attribut groupe from Attributs Set.
Big thank from French riviera !