【问题标题】:How to get associated product attribute text value in Magento?如何在 Magento 中获取相关的产品属性文本值?
【发布时间】:2014-02-19 18:41:30
【问题描述】:

$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 和相关的产品属性颜色值可以使用。我需要获取相关的产品属性颜色文本。

【问题讨论】:

    标签: php magento attributes


    【解决方案1】:

    这对我有用

    $_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);
    

    谢谢

    【讨论】:

      猜你喜欢
      • 2013-12-11
      • 1970-01-01
      • 2018-03-27
      • 1970-01-01
      • 2016-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多