Reputation: 549
I've been searching for hours now and haven't found any solution to this problem. I need to get the option ID for a configurable product. The current informations I have are the SKU, the attribute set ID and the option label. How can I fetch the option ID using these values?
Many thanks to those who can help me.
** UPDATE **
Here's a sample of the database table eav_attribute_option_value (from wich I'm guessing Magento take the value for the ID)
value_id option_id store_id value
729141 57 0 Rose
729142 57 3 Rose
729143 57 1 Pink
728847 749 0 Pink
728848 749 3 Pink
728849 749 1 Pink
I need to get the value ID 57. When the locale is in french, I get the right value. But when I switch to english, I get the ID 749, which is from another attribute set.
Upvotes: 4
Views: 10699
Reputation: 11494
My own query for getting the attribute option id from the database. All you must specify is the attribute name and the value. E.g:
SELECT ao.option_id
FROM `eav_attribute_option` AS ao, `eav_attribute_option_value` AS av
WHERE ao.option_id = av.option_id
AND av.value LIKE 'dragon'
AND ao.attribute_id IN
(SELECT attribute_id
FROM eav_attribute
WHERE attribute_code
LIKE 'manufacturer')
Upvotes: 0
Reputation: 4331
If you want to fetch the option id you do it easily just like this :
$productModel = Mage::getModel('catalog/product')->load('1234', 'sku');
$attr = $productModel->getResource()->getAttribute("color");
if ($attr->usesSource()) {
echo $color_id = $attr->getSource()->getOptionId("Red");
}
For details you can check this link
Upvotes: 4