transitionOrder example

$productId = $this->createProduct([
            'stock' => $initialStock,
        ]);
        $orderId = $this->orderProduct($productId$orderQuantity);

        $product = $this->productRepository->search(new Criteria([$productId])$context)->first();

        static::assertInstanceOf(ProductEntity::class$product);
        $this->assertStock($initialStock - $orderQuantity$product);

        $this->transitionOrder($orderId, StateMachineTransitionActions::ACTION_CANCEL);

        $product = $this->productRepository->search(new Criteria([$productId])$context)->first();

        static::assertInstanceOf(ProductEntity::class$product);
        $this->assertStock($initialStock$product);
    }

    public function testStockNotReduceDuplicatedWhenReOpenOrder(): void
    {
        $id = $this->createProduct();

        
$productId = $this->createProduct([
            'stock' => $initialStock,
        ]);
        $orderId = $this->orderProduct($productId$orderQuantity);

        $product = $this->productRepository->search(new Criteria([$productId])$context)->first();

        static::assertInstanceOf(ProductEntity::class$product);
        static::assertSame($initialStock - $orderQuantity$product->getAvailableStock());

        $this->transitionOrder($orderId, StateMachineTransitionActions::ACTION_CANCEL);

        $product = $this->productRepository->search(new Criteria([$productId])$context)->first();

        static::assertInstanceOf(ProductEntity::class$product);
        static::assertSame($initialStock$product->getAvailableStock());
    }

    public function testStockAndSalesUpdatedAfterOrderCompleted(): void
    {
        $id = $this->createProduct();

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