Search This Blog

Jun 7, 2011

Magent: How to Get Attribute Data

You can simply show the attributes on catalog/product/view.phtml by using the following code statement. Basically it’s calling the attribute collection then from there, you can simply call other data such as attribute label, default value, etc.
/**
 * get attribute collection
 */
$attribute = $_product->getResource()->getAttribute(‘attribute_code’);
/**
 * get attribute type
 */
$attribute->getAttributeType();
/**
 * get attribute Label
 */
$attribute->getFrontendLabel();
/**
 * get attribute default value
 */
$attribute->getDefaultValue();
/**
 * check if the attribute is visible
 */
$attribute->getIsVisible();
/**
 * check if the attribute is required
 */
$attribute->getIsRequired();
/**
 * get attribute value
 */
$attributeValue = Mage::getModel('catalog/product')->load($_product->getId())->getMyAttribute();