11

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

Rup
  • 33,765
  • 9
  • 83
  • 112
Robban
  • 1,191
  • 2
  • 13
  • 25

2 Answers2

27

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

xyz
  • 2,277
  • 2
  • 25
  • 41
  • 7
    Nice, for some reason I got the string "no_selection" returned on some products where the place-holder image was used, so right now I'm using `$has_real_image_set = ($_product->getSmallImage() != null && $_product->getSmallImage() != "no_selection");` – Robban Feb 19 '11 at 11:56
  • 1
    the good thing about getimageurl() is it tests if the image actually exists, whereas getimage() just shows you the path. both usefull for diffierent things, though you could do php file exists... – Hayden Thring May 31 '13 at 01:39
3

Best solution is:

if($_product->getImage() && $_product->getImage() != 'no_selection'){//do}
Javad Masoumi
  • 347
  • 2
  • 5