Wednesday, May 02, 2012

Get product attributes in magento

Collected from a blog:

Following code will help you to retrieve all the attributes assigned to the product and to display them.
foreach ($attributes as $attribute)
{
if($attribute->getIsVisibleOnFront() && $attribute->getIsUserDefined())
{
$value = $attribute->getFrontend()->getValue($product);
if(strlen($value) && $product->hasData($attribute->getAttributeCode()))
{
$data[$attribute->getAttributeCode()] = array(
‘label’ => $attribute->getFrontend()->getLabel(),
‘value’ => $value
);
}
}
}

No comments: