Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento 如何仅显示分配给产品属性值的内容?_Magento - Fatal编程技术网

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
    }
}