Magento – Show image of associated product selected, rather than configurable product on wishlist page

magento-1.8productwishlist

I am trying to get the image of child (associated product) of a configurable product on wishlist page. Currently, parent image is shown which is not desired.

What I already have done:

In this file, I have been trying to get it:

 /template/wishlist/item/column/image.phtml

//my code
if ($product->getHasOptions()) { // mean it is configurable product
$my_options = new Mage_Wishlist_Block_Customer_Wishlist_Item_Options();
$my_config_options = $my_options->getConfiguredOptions();
if ($my_config_options) {
//try to find some link to the image
}

But it is not helping out. My above code may not be good enough, but I am just trying to reflect that I did try it myself.

Best Answer

This what I used to get simple product image to show in wishlist instead of configurable product image. You need to get the simple/child product ID of associated product and then get its attributes, in this case image.

$item_s = Mage::getModel('wishlist/item')
     ->loadWithOptions($item->getId(), 'simple_product')
     ->getOptionsByCode();
$simple_product = $item_s['simple_product']->getData();
// Simple product id
$simple_product_id = $simple_product_data['product_id'];
// Load associated product attribute by id
$simple_product_attr = Mage::getModel('catalog/product')->load($simple_product_id);
// Get Image
$simple_product_img_url = $this->helper('catalog/image')->init($simple_product_attr ,'small_image');

echo $simple_product_img_url into the html img src attribute.

Related Topic