Monday, August 27, 2012

Magento : Get all options of a dropdown or multiselect attribute

Magento : Get all options of a dropdown or multiselect attribute

$arg_attribute = "manufacturer";//this may be any attribute code

//Object of attribute model

$attribute_model = Mage::getModel('eav/entity_attribute');

//Object of attribute options model

$attribute_options_model= Mage::getModel('eav/entity_attribute_source_table') ;

//

$attribute_code = $attribute_model->getIdByCode('catalog_product', $arg_attribute);

$attribute = $attribute_model->load($attribute_code);

$attribute_table =$attribute_options_model->setAttribute($attribute);

//Getting all options

$options = $attribute_options_model->getAllOptions(false);

//Printing all options of particular attribute

echo "<pre />";

print_r($options);