To get the image src in a template file the following code is used:
$this->helper('catalog/image')->init($_product, 'small_image')->resize(200,100);
But how开发者_JAVA技巧 can I find out if there is an image associated with the product or if the placeholder image will be used?
(Magento v. 1.4.2)
Placeholder is always used if product dosen't have image.
You can check those methods:
$product->getSmallImage();
$product->getThumbnail();
$product->getImage();
If product has image those moethod will return path.
Or you can check this method
$product->getMediaGalleryImages();
UPDATE 14.10.2011
no_selection
is set when you check in BO > Product Edit Page > Images 'No image' chackbox
Best solution is:
if($_product->getImage() && $_product->getImage() != 'no_selection'){//do}
精彩评论