magento2 – How to stop the merging of unconnected basket items when the client connects?

I do not wish to merge cart items if the user has items in the cart and logs on to the site.

Let's review the scenario:

  1. The user logs in and adds an item to the cart and disconnects from a site.
  2. Now, as a guest user, he adds 2 items to the cart.
  3. It connects again on the site and sees 3 elements.

What am I trying to achieve? What I want to do is that, when it connects to the site, the items that were in its basket before the connection should not be merged. After logging in, he should only see one item in the cart.

I observed sales_quote_merge_before event as shown below and removed the invite from the guest user, nevertheless, these items are visible in the cart after login.

etc / frontend / events.xml



    
        
    

QuoteBeforeMerge.php

quoteRepository = $ quoteRepository;
}

/ **
* @param Observer $ observer
* @return void
* /
public service execute (Observer $ observer)
{
if ($ observe-> getSource () -> hasItems ()) {
$ currentQuote = $ observer-> getSource ();
$ quoteId = $ currentQuote-> getId ();
$ quote = $ this-> quoteRepository-> get ($ quoteId);
$ this-> quoteRepository-> delete ($ quote);
}
}
}