Magento – How to get image of configurable product

configurable-productimagemagento-1.9

How can I get image of configurable product.
I found this code but it returns null

$_swatchUrl = Mage::helper('configurableswatches/productimg');

Best Answer

The methods available in the helper you mentioned allows you to retrieve the image urls for the configurable swatches. For example the url of pink/white/blue swatch url for a super attribute such as color (ex: media/catalog/swatches/1/21x21/media/pink.png). You can check in .../configurable/swatches.phtml how is being used by the core:

$_swatchUrl = Mage::helper('configurableswatches/productimg') ->getSwatchUrl($_product, $_option->label, $_swatchInnerWidth, $_swatchInnerHeight, $_swatchType);

But you want to take the image of a parent/configurable product so just follow the code from .../catalog/product/view/media.phtml

src="<?php echo $this->helper('catalog/image')->init($_product, 'image') ?>"
which is retrieving the image of the product in the product view/page.

Note: above sample of codes were taken from Magento ver. 1.9.2.4