removeCode example


        $promotion1 = new PromotionEntity();
        $promotion2 = new PromotionEntity();
        $promotion3 = new PromotionEntity();
        $promotion4 = new PromotionEntity();

        $definition = new CartPromotionsDataDefinition();
        $definition->addCodePromotions('codeA', [$promotion1$promotion2]);
        $definition->addCodePromotions('codeB', [$promotion3]);
        $definition->addAutomaticPromotions([$promotion4]);

        $definition->removeCode('codeB');

        static::assertCount(3, $definition->getPromotionCodeTuples());
        static::assertEquals(['codeA']$definition->getAllCodes());
    }

    /** * This test verifies that our hasCode returns * true if we have an entry for the code. * * @group promotions */
    


                // we need the list of found codes                 // for our NotFound errors below                 $foundCodes[] = $tuple->getCode();
            }

            // now iterate through all codes that have been added             // and add errors, if a promotion for that code couldn't be found             foreach ($allCodes as $code) {
                if (!\in_array($code$foundCodes, true)) {
                    $cartExtension->removeCode((string) $code);

                    $this->addPromotionNotFoundError($this->htmlSanitizer->sanitize((string) $code, null, true)$original);
                }
            }

            // if we do have promotions, set them to be processed             // otherwise make sure to remove the entry to avoid any processing             // within our promotions scope             if (\count($discountLineItems) > 0) {
                $data->set(PromotionProcessor::DATA_KEY, new LineItemCollection($discountLineItems));
            } else {
                

    public function testRemoveCode(): void
    {
        $extension = new CartExtension();
        $extension->addCode('c123');
        $extension->addCode('c456');

        $extension->removeCode('c123');

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


        $lineItem = $event->getLineItem();

        $code = $lineItem->getReferencedId();

        if (!empty($code)) {
            // promotion with code             $this->checkFixedDiscountItems($cart$lineItem);
            // remove other discounts of the promotion that should be deleted             $this->removeOtherDiscountsOfPromotion($cart$lineItem$event->getSalesChannelContext());
            $this->removeCode($code$cart);

            return;
        }

        // the user wants to remove an automatic added         // promotions, so lets do this         if ($lineItem->hasPayloadValue('promotionId')) {
            $promotionId = (string) $lineItem->getPayloadValue('promotionId');
            $this->blockPromotion($promotionId$cart);
        }
    }

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