4

When I select a child product of a configurable product, and add it to the cart the correct simple child product image is displayed in the cart.

However if I add the same child product to the wishlist, the parent configurable product image is displayed.

I found the setting in Magento back end that controlled which image would be displayed in the cart, but I couldn't find a similar setting for the wishlist.

I also have been trying to fix this situation by changing the code in

app/design/frontend/customtheme/default/template/wishlist/item/column/image.phtml. 

However I have been unsuccessful.

Any help would be appreciated! Thanks

This is the code I have done so far; however now I don't have any image being displayed in my Wishlist. The file I am modifying is

app/design/frontend/customtheme/default/template/wishlist/item/column/image.phtml

and code is below

<?php
$item = $this->getItem();
$product = $item->getProduct();
$item_s = Mage::getModel('wishlist/item')->loadWithOptions($item->getId(), 'simple_product')->getOptionsByCode();
$simple_product = $item_s['simple_product']->getData();
$simple_product_id = $simple_product_data['product_id'];
$simple_product_attr = Mage::getModel('catalog/product')->load($simple_product_id);
?>
<a class="product-image" href="<?php echo $this->getProductUrl($item) ?>" title="<?php echo $this->escapeHtml($product->getName()) ?>">
     <img src="<?php echo $this->helper('catalog/image')->init($simple_product_attr ,'small_image'); ?>" alt="<?php echo $this->escapeHtml($product->getName()) ?>" />
</a>

Also here is the code with extraneous code removed:

$item = $this->getItem();
$product = $item->getProduct();
$item_s = Mage::getModel('wishlist/item')
     ->loadWithOptions($item->getId(), 'simple_product')
     ->getOptionsByCode();
$simple_product = $item_s['simple_product']->getData();
$simple_product_id = $simple_product_data['product_id'];
$simple_product_attr = Mage::getModel('catalog/product')
    ->load($simple_product_id);
<img src="<?php echo $this->helper('catalog/image')
    ->init($simple_product_attr ,'small_image'); ?>" />
2
  • Can you show what you've tried, it can be a simple fix.
    – user4351
    Commented Mar 10, 2015 at 20:00
  • @Melvyn sure. I edited my original post to show what I have done so far. I have also tried using getThumbnail() from the checkout for a while, but have given up on that approach since three files are required for that function.
    – SeanM
    Commented Mar 10, 2015 at 22:34

2 Answers 2

1
$_product_id = $item->getData('product_id');
$_simple_product_id = Mage::helper('nhuthep')->getSimpleProductIdInWishlist($item->getData('wishlist_item_id'), $_product_id);
if ($_product_id != $_simple_product_id) {
    $_simple_product = Mage::getModel('catalog/product')->load($_simple_product_id);
}

if (isset($_simple_product) && $_simple_product->getId()) {
    $_small_image = $this->helper('catalog/image')->init($_simple_product, 'small_image');
} else {
    $_small_image = $this->helper('catalog/image')->init($product, 'small_image');
}

with helper nhuthep I have a function getSimpleProductIdInWishlist like this:

public function getSimpleProductIdInWishlist($wishlistItemId, $itemProductId)
{
   $wishlistItemOptions = Mage::getModel('wishlist/item_option')
      ->getCollection()
      ->addFieldToFilter('wishlist_item_id', $wishlistItemId);

   foreach ($wishlistItemOptions as $option) {
       $optionProductId = $option->getProductId();
       if ($optionProductId != $itemProductId) {
           return $optionProductId;
          }
       }

   return $itemProductId;
}

You can also get product name or product url of child product.

0

In default Magento you can select which you want to show in the Cart.

Goto System / Configuration -> Sales/Checkout -> Checkout -> Configurable product image

Change to Parent Product Thumbnail or Product Thumbnail self and do not change anything yourself.

2
  • This will work only for the Shopping Cart images. Not for the Wishlist pages.
    – PHP Bugs
    Commented Apr 21, 2015 at 10:44
  • Then you should do a minor change in copy/pasting from cart/items.phtml -> wishlist...
    – Jeroen
    Commented Apr 29, 2015 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.