I have rewritten the Mage_Catalog_Block_Product_View_Attributes block with the following to not display N/A or No attributes. However, some blank attributes are still displaying as No on the front end. I want to be able to keep Yes/No type attributes on the front end so I can't just apply an if statement for "No". Is there somewhere else Magento could be changing an empty attribute to No?
EDIT: After further research it appears this is happening on dropdown attributes.
public function getAdditionalData(array $excludeAttr = array())
{
$data = array();
$product = $this->getProduct();
$attributes = $product->getAttributes();
foreach ($attributes as $attribute) {
// if ($attribute->getIsVisibleOnFront() && $attribute->getIsUserDefined() && !in_array($attribute->getAttributeCode(), $excludeAttr)) {
if ($attribute->getIsVisibleOnFront() && !in_array($attribute->getAttributeCode(), $excludeAttr)) {
$value = $attribute->getFrontend()->getValue($product);
if (!$product->hasData($attribute->getAttributeCode())) {
$value = Mage::helper('catalog')->__('N/A');
} elseif ((string)$value == '') {
// $value = Mage::helper('catalog')->__('No');
} elseif ($attribute->getFrontendInput() == 'price' && is_string($value)) {
$value = Mage::app()->getStore()->convertPrice($value, true);
}
if($value === 'N/A' || $value === ''){
//do nothing makes sure N/A and empty attributes don't show up on product view page
}
elseif(is_string($value) && strlen($value)) {
$data[$attribute->getAttributeCode()] = array(
'label' => $attribute->getStoreLabel(),
'value' => $value,
'code' => $attribute->getAttributeCode()
);
}
}
}
return $data;
}
Best Answer
Hide the empty attributes by just edit the template file named as app/design/frontend/[mypackage]/[mytheme]/template/catalog/product/view/attributes.phtml
In your code, find following lines:
Replace this: