Sanjoy Roy

[MCM, MCP, SCJP] – Senior PHP Programmer

Magento – How to get a product attribute value?


I have created an extra attribute ‘enquiry_only’ in the back-end, this is how I can retrieve the attribute value in the product info template page:
\public_html\app\design\frontend\base\default\template\catalog\product\

$enquiry_only = Mage::getModel('catalog/product')
                            ->load($_product->getId())
                            ->getAttributeText('enquiry_only');

Alternatively we can use like:

$prod = Mage::getModel('catalog/product')->load($_product->getEntityId());
					$prod = $prod->getData(); 								
					$enquiry_only = 'No';		
					$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'enquiry_only');
					foreach ( $attribute->getSource()->getAllOptions(true, true) as $option){
						if ($option['value'] == $prod['enquiry_only'])
							$enquiry_only = $option['label'];
					}	

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: