I'm using the following code to add cart products manually.

The following code works fine, except that I would like to change the cart product thumbnails.

Can some one help me with the thumbnail part? Here is my code.

$session = Mage::getSingleton('customer/session');

// Get cart instance
$cart = Mage::getSingleton('checkout/cart');

// Add a product with custom options
$productId = 3;
$productInstance = Mage::getModel('catalog/product')->load($productId);
$param = array(
    'product' => $productInstance->getId(),
    'qty' => 1
$request = new Varien_Object();
$cart->addProduct($productInstance, $request);

// update session

// save the cart
| improve this question | | | | |
  • Are you using this code magento frontend system – Amit Bera May 24 '15 at 14:31
  • @AmitBera Yes.. – user1897581 May 24 '15 at 19:39

You can try like this:

$product->getMediaUrl( $product->getImage() ); //getSmallImage(), getThumbnail()

Sometimes though you have only one image and want to set all sizes to that same image like so:

if (!$product->hasImage()) continue;
    if (!$product->hasSmallImage()) $product->setSmallImage($product->getImage());
    if (!$product->hasThumbnail()) $product->setThumbnail($product->getImage());

And if you want to see which data you can access in the array:

| improve this answer | | | | |

Check out the renderer-templates in app/design/frontend/rwd/default/template/checkout/cart/render

As an example for a simple product (taken from app/design/frontend/rwd/default/template/checkout/cart/render/simple.phtml):

<a href="<?php echo $this->getItemUrl($_item) ?>" title="<?php echo $this->escapeHtml($this->getItemName($_item)) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($this->getItemProductForThumbnail($_item), 'thumbnail')->resize(75); ?>" width="75" height="75" alt="<?php echo $this->escapeHtml($this->getItemName($_item)) ?>" /></a>

Interesting for you is the parameter 'thumbnail' in the init method of the catalog image helper. This refers to the settings from the images tab of your products where you can define different images for the base image, small image and thumbnail. Upload another picture and copy the renderer-template to your package/theme to adjust the parameter.

Even easier: Upload the image in the Magento Admin and select it as Thumbnail image and it will show up in the checkout (and everywhere the thumbnail image is used).

| improve this answer | | | | |
  • I'm selling iphone cases. So i'm letting my users customize cases using their own images. Finished image will be used as cart product thumbnail and only for that particular order. So I don't think your suggestion would work. Thanks for your input. Appreciate that very much. – user1897581 May 24 '15 at 19:43
  • I see, so you cannot use the images defined in the backend anyway. Just replace the img src="" input with a link to the customized image then. – Anna Völkl May 24 '15 at 19:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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