January 12, 2010

Fetching all the options values of attribute.

The below post show he syntax of  fetching values of attribute furniturebrand.
“furniturebrand” attribute type is combo.
Syntax ::
$product = Mage::getModel(“catalog/product”);
$attributes = Mage::getResourceModel(“eav/entity_attribute_collection”)
->setEntityTypeFilter($product->getResource()->getTypeId())
->addFieldToFilter(“attribute_code”, “furniturebrand”) // This can be changed to any attribute code
->load(false);
$attribute = $attributes->getFirstItem()->setEntity($product->getResource()); /* @var $attribute Mage_Eav_Model_Entity_Attribute */
$sortby = $attribute->getSource()->getAllOptions(false);
foreach($sortby as $sort_attribute) {
echo $sort_attribute['value'];
}
The above foreach loop is to display all the values of attribute furniturebrand.

1 comment: