开发者

use the category default image as products default image

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 开发者_C百科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


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


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 :) )

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