cleanupCart example

return EntityDefinitionQueryHelper::columnExists($this->connection, 'cart', 'payload');
    }

    private function serializeCart(Cart $cart, bool $payloadExists): string
    {
        $errors = $cart->getErrors();
        $data = $cart->getData();

        $cart->setErrors(new ErrorCollection());
        $cart->setData(null);

        $this->cartSerializationCleaner->cleanupCart($cart);

        // @deprecated tag:v6.6.0 - remove else part         if ($payloadExists) {
            $serialized = $this->compress ? CacheValueCompressor::compress($cart) : serialize($cart);
        } else {
            $serialized = serialize($cart);
        }

        $cart->setErrors($errors);
        $cart->setData($data);

        
$dispatcher = $this->getContainer()->get('event_dispatcher');

        $listener = $this->getMockBuilder(CallableClass::class)->getMock();
        $listener->expects(static::once())->method('__invoke');

        $this->addEventListener($dispatcher, CartBeforeSerializationEvent::class$listener);

        $connection = $this->createMock(Connection::class);
        $connection->expects(static::once())->method('fetchFirstColumn')->willReturn($allowed);

        $cleaner = new CartSerializationCleaner($connection$dispatcher);
        $cleaner->cleanupCart($cart);

        $items = $cart->getLineItems()->getFlat();
        foreach ($items as $item) {
            static::assertArrayHasKey($item->getId()$payloads);
            static::assertEquals($payloads[$item->getId()]$item->getPayload());
        }

        $delivery = $cart->getDeliveries()->first();
        $deliveryItems = $delivery !== null ? $delivery->getPositions()->getLineItems()->getFlat() : [];

        foreach ($deliveryItems as $item) {
            
$this->delete($oldToken$context);
    }

    private function serializeCart(Cart $cart, SalesChannelContext $context): string
    {
        $errors = $cart->getErrors();
        $data = $cart->getData();

        $cart->setErrors(new ErrorCollection());
        $cart->setData(null);

        $this->cartSerializationCleaner->cleanupCart($cart);

        $content = ['cart' => $cart, 'rule_ids' => $context->getRuleIds()];

        $content = $this->compress ? CacheValueCompressor::compress($content) : \serialize($content);

        $cart->setErrors($errors);
        $cart->setData($data);

        return \serialize([
            'compressed' => $this->compress,
            'content' => $content,
            
Home | Imprint | This part of the site doesn't use cookies.