简体   繁体   English

在 Magento 中添加新的产品图像类型(属性)

[英]Add New Product Image Type (Attribute) in Magento

I am trying to add a new image type in the product admin panel.我正在尝试在产品管理面板中添加新的图像类型。 I created a new attribute (hero_banner) set it's type to media image (similar to how the thumbnail image and small_image have been set up).我创建了一个新属性 (hero_banner),将其类型设置为媒体图像(类似于缩略图图像和 small_image 的设置方式)。 I then added it to the Default attribute set under images.然后我将它添加到图像下的默认属性集。 It appears fine in the admin panel and allows you to assign images as the hero but then when I try and echo the image path into the phtml the templates stop rendering.它在管理面板中看起来很好,并允许您将图像指定为英雄,但是当我尝试将图像路径回显到 phtml 时,模板停止渲染。 The code I am using to echo the image is below:我用来回显图像的代码如下:

<?php echo $this->helper('catalog/image')->init($_product, 'hero_banner'); ?>

This is being done within a product foreach iteration so I have the $_product variable and I am able to echo other images fine (such as thumbnail, small_image etc).这是在产品 foreach 迭代中完成的,所以我有 $_product 变量,我能够很好地回显其他图像(例如缩略图、small_image 等)。 What am I doing wrong?我究竟做错了什么?

I think you have to select this attribute too in your collection like this before the collection is actually loaded:我认为在实际加载集合之前,您也必须像这样在集合中选择此属性:

$productCollection->addAttributeToSelect('hero_banner');

It works fine on my code, but I dont know if you already have rewrited the block where your collection is defined (it won't work in your template since the collection is already loaded there) Maybe you can configure your hero_attribute to add this addAttributeToSelect directly in Magento back office, I'll have a look它在我的代码上运行良好,但我不知道您是否已经重写了定义集合的块(它不会在您的模板中工作,因为集合已在那里加载)也许您可以配置您的 hero_attribute 以添加此 addAttributeToSelect直接在 Magento 后台,我去看看

Edit: Ok, I think I've got it, you won't have to worry about collection & rewrites :) If you use this attribute on product listing, you have to set the property "visible on product listing" to true to your image attribute (in the admin panel attribute management)编辑:好的,我想我知道了,您不必担心收集和重写:) 如果您在产品列表中使用此属性,则必须将属性“在产品列表上可见”设置为 true图像属性(在管理面板属性管理中)

Good luck祝你好运

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM