Whenever a customer logs in on the checkout page, my objective is to eliminate the old cart items (Abandoned Cart) from the checkout.

Currently, when a customer logs in on the checkout page and there are items left in the previous quote (Abandoned Cart) that were not purchased, Magento combines those items after login, following the default behavior.

I'd like Magento to retain only the current item in the cart and remove any previous items when the customer_login event occurs. I do not want this action to take place during the sale_quote_merge events (before or after).

Can you please provide guidance on how to achieve this in Magento 2?

2 Answers 2


You can use controller_action_postdispatch_customer_ajax_login event and set your observer accordingly.


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="customer_login">
        <observer name="controller_action_postdispatch_customer_ajax_login" instance="Vendor\Module\Observer\CustomerOldItem" />



namespace Vendor\Module\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\Quote\Model\QuoteRepository;

class CustomerOldItem implements ObserverInterface
    protected $quoteRepository;

    public function __construct(
        QuoteRepository $quoteRepository
    ) {
        $this->quoteRepository = $quoteRepository;

    public function execute(\Magento\Framework\Event\Observer $observer)
        $customer = $observer->getEvent()->getCustomer();
        $quote = $this->quoteRepository->getForCustomer($customer->getId());

You can use below event for checkout customer login page,

<event name="controller_action_postdispatch_customer_ajax_login">

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.