Magento Product Attribute Get Value

后端 未结 13 1637
暗喜
暗喜 2020-12-02 05:32

How to get specific product attribute value if i know product ID without loading whole product?

13条回答
  •  星月不相逢
    2020-12-02 06:04

    You could write a method that would do it directly via sql I suppose.

    Would look something like this:

    Variables:

    $store_id = 1;
    $product_id = 1234;
    $attribute_code = 'manufacturer';
    

    Query:

    SELECT value FROM eav_attribute_option_value WHERE option_id IN (
        SELECT option_id FROM eav_attribute_option WHERE FIND_IN_SET(
            option_id, 
            (SELECT value FROM catalog_product_entity_varchar WHERE
                entity_id = '$product_id' AND 
                attribute_id = (SELECT attribute_id FROM eav_attribute WHERE
                    attribute_code='$attribute_code')
            )
        ) > 0) AND
        store_id='$store_id';
    

    You would have to get the value from the correct table based on the attribute's backend_type (field in eav_attribute) though so it takes at least 1 additional query.

提交回复
热议问题