getCodes example

// add promotion to cart         $cart = $this->addPromotionCode($promotionCode$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::assertCount(0, $extension->getCodes());
    }

    /** * This test verifies that we successfully block any promotion * that does not have a code but gets removed by the user. * In this case the promotion must not be added automatically again and again. * * @group promotions */
    public function testAutoPromotionGetsBlockedWhenDeletingItem(): void
    {
        


            // if we are in recalculation,             // we must not re-add any promotions. just leave it as it is.             if ($behavior->hasPermission(self::SKIP_PROMOTION)) {
                return;
            }

            // now get the codes from our configuration             // and also from our line items (that already exist)             // and merge them both into a flat list             $extensionCodes = $cartExtension->getCodes();
            $cartCodes = $original->getLineItems()->filterType(PromotionProcessor::LINE_ITEM_TYPE)->getReferenceIds();
            $allCodes = array_unique(array_merge(array_values($cartCodes)$extensionCodes));

            $allPromotions = $this->searchPromotionsByCodes($data$allCodes$context);

            if (!$behavior->hasPermission(self::SKIP_AUTOMATIC_PROMOTIONS)) {
                // add auto promotions                 $allPromotions->addAutomaticPromotions($this->searchPromotionsAuto($data$context));
            }

            // check if max allowed redemption of promotion have been reached or not
/** * This test verifies that we can add * a new code to the extension * * @group promotions */
    public function testAddCode(): void
    {
        $extension = new CartExtension();
        $extension->addCode('c123');

        static::assertEquals(['c123']$extension->getCodes());
    }

    /** * This test verifies that our function * returns the correct value if existing * * @group promotions */
    public function testHasCode(): void
    {
        $extension = new CartExtension();
        
Home | Imprint | This part of the site doesn't use cookies.