addCodePromotions example

/** * This test verifies that promotions with code get the * correct code within its tuple object. * We add 1 promotion with code, and verify the single tuple * that will be generated. * * @group promotions */
    public function testCodePromotionHasCorrectCode(): void
    {
        $definition = new CartPromotionsDataDefinition();
        $definition->addCodePromotions('codeA', [new PromotionEntity()]);

        /** @var PromotionCodeTuple[] $tuples */
        $tuples = $definition->getPromotionCodeTuples();

        static::assertEquals('codeA', $tuples[0]->getCode());
    }

    /** * This test verifies we get 2 tuple objects for a code * if we add 2 promotions for it. * * @group promotions */
// 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[]);
        }

        // if we have new codes to fetch         // make sure to load it and assign it to         // the code in our cache list.         if (\count($codesToFetch) > 0) {
            $salesChannelId = $context->getSalesChannel()->getId();

            foreach ($codesToFetch as $currentCode) {
                // try to find a global code first because                 // that search has less data involved
Home | Imprint | This part of the site doesn't use cookies.