小编jdh*_*aar的帖子

Magento中的自定义图像属性在未设置任何图像时生成错误,并从产品视图页面调用

我创建了一个自定义图像属性,并将其添加到Magento中的默认属性集中.我的新属性是img_supportimg_upgrade.我使用以下代码在产品视图页面上显示了这两个图像:

<?php if ($_product->getimg_upgrade()):
 $_img = '<img src="'.$this->helper('catalog/image')->init($_product, 'img_upgrade')->resize(85).'" alt="'.$this->htmlEscape($this->getImageLabel()).'" title="'.$this->htmlEscape($this->getImageLabel()).'"  "/>';
 echo $_helper->productAttribute($_product, $_img, 'img_upgrade');
 endif; 
?>
Run Code Online (Sandbox Code Playgroud)

具有第二个自定义图像属性名称的相同代码将显示img_support图像.当我设置图像并为这两个属性选择它们时,它们将显示正常,但是当没有上传和选择这些属性的图像时,我尝试在产品视图页面上显示它然后它会生成错误.像这样的东西:

a:5:{i:0;s:25:"Image file was not found.";i:1;s:3911:"#0 C:\Program Files\EasyPHP-    5.3.8.0\www\mymagentoroot\app\code\core\Mage\Catalog\Helper\Image.php(163):
Mage_Catalog_Model_Product_Image->setBaseFile('no_selection').....
Run Code Online (Sandbox Code Playgroud)

之后有很长的痕迹.所以基本上它即使没有选择图像也会取出图像.谁能告诉我如何在所选产品的产品视图页面中显示我的自定义图像?我有10个产品,默认属性设置.因此,所有这10个产品都可以使用img_support和img_upgrade设置,但我想仅在5个选定的产品上显示自定义图像.如果图像设置显示.否则不要.我怎样才能做到这一点?如果有任何其他正确或更好的方法来做到这一点,那么帮助我在这里.谢谢!

attributes product image magento

2
推荐指数
1
解决办法
6613
查看次数

标签 统计

attributes ×1

image ×1

magento ×1

product ×1