0

Steps :

  1. When I add any product to cart and go to the checkout page.
  2. On the checkout page when I login with customer who added product previously then the product will be added to the cart.

I want to stop or remove this functionality so what steps should I follow.

1 Answer 1

1

You may create an event to delete existing quote items when merging quotes. Somewhat like below.

etc/events.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="sales_quote_merge_before">
        <observer name="remove_old_quote_items" instance="Vendor\Module\Observer\RemoveOldQuoteItems" />
    </event>
</config>

Observer/RemoveOldQuoteItems.php

<?php

namespace Vendor\Module\Observer;

use Magento\Framework\Event\ObserverInterface;

class RemoveOldQuoteItems implements ObserverInterface
{
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        if ($observer->getQuote()->getAllVisibleItems()) {
            foreach ($observer->getQuote()->getAllVisibleItems() as $item) {
                $observer->getQuote()->removeItem($item->getId())->save();
            }
        }

        return $this;
    }
}
1
  • Thanks bro it is working like charm ! Commented Nov 19, 2019 at 10:09

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.