Get Attribute options and values

Posted: April 6, 2010 in Magento, Version 1.3.*
Tags: , , ,

// Add the attribute code here.
$attribute=$product->getResource()->getAttribute("color");
// Checking if the attribute is either select or multiselect type.
if($attribute->usesSource()){
// Getting all the sources (options)
$options = $attribute->getSource()->getAllOptions(false);
}
// print as label-value pair
echo '<pre>'. print_r($options) .'</pre>';

Thanks,
– Bijal Bhavsar 🙂

Advertisements
Comments
  1. Anupama says:

    Hi Bijal..

    Its useful to me .. thanks .. keep writing

  2. This will get the option value and is much simpler:

    $_product->getAttributeText($attributeCode)

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