Once user Uploaded custom image on Product image & Add item to cart, than we want to display custom image below "Recently added items" instead of normal product image.

enter image description here

custom uploaded image :

enter image description here

we are saving custom image in path : media/custom_options/quote . custom image path in table : "sales_flat_quote_item_option" in column : "value"

enter image description here

1.code to display normal product image :


<!--Custom product image code -->

<?php $_helper = $this->helper('catalog/output'); 
$_product = $this->getProduct();

    // code for display custom image    



<!--Normal product image code -->

<?php echo $this->getProductThumbnail()->resize(50, 50)->setWatermarkSize('30x10'); ?>

I tried below code , but its not displaying custom image under Recently added items : Mage_Checkout_Block_Cart_Item_Renderer.php

protected function _getImageSrc($optionValue)
            $pathNew = str_replace(DS.'media'.DS.'custom_options', '', $optionValue['order_path']);
            $image = Mage::getModel('aitcg/image');
            $image->copyImage($optionValue['fullpath'], $image->getEmailPath().$pathNew);
            return $image->getEmailUrl().$pathNew;

        return false;

As we are saving custom image in path : media/custom_options/quote how to display that custom image under "Recently added items".....

  • from where exactly you are getting that customized image tag ? Feb 14, 2017 at 6:16
  • @GopalPatel please visit link and upload image and save design and add to cart and go for cart page.... in cart page you can see both normal and customized image.... Feb 14, 2017 at 6:18
  • Looks like they are storing image as product option Feb 14, 2017 at 6:24
  • @GopalPatel please help me to display same image below Recently added items also..... Feb 14, 2017 at 6:25
  • Find the code from where they are creating div with id=""preview_container899967386" //any number on cart page. may be they are storing something into quote object Feb 14, 2017 at 6:33

4 Answers 4


Update your app/design/frontend/rwd/Stylebaby/template/checkout/cart/minicart/default.phtml file with below code,

$customImage = '';
$quoteOptions = $_item->getProduct()->getTypeInstance(true)->getOrderOptions($_item->getProduct());
    $customImage = $quoteOptions['info_buyRequest']['options'][132]["quote_path"];

Now update your image code with below.

<?php if ($this->hasProductUrl()): ?>
    <a href="<?php echo $this->getProductUrl()?>" title="<?php echo $this->escapeHtml($this->getProductName()) ?>" class="product-image">
    <?php if($customImage == ''){ ?>
    <img src="<?php echo $this->getProductThumbnail()->resize(50, 50)->setWatermarkSize('30x10'); ?>" width="50" height="50" alt="<?php echo $this->escapeHtml($this->getProductName()) ?>" />
    <?php } else { ?>
        <img src="<?php echo $this->getBaseUrl().$customImage; ?>" width="50" alt="<?php echo $this->escapeHtml($this->getProductName()) ?>" />
    <?php }
<?php else: ?>
    <span class="product-image">
    <?php if($customImage == ''){ ?>
    <img src="<?php echo $this->getProductThumbnail()->resize(50, 50)->setWatermarkSize('30x10'); ?>" width="50" height="50" alt="<?php echo $this->escapeHtml($this->getProductName()) ?>" />
    <?php } else { ?>
        <img src="<?php echo $this->getBaseUrl().$customImage; ?>" width="50" alt="<?php echo $this->escapeHtml($this->getProductName()) ?>" />
    <?php }
<?php endif; ?>
  • let me check and get back to you..... Mar 25, 2017 at 12:19
  • Thanks , almost working fine, need to replace image icon with real image..... Mar 25, 2017 at 12:53

Save custom image in database table and for cart page. Modify the Mage_Checkout_Block_Cart_Item_Renderer.php (rewrite class) override getProductThumbnail() and apply your saved custom image instead of default product image.

  • thanks, please update answer with code according to my requirements...... Feb 22, 2017 at 10:37
  • If u save image in database table sales_flat_quote_item, u will be able to get that image from item object ($this->getItem()). Then check that if the product is added after cutomizaation then return custom image and other wise return product image.
    – Ajay
    Feb 22, 2017 at 10:42
  • please check updated question...... Mar 21, 2017 at 11:58

