Magento Attributes – Custom Image Attribute Not Displayed on Search List

attributescatalogsearchimageproduct-list

I have a custom media image attribute called hover_image as you may understand when a customer hovers on the product image hover_image shows up.

This works with catalog list but when I search for a product the list that comes up does not show the image that I uploaded to hover_image. It shows placeholder that I uploaded for hover_image from system>configuration>catalog

This is the code that I use for displaying hover image in the list.phtml view

 <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image">
    <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(400,600); ?>" width="300" height="400" 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(400,600) ?>';" onmouseout="this.src='<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(400,600) ?>';" />
</a>

Best Answer

Make sure the hover_image attribute is marked as 'Used in product listing'.
Unfortunately, for some reason still unknown to me, you cannot set that flag for media attributes from the backend. But you can do it directly in the db.
Just run this query to identify the attribute id.

SELECT * FROM eav_attribute WHERE attribute_code = 'hover_image'

After getting that id, just run this to this to set the correct flag

UPDATE `catalog_eav_attribute` SET `used_in_product_listing` = 1 WHERE `attribute_id` = {value from above}

Reindex everything and it should work.

I know that can be done from a single query but it's easier to follow this way.

Related Topic