如何在Magento中获取关联的产品属性文本值?

时间:2014-02-19 18:41:31

标签: php magento attributes

$ ap_product是相关产品(简单产品)。即使它是一个简单的产品,我也不能使用方法getResource(),因为$ ap_product在catalog / product_type_configurable类中。我知道多种方法来获取颜色属性的值(例如:255代表红色),但我无法得到实际的文本“红色”。

getResource()->getAttribute("color");

if($attribute->usesSource()){
$apColorSizeValue = $attribute->getSource()->getOptionValue($test);
}

此方法也不适用,因为它是一个相关产品,而不仅仅是一个简单的产品。

 $_product->getAttributeText('color');

我还尝试重新加载产品型号,但加载了相关的产品ID。那也行不通。所以现在我有相关的产品ID和相关的产品属性颜色值来使用。我需要获取关联的产品属性颜色文本。

1 个答案:

答案 0 :(得分:0)

这项工作对我来说

$_associatedProduct = $ap_product->getId();
$_colorAttributeId = Color_ID
$query = "select cpei.value as id,eapv.value as value from catalog_product_entity_int cpei LEFT JOIN eav_attribute_option_value eapv on cpei.value = eapv.option_id where cpei.entity_id=" . $_associatedProduct. " and cpei.attribute_id = " . $_colorAttributeId . " limit 1";
$color = $_readConnection->fetchAll($query);

感谢