PromotionCartAddedInformationError example



    /** * function checks if the Original Cart contains the lineItem. * if not, an PromotionCartAddedInformationError is set in the calculated cart */
    private function addPromotionAddedNotice(Cart $original, Cart $calculated, LineItem $discountLineItem): void
    {
        if ($original->has($discountLineItem->getId())) {
            return;
        }
        $error = new PromotionCartAddedInformationError($discountLineItem);
        $calculated->addErrors($error);
    }

    /** * function checks if the Original Cart contains the lineItem. * if yes, an PromotionCartDeletedInformationError is set in the calculated cart */
    private function addPromotionDeletedNotice(Cart $original, Cart $calculated, LineItem $discountLineItem): void
    {
        if ($original->has($discountLineItem->getId())) {
            $error = new PromotionCartDeletedInformationError($discountLineItem);
            
public function testAddPromotion(): 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);
        $item->setLabel($code);
        $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);
    }
Home | Imprint | This part of the site doesn't use cookies.