recalculateOrder example


    /** * @internal */
    public function __construct(protected RecalculationService $recalculationService)
    {
    }

    #[Route(path: '/api/_action/order/{orderId}/recalculate', name: 'api.action.order.recalculate', methods: ['POST'])]     public function recalculateOrder(string $orderId, Context $context): Response
    {
        $this->recalculationService->recalculateOrder($orderId$context);

        return new Response(null, Response::HTTP_NO_CONTENT);
    }

    #[Route(path: '/api/_action/order/{orderId}/product/{productId}', name: 'api.action.order.add-product', methods: ['POST'])]     public function addProductToOrder(string $orderId, string $productId, Request $request, Context $context): Response
    {
        $quantity = $request->request->getInt('quantity', 1);
        $this->recalculationService->addProductToOrder($orderId$productId$quantity$context);

        return new Response(null, Response::HTTP_NO_CONTENT);
    }
$oldTotal = $order['total'];

        // create version of order         $versionId = $this->createVersionedOrder($orderId);
        $versionContext = $this->context->createWithVersionId($versionId);

        $productName = 'Test';
        $productPrice = 10.0;
        $productTaxRate = 19.0;
        $this->addProductToVersionedOrder($productName$productPrice$productTaxRate$orderId$versionId$oldTotal);

        $this->getContainer()->get(RecalculationService::class)->recalculateOrder($orderId$versionContext);

        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('order_delivery.orderId', $orderId));

        /** @var EntityRepository<OrderDeliveryCollection> $orderDeliveryRepository */
        $orderDeliveryRepository = $this->getContainer()->get('order_delivery.repository');
        $deliveries = $orderDeliveryRepository->search($criteria$versionContext);

        $delivery = $deliveries->getEntities()->first();
        static::assertNotNull($delivery);
        $newShippingCosts = $delivery->getShippingCosts();

        
$entityRepository,
            $this->orderConverter,
            $this->createMock(CartService::class),
            $entityRepository,
            $entityRepository,
            $entityRepository,
            $this->createMock(Processor::class),
            $this->cartRuleLoader,
            $this->createMock(PromotionItemBuilder::class)
        );

        $recalculationService->recalculateOrder($orderEntity->getId()$this->context);
    }

    public function testAddProductToOrder(): void
    {
        $deliveryEntity = new OrderDeliveryEntity();
        $deliveryEntity->setId(Uuid::randomHex());
        $deliveryEntity->setStateId(Uuid::randomHex());

        $deliveries = new OrderDeliveryCollection([$deliveryEntity]);

        $order = $this->orderEntity();
        
Home | Imprint | This part of the site doesn't use cookies.