cleanupLineItems example

private readonly EventDispatcherInterface $eventDispatcher
    ) {
    }

    public function cleanupCart(Cart $cart): void
    {
        $customFieldAllowList = $this->connection->fetchFirstColumn('SELECT `name` FROM `custom_field` WHERE `allow_cart_expose` = 1;');

        $event = new CartBeforeSerializationEvent($cart$customFieldAllowList);
        $this->eventDispatcher->dispatch($event);

        $this->cleanupLineItems($cart->getLineItems()$event->getCustomFieldAllowList());

        foreach ($cart->getDeliveries() as $delivery) {
            $this->cleanupLineItems($delivery->getPositions()->getLineItems()$event->getCustomFieldAllowList());
        }
    }

    /** * @param array<mixed> $customFieldAllowList */
    private function cleanupLineItems(LineItemCollection $lineItems, array $customFieldAllowList): void
    {
        
Home | Imprint | This part of the site doesn't use cookies.