Reputation: 1
I would like to display Yes/No Attributes in my view.phtml. I tried some codes but none is working.
Firstly I tried this syntax, which I found only and which is working for Attributes with Text-Values:
<?php
if ($_product->getAn_342() != null && $_product->getAn_342() != "") {
echo $this->__('Deliveryinformation');
echo $_product->getAn_342();
}
?>
This does not work for Attributes with yes/no Values. With this syntax there is displayed the Magento-ID of the Attribut but not the Value.
Next I tried this Syntax, which I found here in this forum:
<?php
if ($_product->getAttributeText($_data['An_56']) == "Yes"):
?>
But this does not work as well.
For explanation: One Attribut i want to display would be "Bestseller". The Attribut has Label "an_bestsller" and code "an_56", which will be the magento-Id.
So what exactly is wrong with that yes/no syntax above? Some help would be great.
Upvotes: 0
Views: 1495
Reputation: 111
You've to check different translatable values: 'N/A' or 'NO':
if ($_product->getAttributeText($_data['An_56']) =! $this->__("N/A") && $_product->getAttributeText($_data['An_56'] != $this->__('NO')):
It is better to make an extension which extends Mage_Catalog_Block_Product_View_Attributes and overwrites the function getAdditionalData:
public function getAdditionalData(array $excludeAttr = array())
{
$data = parent::getAdditionalData($excludeAttr);
foreach ($data as $code => $item) {
if ($item['value'] == Mage::helper('catalog')->__('N/A')
|| $item['value'] == Mage::helper('catalog')->__('No')
//You can add more values to hide
//|| $item['value'] == Mage::helper('catalog')->__('--')
) {
unset($data[$code]);
}
}
return $data;
}
Upvotes: 0
Reputation: 2500
You can try to do as follows :
$attr = $product->getResource()->getAttribute("oversize_type");
if ($attr->usesSource()) {
$oversizeLabel = $attr->getSource()->getOptionText($oversizeId);
}
Please change oversize_type to your attribute code
Above is the way of getting the option text of dropdown type.
hope this helps.
Upvotes: 0