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.
Where will i add this code ? Would you please guide me that how can i do this ?
Thanks !
Hi,
You can add this code in the observer when product is added to cart.
Above code shows when you add product to cart programmatically.
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 !
See this SO answer for more information: http://magento.stackexchange.com/a/24718/2294
For the love of god man instruct as to what file or your information is useless , get your head in the game !!