Magento® – Show Same Product in Different Lines in Cart

In Magento sometimes you may want to show same product as different line items in cart, checkout and admin. You may want to do this when you are adding same product but with different options in cart. If you want to do this, here is the simple way do do it.

<?php
// Load the product
$product = Mage::getModel('catalog/product')->load($product_id);
$cart = Mage::helper('checkout/cart')->getCart();

// Add product to cart
$cart->addProduct($product, 1);
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
$cart->save();

// Get the recently added quote item
$quote = Mage::getSingleton('checkout/session')->getQuote();
$quote_item = $quote->getItemByProduct($product);

if ($quote_item) {
    // Add custom option to quote item
    // a random number will differentiate it from other similar products
    $quote_item->addOption(array(
          "code" => "random",
          "value" => serialize(array(time()))
    ));
    $quote_item->save();
}

Now when you will see the cart, all products will appear in different rows.

Written by Arvind Bhardwaj

Arvind is a Magento and WordPress expert with more than 6 years of industry wide experience.

Website: http://www.webspeaks.in/

5 thoughts on “Magento® – Show Same Product in Different Lines in Cart

      1. Can u show u this ? (i have tried it with CartController in app/code/core.. but it isnt right) Sorry because im beginer with Magento, im going to change/edit Core code or make a new file in app/local. Only know i do that @@

        Thanks in advance !

Comments are closed.