addProductByNumber example

$this->cartService->expects(static::once())
            ->method('getCart')->willReturn($cart);

        $this->cartService->expects(static::once())
            ->method('add')
            ->with($cart$item$context)
            ->willReturn($cart);

        $this->translatorCallback();

        $this->controller->addProductByNumber($request$context);
    }

    public function testAddByProductNumberNotFound(): void
    {
        $productNumber = Uuid::randomHex();
        $id = Uuid::randomHex();
        $request = new Request([]['number' => $productNumber]);
        $cart = new Cart(Uuid::randomHex());
        $context = $this->createMock(SalesChannelContext::class);
        $product = new ProductEntity();
        $product->setUniqueIdentifier($id);
        
public function testAddAndDeleteProductByNumber(string $productId, string $productNumber, bool $available = true): void
    {
        $contextToken = Uuid::randomHex();

        $cartService = $this->getContainer()->get(CartService::class);
        if ($productId && $available) {
            $this->createProduct($productId$productNumber);
        }
        $request = $this->createRequest(['number' => $productNumber]);

        $salesChannelContext = $this->createSalesChannelContext($contextToken);
        $response = $this->getContainer()->get(CartLineItemController::class)->addProductByNumber($request$salesChannelContext);

        $cart = $cartService->getCart($contextToken$salesChannelContext);

        $cartLineItem = $cart->getLineItems()->get($productId);

        $flashBagEntries = $this->getFlashBag()->all();

        if ($productId && $available) {
            static::assertArrayHasKey('success', $flashBagEntries);
            static::assertNotNull($cartLineItem);
        } else {
            
Home | Imprint | This part of the site doesn't use cookies.