Get all attribute options
To get all attribute options from a Magento dropdown attribute (select field) you can use the following snippet:
1 2 3 4 |
<?php $oAttibute = Mage::getModel('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, 'sheldon_special'); $aOptions = $oAttibute->getSource()->getAllOptions(); var_dump($aOptions); |
That gives you an array like that:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<?php $aOptions = {array} [6] 0 = {array} [2] label = "" value = "" 1 = {array} [2] label = "best" value = "306" 2 = {array} [2] label = "new" value = "305" 3 = {array} [2] label = "no" value = "304" 4 = {array} [2] label = "sale" value = "307" 5 = {array} [2] label = "special" value = "632" |
This can be used as source for a system config field for example. See my blogpost about Category dropdown element. To get a specific value by given label, you can […]