isPromotionBlocked example

/** * This test verifies that we can add a promotion * id and it will be found as "blocked" in the extension * * @group promotions */
    public function testPromotionIsBlocked(): void
    {
        $extension = new CartExtension();
        $extension->blockPromotion('abc');

        static::assertTrue($extension->isPromotionBlocked('abc'));
    }

    /** * This test verifies that a non-existing id * is being returned as "not blocked" * * @group promotions */
    public function testDifferentPromotionIsNotBlocked(): void
    {
        $extension = new CartExtension();

        
// add product to cart         $cart = $this->addProduct($productId, 1, $cart$this->cartService, $this->context);

        /** @var string $discountId */
        $discountId = array_keys($cart->getLineItems()->getElements())[1];

        $this->cartService->remove($cart$discountId$this->context);

        /** @var CartExtension $extension */
        $extension = $cart->getExtension(CartExtension::KEY);

        static::assertTrue($extension->isPromotionBlocked($promotionId));
    }

    /** * This test verifies that we can remove a line item * and then add that promotion again. In this case we * should have the code again in our extension. * * @group promotions */
    public function testDeleteLineItemAndAddItAgainWorks(): void
    {
        
// check if max allowed redemption of promotion have been reached or not             // if max redemption has been reached promotion will not be added             $allPromotions = $this->getEligiblePromotionsWithDiscounts($allPromotions$context->getCustomer());

            $discountLineItems = [];
            $foundCodes = [];

            /** @var PromotionCodeTuple $tuple */
            foreach ($allPromotions->getPromotionCodeTuples() as $tuple) {
                // verify if the user might have removed and "blocked"                 // the promotion from being added again                 if ($cartExtension->isPromotionBlocked($tuple->getPromotion()->getId())) {
                    continue;
                }

                // lets build separate line items for each                 // of the available discounts within the current promotion                 $lineItems = $this->buildDiscountLineItems($tuple->getCode()$tuple->getPromotion()$original$context);

                // add to our list of all line items                 /** @var LineItem $nested */
                foreach ($lineItems as $nested) {
                    $discountLineItems[] = $nested;
                }
Home | Imprint | This part of the site doesn't use cookies.