Magento 1.9 - Get all options of a dropdown or multiselect attribute in magento

Below is the example code.

this may be any attribute code

$arg_attribute = "manufacturer";

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

print_r($options); 

Below is comple code

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

//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
print_r($options); 

No comments:

Post a Comment