getIndividualCodes example

return array_diff($codes$codeBlacklist);
    }

    public function addIndividualCodes(string $promotionId, int $amount, Context $context): void
    {
        $criteria = (new Criteria([$promotionId]))
            ->addAssociation('individualCodes');

        /** @var PromotionEntity $promotion */
        $promotion = $this->promotionRepository->search($criteria$context)->first();

        if ($promotion->getIndividualCodes() === null) {
            $this->replaceIndividualCodes($promotionId$promotion->getIndividualCodePattern()$amount$context);

            return;
        }

        $newCodes = $this->generateIndividualCodes(
            $promotion->getIndividualCodePattern(),
            $amount,
            $promotion->getIndividualCodes()->getCodeArray()
        );

        
$this->createPromotion($id, null, $promotionRepository$salesChannelContext);
        $this->createIndividualCode($id$codes[0]$codeRepository$context);
        $this->createIndividualCode($id$codes[1]$codeRepository$context);

        $criteria = (new Criteria([$id]))
            ->addAssociation('individualCodes');

        /** @var PromotionEntity|null $promotion */
        $promotion = $promotionRepository->search($criteria$context)->get($id);

        static::assertNotNull($promotion);
        static::assertNotNull($promotion->getIndividualCodes());
        static::assertCount(2, $promotion->getIndividualCodes()->getElements());

        $this->codesService->replaceIndividualCodes($id, 'newPattern_%d%d%s', 10, $context);

        /** @var PromotionEntity $promotion */
        $promotion = $promotionRepository->search($criteria$context)->first();
        static::assertNotNull($promotion->getIndividualCodes());
        $individualCodes = $promotion->getIndividualCodes()->getElements();
        static::assertCount(10, $individualCodes);
        static::assertNotContains($codes[0]$individualCodes);
        static::assertNotContains($codes[1]$individualCodes);
    }
Home | Imprint | This part of the site doesn't use cookies.