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'];
}

所以它显示了该属性的所有选项,而不是分配给产品

如何显示仅分配给产品值的属性?

我真的很感激任何帮助!

4

1 回答 1

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
    }
}
于 2012-07-09T07:38:52.170 回答