In phtml displaying products in cart you have to add own logic for displaying base image. By default it is in app\design\frontend\base\default\template\checkout\cart\item\default.phtml

or app\design\frontend\base\default\template\checkout\cart\render\default(or simple).phtml

But on your store it should be in different theme.

There is line 33 :

<td><?php if ($this->hasProductUrl()):?><a href="<?php echo $this->getProductUrl() ?>" title="<?php echo $this->escapeHtml($this->getProductName()) ?>" class="product-image"><?php endif;?><img src="<?php echo $this->getProductThumbnail()->resize(75); ?>" width="75" height="75" alt="<?php echo $this->escapeHtml($this->getProductName()) ?>" /><?php if ($this->hasProductUrl()):?></a><?php endif;?></td>

and inside:

<img src="<?php echo $this->getProductThumbnail()->resize(75); ?>" width="75" height="75" alt="<?php echo $this->escapeHtml($this->getProductName()) ?>" />

code <?php echo $this->getProductThumbnail()->resize(75); ?> respond for displaying image product. You should make some logic checking in current product have custom design and depends on it display base image (thumbnail) or custom (design).

Also remove display image from recently added

  • Thanks , i am trying if($_product->getAttributeSetId()==9) this condition to display custom product image. but i am struck in what code is i need to use to display custom image under recently added items..... Mar 21, 2017 at 15:09

I done this functionality and successfully working in my project. Below are the steps for it.

  1. I added two column named as "custom_image" and "custom_flag" in table sales_flat_quote_item and sales_flat_order_item
  2. Set image source into hidden field in product_addtocart_form form. Using submit event of form I set value of image source into hidden filed.
  3. I used event "checkout_cart_add_product_complete" and in this event I get all post data including that image source in hidden field. Hidden field name is download_image_data. I created one folder tmpcartprodimg inside media. Add below code in observer.

    $product_id     = $this->_getRequest()->getPost('product_id');
    $currentDate    = Mage::getModel('core/date')->date('Y-m-d_H_i_s');
    $cart   = Mage::getModel('checkout/cart')->getQuote();
    $quote  = Mage::helper('checkout/cart')->getCart()->getQuote();
    $quote_item =  Mage::getModel('sales/quote_item')->load($quote->getItemByProduct($observer->getEvent()->getProduct())->getId());
    $quote_id   = $quote_item->getItemId();
    foreach ($cart->getAllItems() as $item) {
        if(($item->getProductId() == $product_id) && ($quote_id == $item->getId())) {
            $cart_id = $item->getId();
            $product_img    = md5($item->getProductId().$currentDate);
            $sales_quote = Mage::getModel('sales/quote_item')->load($item->getId());
            $sales_quote->setData('custom_flag' , 1);
            $sales_quote->setData('custom_image' , $product_img.".png");
            // Convert hidden value into image and store into tmpcartprodimg folder
            $image_base64_data  = $this->_getRequest()->getPost('download_image_data');
            $image_base64_data  = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $image_base64_data));
            $prod_image_name    = Mage::getBaseDir('media'). DS ."tmpcartprodimg". DS . $product_img .'.png';
            file_put_contents($prod_image_name, $image_base64_data);

4) You will get data of custom_image and custom_flag in app\design\frontend\base\default\template\checkout\cart\item\default.phtml by $_item->getCustomImage() You can write your code dispaly this image from tmpcartprodimg folder.

5) When quote will convert into order that time this fields need to be move into sales_flat_order_item table. You need to write code for it.

  • Thanks for your time and answer, custom image is already saving in db , all i need is to fetch that custom image and display in frontend. i need help for this..... Mar 24, 2017 at 7:47
  • Write code to get custom option value of image and replace it with product image in app\design\frontend\base\default\template\checkout\cart\item\default.phtml Mar 24, 2017 at 8:32

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.