addPromotion example

$cart->addErrors(new PromotionCartAddedInformationError($item));

        $this->promotionItemBuilderMock->method('buildPlaceholderItem')->willReturn($item);

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

        $this->translatorCallback();

        $this->controller->addPromotion($cart$request$context);
    }

    public function testAddPromotionOtherExceptions(): void
    {
        $code = Uuid::randomHex();

        $request = new Request([]['code' => $code]);
        $cart = new Cart(Uuid::randomHex());
        $context = $this->createMock(SalesChannelContext::class);
        $uniqueKey = PromotionItemBuilder::PLACEHOLDER_PREFIX . $code;
        $item = new LineItem($uniqueKey, PromotionProcessor::LINE_ITEM_TYPE);
        
/** * @dataProvider promotions */
    public function testAddPromotion(string $code): void
    {
        $contextToken = Uuid::randomHex();

        $cartService = $this->getContainer()->get(CartService::class);
        $request = $this->createRequest(['code' => $code]);

        $salesChannelContext = $this->createSalesChannelContext($contextToken);
        $this->getContainer()->get(CartLineItemController::class)->addPromotion(
            $cartService->getCart($contextToken$salesChannelContext),
            $request,
            $salesChannelContext
        );

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

        static::assertArrayHasKey('danger', $flashBagEntries);
        static::assertSame($this->getContainer()->get('translator')->trans('checkout.promotion-not-found', ['%code%' => \strip_tags($code)])$flashBagEntries['danger'][0]);
        static::assertCount(0, $cartService->getCart($contextToken$salesChannelContext)->getLineItems());
    }

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