2014-02-19 34 views
0

$ ap_product是關聯的產品(簡單產品)。儘管它是一個簡單的產品,但我不能使用getResource()方法,因爲$ ap_product位於catalog/product_type_configurable類中。我知道多種方法來獲取顏色屬性的值(例如:255代表紅色),但我無法獲得實際文本「紅色」。如何在Magento中獲取關聯的產品屬性文本值?

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

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

而且這種方法不會與工作,因爲其相關的產品,而不僅僅是一個簡單的產品。

$_product->getAttributeText('color'); 

我也嘗試重新加載產品模型,但加載相關的產品ID。那也行不通。所以現在我有相關的產品ID和相關的產品屬性顏色值來處理。我需要獲得關聯的產品屬性顏色文本。

回答

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

謝謝

相關問題