Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find out if product has a product image?

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)

like image 435
Robban Avatar asked Feb 19 '11 08:02

Robban


2 Answers

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

like image 62
xyz Avatar answered Nov 09 '22 19:11

xyz


Best solution is:

if($_product->getImage() && $_product->getImage() != 'no_selection'){//do}
like image 3
Javad Masoumi Avatar answered Nov 09 '22 21:11

Javad Masoumi