使用类别默认图片作为产品默认图片
在 magento 中,您可以将图像设置为显示在产品上方的类别。 是否可以使用类别图片作为默认产品图片? 如果产品有图像,它将使用它,但如果没有图像,并且其第一个类别有图像,它将使用它。
最简单的方法是覆盖产品块和模板,并在没有图像的情况下查找每个产品的类别和图像,但这会增加许多查询。对于类别视图,我可以进行一次查询,但对于搜索结果,我必须对每个产品进行一次查询,因为每种产品可以来自不同的类别。
有更好的方法吗? 也许使用自定义类别设计或覆盖索引?
谢谢
In magento you can set an image to a category which is shown above products.
Is it possible to use the category image as the default product image instead?
If a product has an image it'll use it but if it doesn't and its first category has an image it will use it.
The simplest way is to override the product block and template and to find the category and image for each product without an image but that will add many queries. For category view I can make one query but for search result I'll have to make one query per product because each product can be from a different category.
Is there a better way to do it?
Maybe with custom category design or overriding indexes?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常用于生成这些图像的助手 (Mage_Catalog_Helper_Image) 有一个方法
placeholder($filename)
应该设置占位符图像 URL。您应该能够在显示类别产品之前设置该图像,以使用类别图像作为占位符图像。希望有帮助!
谢谢,
乔
The helper usually used to generate those images (Mage_Catalog_Helper_Image) has a method
placeholder($filename)
that should set the placeholder image URL. You should be able to set that image before displaying the category products to use the category image as the placeholder image.Hope that helps!
Thanks,
Joe
为了完成 Joseph 和 Pablo 的回答,在 Magento 1.9.1 上,它在助手的 __toString() 方法中使用。
请注意,当调用 $this->helper('catalog/image')->placeholder($placeholder) 时,$placeholder 是皮肤目录中的相对文件路径,因此它几乎不能用于您的问题(我的也没有,我会用你的解决方案:))
To complete Joseph and Pablo answer, on Magento 1.9.1, it is used in the __toString() method of the helper.
Note that when calling $this->helper('catalog/image')->placeholder($placeholder), $placeholder is a relative file path in the skin directory, so it can barely be used for your problem (mine neither, I'll do with your solution :) )