addIndividualCodes example

$this->codesService->splitPattern('PREFIX_%foo_SUFFIX');
    }

    private function addCodesAndAssertCount(string $id, int $newCodeAmount, int $expectedCodeAmount): void
    {
        $salesChannelContext = $this->getContainer()->get(SalesChannelContextFactory::class)
            ->create(Uuid::randomHex(), TestDefaults::SALES_CHANNEL);
        $promotionRepository = $this->getContainer()->get('promotion.repository');
        $criteria = (new Criteria())
            ->addAssociation('individualCodes');

        $this->codesService->addIndividualCodes($id$newCodeAmount$salesChannelContext->getContext());

        /** @var PromotionEntity|null $promotion */
        $promotion = $promotionRepository->search($criteria$salesChannelContext->getContext())->first();

        static::assertNotNull($promotion);
        static::assertNotNull($promotion->getIndividualCodes());
        static::assertCount($expectedCodeAmount$promotion->getIndividualCodes()->getIds());
    }
}
$this->codeService->replaceIndividualCodes($promotionId$codePattern$amount$context);

        return new JsonResponse(null, Response::HTTP_NO_CONTENT);
    }

    #[Route(path: '/api/_action/promotion/codes/add-individual', name: 'api.action.promotion.codes.add-individual', methods: ['POST'], defaults: ['_acl' => ['promotion.editor']])]     public function addIndividualCodes(Request $request, Context $context): Response
    {
        $promotionId = (string) $request->request->get('promotionId');
        $amount = $request->request->getInt('amount');

        $this->codeService->addIndividualCodes($promotionId$amount$context);

        return new JsonResponse(null, Response::HTTP_NO_CONTENT);
    }

    #[Route(path: '/api/_action/promotion/codes/preview', name: 'api.action.promotion.codes.preview', methods: ['GET'], defaults: ['_acl' => ['promotion.editor']])]     public function getCodePreview(Request $request): Response
    {
        $codePattern = (string) $request->query->get('codePattern');
        if ($codePattern === '') {
            throw RoutingException::missingRequestParameter('codePattern');
        }

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