0

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/

2 Answers 2

3

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'];
}
2

Inside an phtml file I use this code:

<?php echo $this->escapeHtml($_product->getAttributeText('technique')); ?>
2
  • I think you've got it backwards. My understanding of his question is that he wants to get the option_id itself from the front-end value. But in your example, you've provided code to get the attribute front-end value for a given product. Feb 25, 2013 at 17:48
  • yes this is not exactly what I want, also it doesn't work (return false), probably because my attibute is a select. Sorry for my not proper explanation
    – Fra
    Feb 25, 2013 at 18:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.