I am trying to remove a LineItem from the cart during the CartChangedEvent but it does not work. I tried
public function cartChangedEvent(CartChangedEvent $pEvent)
{
$lineItems = $pEvent->getCart()->getLineItems();
$x = $lineItems->count();
$lineItems->removeElement($pEvent->getCart()->getLineItems()->first());
$lineItems->count(); // The size is $x - 1 now
$pEvent->getCart()->setLineItems($lineItems);
}
But that does not work. The line items list gets changed, but the cart does not change even though I am using setLineItems