1

Is it possible to disable the merging of same products into one position in the cart?

So when someone adds Product ABC with Qty 1 to the cart, continues shopping and adds the same product again with Qty 2, Magento merges/sums the two products into one position with a Qty of 3.

I’d like to have 2 cart positions with Product ABC with their respective quantities. Is that possible?

The only thing I was finding while looking through the code was Mage_Sales_Model_Quote::merge, but that doesn't seem to be the right method as it handles merging the carts from a former session after logging in.

Thanks a lot!

2 Answers 2

10

You can just add an option to the product in the event sales_quote_add_item:

$data['microtime'] = microtime(true);

$product->addCustomOption('do_not_merge', serialize($data));
$item->addOption($product->getCustomOption('do_not_merge'));
6
  • Can I dynamically use it for certain type of products (eg: customizable product)
    – Tusar
    Commented Jun 10, 2014 at 12:13
  • 1
    In the event you can do all checks you want on both: product and quote_item, so yes. Commented Jun 10, 2014 at 12:19
  • Where would you put this code? Sorry, trying to perform a patch job and unfamiliar with Magento Commented Mar 15, 2018 at 19:51
  • You implement your own module, add an observer, which listens to the event sales_quote_add_item , get the quote item just added from the $observer and run the code on the $item. Commented Mar 15, 2018 at 20:46
  • @fabian-blechschmidt : I tried this code it is working fine when I add product from product-details page. But when I change the quantity from the 'checkout/cart' this solution is not working. Commented May 8, 2019 at 4:41
5

When adding a product to the cart, this method is called to see if the product with the same options are already in cart. Mage_Sales_Model_Quote_Item::representProduct($product). If you override this and make it return false every time, you should achieve your desired result. It worked for me in the past.

7
  • Can you plz. sample code and file Path for this ?
    – Tusar
    Commented Jun 10, 2014 at 9:50
  • 1
    @Tusar. I think you should use the answer provided by Fabian (the accepted answer). It's cleaner and non intrusive. You just have to create an observer for an event. You should find tutorials about that on the web.
    – Marius
    Commented Jun 10, 2014 at 9:54
  • @Marius already I have an event handle checkout_cart_product_add_after how can I have <sales_quote_add_item> handle? Can I add two observer events in a same module observer file, sorry for incorrect terminology I used, but hope you understand what I am asking
    – Anto S
    Commented Jun 22, 2015 at 8:55
  • @new_bee_magento. What does your comment have to do with this question or answer? Please don't mix them. Ask a separate question.
    – Marius
    Commented Jun 22, 2015 at 9:06
  • I asked a question and you closed it as duplicate magento.stackexchange.com/questions/71721/… and referred this one,
    – Anto S
    Commented Jun 22, 2015 at 9:08

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.