Magento – Get Attribute option Id by Attribute admin value

attribute-optionsattributescustom-options

For a Magento Dropdown Attribute, it is possible to get an Attribute option Id by Attribute admin value?

Best Answer

Suppose, you have an product attribute called "color" in Magento. You have the attribut admin value (e.g. Purple), and you want to find it’s value. The below code will help you get the value for it.

$_product = Mage::getModel('catalog/product');
$attr = $_product->getResource()->getAttribute("color");
if ($attr->usesSource()) {
echo $color_id = $attr->setStoreId(0)->getSource()->getOptionId("Purple");
}