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

3 comments:

Mind Genies said...

I truly like to reading your post. Thank you so much for taking the time to share such a nice information.
Web Development Company

athletic clothing said...

nice to see such a great post. athletic clothing

Muhammad Rehan Mobin said...

very nice