createIndividualCode example

$promotionEvent = $writtenEvent->getEventByEntityName(PromotionDefinition::ENTITY_NAME);

        static::assertNotNull($promotionEvent);
        static::assertNotEmpty($promotionEvent->getWriteResults()[0]);
        $promotionId = $promotionEvent->getWriteResults()[0]->getPayload()['id'];

        $userId = Uuid::randomHex();
        $origin = new AdminApiSource($userId);
        $origin->setIsAdmin(true);
        $context = Context::createDefaultContext($origin);

        $event = $this->createIndividualCode($promotionId, 'CODE-1', $promotionIndividualRepository$context);

        $result = $indexer->update($event);

        static::assertNull($result);
    }

    public function testPromotionIndexerUpdateReturnPromotionIndexingMessage(): void
    {
        $indexer = $this->getContainer()->get(PromotionIndexer::class);

        $salesChannelContext = $this->createSalesChannelContext();

        
public function testReplaceIndividualCodes(): void
    {
        $promotionRepository = $this->getContainer()->get('promotion.repository');
        $codeRepository = $this->getContainer()->get('promotion_individual_code.repository');
        $salesChannelContext = $this->getContainer()->get(SalesChannelContextFactory::class)
            ->create(Uuid::randomHex(), TestDefaults::SALES_CHANNEL);
        $context = $salesChannelContext->getContext();

        $id = Uuid::randomHex();
        $codes = ['myIndividualCode_00A', 'myIndividualCode_11B'];
        $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());

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