hasCode example

/** * This test verifies that our function * returns the correct value if existing * * @group promotions */
    public function testHasCode(): void
    {
        $extension = new CartExtension();
        $extension->addCode('c123');

        static::assertTrue($extension->hasCode('c123'));
    }

    /** * This test verifies that we can remove * an existing code from the cart extension * * @group promotions */
    public function testRemoveCode(): void
    {
        $extension = new CartExtension();
        
$cart = $this->cartService->getCart($this->context->getToken()$this->context);

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

        // add promotion to cart         $this->addPromotionCode($promotionCode$cart$this->cartService, $this->context);

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

        static::assertTrue($extension->hasCode($promotionCode));
    }

    /** * This test verifies that our cart services * does also correctly remove the matching code * within our extension, if existing. * We add a product and promotion code, then we grab the promotion * line item id and remove it. * After that we verify that our code array is empty in our extension. * * @group promotions */
/** * This test verifies that our hasCode returns * true if we have an entry for the code. * * @group promotions */
    public function testHasCodeIsTrueEvenIfEmpty(): void
    {
        $definition = new CartPromotionsDataDefinition();
        $definition->addCodePromotions('codeA', []);

        static::assertTrue($definition->hasCode('codeA'));
    }

    /** * This test verifies that our hasCode returns * false if we dont have an entry for the code. * * @group promotions */
    public function testHasCodeIsFalse(): void
    {
        $definition = new CartPromotionsDataDefinition();
        
$promotionsList->removeCode((string) $code);
            }
        }

        $codesToFetch = [];

        // let's find out what promotions we         // really need to fetch from our database.
        foreach ($allCodes as $code) {
            // check if promotion is already cached             if ($promotionsList->hasCode($code)) {
                continue;
            }

            // fetch that new code             $codesToFetch[] = $code;

            // add a new entry with null             // so if we cant fetch it, we do at least             // tell our cache that we have tried it             $promotionsList->addCodePromotions($code[]);
        }

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