CartResponse example

$cart->markModified();
        }

        $cart = $this->cartCalculator->calculate($cart$context);
        $this->cartPersister->save($cart$context);

        $this->eventDispatcher->dispatch(new AfterLineItemRemovedEvent($lineItems$cart$context));

        $this->eventDispatcher->dispatch(new CartChangedEvent($cart$context));

        return new CartResponse($cart);
    }
}
return new Response(null, Response::HTTP_NO_CONTENT);
    }

    #[Route(path: '/api/_action/order/{orderId}/promotion-item', name: 'api.action.order.add-promotion-item', methods: ['POST'])]     public function addPromotionItemToOrder(string $orderId, Request $request, Context $context): Response
    {
        $code = (string) $request->request->get('code');

        $cart = $this->recalculationService->addPromotionLineItem($orderId$code$context);

        return new CartResponse($cart);
    }

    #[Route(path: '/api/_action/order/{orderId}/toggleAutomaticPromotions', name: 'api.action.order.toggle-automatic-promotions', methods: ['POST'])]     public function toggleAutomaticPromotions(string $orderId, Request $request, Context $context): Response
    {
        $skipAutomaticPromotions = (bool) $request->request->get('skipAutomaticPromotions', true);

        $cart = $this->recalculationService->toggleAutomaticPromotion($orderId$context$skipAutomaticPromotions);

        return new CartResponse($cart);
    }

    
$cart = $this->persister->load($token$context);
        } catch (CartTokenNotFoundException) {
            $cart = $this->cartFactory->createNew($token);
        }

        $cart = $this->cartCalculator->calculate($cart$context);

        if ($taxed) {
            $this->taxProviderProcessor->process($cart$context);
        }

        return new CartResponse($cart);
    }
}
$this->eventDispatcher->dispatch(new BeforeLineItemAddedEvent($item$cart$context$alreadyExists));
        }

        $cart->markModified();

        $cart = $this->cartCalculator->calculate($cart$context);
        $this->cartPersister->save($cart$context);

        $this->eventDispatcher->dispatch(new AfterLineItemAddedEvent($items$cart$context));
        $this->eventDispatcher->dispatch(new CartChangedEvent($cart$context));

        return new CartResponse($cart);
    }
}
$this->lineItemFactory->update($cart$item$context);
        }

        $cart->markModified();

        $cart = $this->cartCalculator->calculate($cart$context);
        $this->cartPersister->save($cart$context);

        $this->eventDispatcher->dispatch(new AfterLineItemQuantityChangedEvent($cart$itemsToUpdate$context));
        $this->eventDispatcher->dispatch(new CartChangedEvent($cart$context));

        return new CartResponse($cart);
    }
}
$response = $this->controller->cartPage($request$this->createMock(SalesChannelContext::class));

        static::assertEquals(new Response()$response);
    }

    public function testGetCartJson(): void
    {
        $cart = new Cart(Uuid::randomHex());

        $this->cartLoadRouteMock->method('load')->willReturn(
            new CartResponse($cart)
        );

        $response = $this->controller->cartJson(new Request()$this->createMock(SalesChannelContext::class));

        static::assertEquals(new CartResponse($cart)$response);
    }

    public function testConfirmPageNoCustomer(): void
    {
        $context = $this->createMock(SalesChannelContext::class);
        $context->method('getCustomer')->willReturn(null);

        
Home | Imprint | This part of the site doesn't use cookies.