4

If we have a custom attribute with the frontend properties for "Visible on Product View Page on Front-end" set to yes, then these attributes show up in our additional info box.

Even if the attribute does not have a value, it will still show up but say something like No or N/A in the additional info box.

Is there any way to make it so it will only show the value if a value exists? For example we may have an attribute like production dimensions. If we don't have the dimension available, I'd prefer to leave it off completely, not show N/A.

example

7

one solution is to override the template file: you can find it here : app/design/frontend/base/default/template/catalog/product/view/attributes.phtml

here an exmple which i tried on Magento 1.9.0.1 rwd Package :

<?php foreach ($_additional as $_data): ?>
        <?php if ($_helper->productAttribute($_product, $_data['value']) == 'Black'):?>
            <?php continue;?>
        <?php endif; ?>
            <tr>
                <th class="label"><?php echo $this->escapeHtml($this->__($_data['label'])) ?></th>
                <td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
            </tr>
        <?php endforeach; ?>

i just added the if statement, it checks for example if the value is Black. You can easily modify it for example with your N/A .....

Hope my answer was helpful.

4
  • 2
    What would be the best way to have multiple checks. For example only if it says N/A or No?
    – callmedpit
    Jul 7 '14 at 16:37
  • 2
    Also, what about if it's empty (for example no country of manufacture)?
    – callmedpit
    Jul 7 '14 at 16:50
  • 1
    not working,...
    – Gem
    Jan 10 '17 at 5:41
  • Not working above mentioned code,
    – user51361
    Apr 8 '17 at 9:51
3

Another way of doing this would be to rewrite the block Mage_Catalog_Block_Product_View_Attributes and change the function getAdditionalData

In this function you have the following section:

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);
}

What you could do is change this part to stop the changing of $value to include 'N/A' and 'No'. Then your attributes will not be shown.

1

This is correct solution which was checked on Magento 1.9.1.1, 1.9.3.3.

 <?php foreach ($_additional as $_data): ?>
    <?php if ($_helper->productAttribute($_product, $_data['value']) == 'N/A'):?>
        <?php continue;?>
    <?php endif; ?>
    <?php if ($_helper->productAttribute($_product, $_data['value']) == 'No'):?>
        <?php continue;?>
    <?php endif; ?>
        <tr>
            <th class="label"><?php echo $this->escapeHtml($this->__($_data['label'])) ?></th>
            <td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
        </tr>
  <?php endforeach; ?>
0

Maybe a simple solution. You could try via translate. But this might give some side effects ...

translate.csv

"Mage_Catalog::N/A",""

0

This is the ugly hack I did and it works. Notice I do checks for:

  • No
  • N/A
  • Nein (english/german store)

        <tbody>
        <?php foreach ($_additional as $_data): ?>
            <?php if($_helper->productAttribute($_product, $_data['value'], $_data['code']) == 'Nein'){}
            elseif($_helper->productAttribute($_product, $_data['value'], $_data['code']) == 'No'){}
            elseif($_helper->productAttribute($_product, $_data['value'], $_data['code']) == 'N/A'){}else{ ?>
            <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; ?>
        </tbody>
    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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