Magento gets the option identifier for the specified set of attributes and value

I searched the clock and did not find a solution to this problem. I need to get the parameter identifier for a custom product. Current information I have SKU, attribute set identifier and option label. How can I get the parameter identifier using these values?

Many thanks to those who can help me.

** UPDATE **

Here's an example of the eav_attribute_option_value database table (from which I assume Magento takes a value for an identifier)

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 an ID value of 57. When the locale is in French, I get the correct value. But when I switch to English, I get ID 749, which is from a different set of attributes.

+4
source share
2 answers

If you want the option identifier, you can easily do this:

  $productModel = Mage::getModel('catalog/product')->load('1234', 'sku'); $attr = $productModel->getResource()->getAttribute("color"); if ($attr->usesSource()) { echo $color_id = $attr->getSource()->getOptionId("Red"); } 

See link for more details.

+4
source

My own request is to get the attribute parameter identifier from the database. All you have to specify is an attribute name and value. For instance:

 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') 
0
source

Source: https://habr.com/ru/post/1497878/


All Articles