Hello i am trying to prevent products with different properties from been mixed up in the cart.
to do that I have set some conditions and displaying some notices to the user on the cart. but I need to be able to remove items that I make a notice about.
at the moment, i am setting up logic
public function onLineItemAdded(AfterLineItemAddedEvent $event): void
{
$lineItems = $event->getLineItems();
$shipperExists = false;
foreach ($lineItems as $lineItem) {
$this->processCustomFields($lineItem);
if (isset($lineItem->getPayload()["customFields"]["dropper_"])) {
$shipperExists = true;
}
}
if (!$shipperExists && isset($this->customFields["dropper_"])) {
$this->flashBag->add(
"info",
"Invalid entry, You are trying to include a product without dropshipping option to a product with a dropshipping option."
);
}
if ($shipperExists && !isset($this->customFields["dropper_"]) && isset($this->customFields)) {
$this->flashBag->add(
"info",
"Invalid entry, You are trying to include a product with dropshipping option to a product without a dropshipping option."
);
}
}
and i then tried to use a cartservice
use ShopwareCoreCheckoutCartCartService;
$cart = $cartService->getCart($contextToken);
$cart = $cartService->delete($cart, $lineItemId, $context);
but i am unable to delete the cart item, please help