Magento 如何仅显示分配给产品属性值的内容?
我正在使用并试图通过使用此代码在产品视图页面上获取属性的图像和缩略图Magento 如何仅显示分配给产品属性值的内容?,magento,Magento,我正在使用并试图通过使用此代码在产品视图页面上获取属性的图像和缩略图 $_product = $this->getProduct(); $_attribute = $_product->getResource()->getAttribute('color'); $_options = $_attribute->getSource()->getAllOptions(false); foreach ($_options as $_option) { echo
$_product = $this->getProduct();
$_attribute = $_product->getResource()->getAttribute('color');
$_options = $_attribute->getSource()->getAllOptions(false);
foreach ($_options as $_option) {
echo $_option['image'];
echo $_option['thumbnail'];
}
所以它显示了该属性的所有选项,而不是指定给产品的选项
如何仅显示分配给属性的产品值
我真的很感激任何帮助 您应该通过以下方式进行更正:
$_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
}
}