Question

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');
$cart->init();

// 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();
$request->setData($param);
$cart->addProduct($productInstance, $request);

// update session
$session->setCartWasUpdated(true);

// save the cart
$cart->save();
Was it helpful?

Solution

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());
    $product->save();

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

var_dump(array_keys($product->getData()));

OTHER TIPS

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):

<td>
<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>
</td>

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top