即时使用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 :(得分: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
}
}