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!

9

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'));
  • Can I dynamically use it for certain type of products (eg: customizable product) – Tusar Jun 10 '14 at 12:13
  • 1
    In the event you can do all checks you want on both: product and quote_item, so yes. – Fabian Blechschmidt Jun 10 '14 at 12:19
  • Where would you put this code? Sorry, trying to perform a patch job and unfamiliar with Magento – Bryant Jackson Mar 15 '18 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. – Fabian Blechschmidt Mar 15 '18 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. – manish_khot May 8 '19 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.

  • Can you plz. sample code and file Path for this ? – Tusar Jun 10 '14 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 Jun 10 '14 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 – Butterfly Jun 22 '15 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 Jun 22 '15 at 9:06
  • I asked a question and you closed it as duplicate magento.stackexchange.com/questions/71721/… and referred this one, – Butterfly Jun 22 '15 at 9:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.