We used to run several own plugins which we try to convert to shopware 6 now.
One of these plugins was supposed to add free items to the cart if several requirements were met.
I’ve already managed to load the necessary info and prepare the CustomLineItem, but for some reason as soon as the basket loads the item is gone again.
If I go and put a die(cart->jsonSerialize()) behind the $this->cartService->add($cart,$lineItem,$context) it shows that the CustomLineItem has properly been added but there has been no update to the cart’s price total or anything. It is as if the item was just temporarely added to the array but then discarded again.
In some threads I found a hint towards calling the persister->save($cart, $context) but it does nothing.
When i try to use $this->cartService->update($cart,json_decode(json_encode($lineItems->jsonSerialize()),true), $context) I get insuficient permission because it tries to update a price or something on the position…
Any help would be appreciated, since this is a on-the-fly add to the basket we tried to put it into a call of basketchange instead of making it a own event / controller / page which seems extremely over-the-top complicated for just trying to add a stupid line to the basket…