0

A new attribute was added such as "bust" and ,"Catalog Input Type for Store Owner" was set to "text field". If I don't fill any text as a product attributes value, the frontend shows "Bust: No".
This happens even if the "Values Required" attribute property is set to "No".

I would like the attribute to not be shown if I did not fill any value for it.

closed as unclear what you're asking by brentwpeterson, Moose, Amit Bera, Sander Mangel, Keyul Shah Nov 18 '14 at 2:54

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

1

The reason is the class Mage_Catalog_Block_Product_View_Attributes, which implements the logic for getting the values for the additional attributes in the method getAdditionalData()

public function getAdditionalData(array $excludeAttr = array())
{
    $data = array();
    $product = $this->getProduct();
    $attributes = $product->getAttributes();
    foreach ($attributes as $attribute) {
        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 (is_string($value) && strlen($value)) {
                $data[$attribute->getAttributeCode()] = array(
                    'label' => $attribute->getStoreLabel(),
                    'value' => $value,
                    'code'  => $attribute->getAttributeCode()
                );
            }
        }
    }
    return $data;
}

Please note especially the lines:

} elseif ((string)$value == '') {
    $value = Mage::helper('catalog')->__('No');
}

This bit of code is a common piece of annoyance. There are several possible ways to change that behavior.

One would be to change the block, either by a rewrite, or by creating your own custom block and then using that via layout XML.

Another approach would be to change the output in the template catalog/product/view/attributes.phtml, where the additional attribute data is rendered. Something like

<?php $_data['value'] == 'No' ? '' : $_data['value']  ?>
<td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>

And yet another potential solution would be to set HTML as allowed and use a HTML comment as the value so it no longer matches '' (example given <!-- empty -->).

Not the answer you're looking for? Browse other questions tagged or ask your own question.