Magento – Get option Value from Option label for product/store

attributesproductsql

Having a option value for an attribute I would like to get the code/id associated to this option value.

How can I get this ?

Sql/Magento model approach are both wellcome

EDIT:
I can retrieve option label for an attribute of a configurable product in this way:

function getRawAttribute($product, $attributeId)
{

$attributes = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);

foreach ($attributes as $attr)
    if ($attr['attribute_id'] == $attributeId) {
        foreach  ($attr['values'] as $option)
        $rawAttr[$option['value_index']] = $option['label'];
    }
return $rawAttr;

}

What is missed here for me is the possibility to get the label for a particular store view.

I'm going to evaluate info form this link:
http://blog.chapagain.com.np/magento-how-to-get-attribute-name-and-value/

Best Answer

Please use the following code to get the value from label

$attribute_f = Mage::getModel('eav/config')->getAttribute('catalog_product', 'atr_name');
foreach ( $attribute_f->getSource()->getAllOptions(true, true) as $opt_menuf)
{
    $f_attribute[$opt_menuf['value']] = $opt_menuf['label'];
}