2012-07-09 46 views
0

即時通訊使用https://github.com/witrin/magento-attribute-option-image/並試圖通過使用此代碼我如何顯示只分配給產品屬性值?

$_product = $this->getProduct(); 
$_attribute = $_product->getResource()->getAttribute('color'); 
$_options = $_attribute->getSource()->getAllOptions(false); 

foreach ($_options as $_option) { 
    echo $_option['image']; 
    echo $_option['thumbnail']; 
} 

因此它顯示我的屬性,而不是全部選擇分配給產品

怎麼做才能在產品視圖頁面圖像和屬性的縮略圖我只顯示分配給該屬性的產品價值?

我真的很感激任何幫助!

回答

0

您應該通過以下方式進行修正:

$_product = $this->getProduct(); 
$_attribute = $_product->getResource()->getAttribute('color'); 
$_options = $_attribute->getSource()->getAllOptions(false); 

foreach ($_options as $_option) { 

    //is this value assigned to the current product? 
    if ($_product->getColor() == $_option['value']) { 
     echo $_option['image']; 
     echo $_option['thumbnail']; 
     break; //we found it, no reason to continue searching 
    } 
} 
相關問題