Zend certified PHP/Magento developer

Magento 2.4 how to prevent the merging of the guest cart items into the logged-in cart

I need to prevent the cart from merging in a way that only old items remains in the cart, so:

  • guest user adds an item to the cart
  • guest user logs in
  • customer cart had already an item inside
  • on merging, guest items are discarded and only old items remain in the cart

Currently, whatever I do, I’m able to keep the new items and discard the old ones, but I’m not able to do the reverse.

I tried both sales_quote_merge_before and sales_quote_merge_after but the result is still the same: when I clear the quote with

$observer->getQuote()->removeAllItems();

only the old items are removed, the guest items are preserved.

Is there a way to do the opposite?