If you have a select dropdown for any product attribute, to get the value from label or vice versa is always needed in order to display or get value for further processing.Get product attribute’s value from label, label from value easily in Magento.
Suppose, you have an product attribute called “color” in Magento. You have the label (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->getSource()->getOptionId("Purple");
}
Now suppose, you have the value (let’s say 10, for Purple) for your attribute, but want to get the label for it. Below code will help you to achive it.
$_product = Mage::getModel('catalog/product');
$attr = $_product->getResource()->getAttribute("color");
if ($attr->usesSource()) {
echo $color_label = $attr->getSource()->getOptionText("10");
}