Magento – Magento Product image on Hover not working

magento-1.9media-imagesproductproduct-attributeproduct-images

I want to add a hover image for my product.

So the first step :

1- i've create a new attribute with code named hover_image for all types of the products.

2- in php file catalog->product->list.phtml i've add onmouseover javascript function to image tag like below

onmouseover="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'hover_image')->resize(500,659)?>'"

but it's not working any suggestions ?

Best Answer

here is working code you can try this

<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(224); ?>" width="226" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" onmouseover="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'hover_image')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(224) ?>';" onmouseout="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(224) ?>';" />