在 Magento 中添加新产品图像类型(属性)
我正在尝试在产品管理面板中添加新的图像类型。我创建了一个新属性(hero_banner),将其类型设置为媒体图像(类似于缩略图图像和小图像的设置方式)。然后我将其添加到图像下的默认属性集中。它在管理面板中看起来很好,并允许您将图像指定为英雄,但是当我尝试将图像路径回显到 phtml 中时,模板停止渲染。我用来回显图像的代码如下:
<?php echo $this->helper('catalog/image')->init($_product, 'hero_banner'); ?>
这是在产品 foreach 迭代中完成的,因此我有 $_product 变量,并且我能够很好地回显其他图像(例如缩略图、small_image 等)。我做错了什么?
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). 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. 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). What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为在实际加载集合之前,您也必须在集合中选择此属性:
它在我的代码上运行良好,但我不知道您是否已经重写了定义集合的块(它不起作用)在您的模板中,因为集合已经加载到那里)
也许你可以配置你的hero_attribute直接在Magento后台添加这个addAttributeToSelect,我会看看
编辑:好的,我想我已经明白了,你不必担心收集和删除。重写:)
如果您在产品列表中使用此属性,则必须将图像属性的“在产品列表中可见”属性设置为 true(在管理面板属性管理中)
祝您好运
I think you have to select this attribute too in your collection like this before the collection is actually loaded:
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
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)
Good luck