createPromotionWithCustomData example

private function createPromotion(string $promotionId, ?string $code, EntityRepository $promotionRepository, SalesChannelContext $context): EntityWrittenContainerEvent
    {
        $data = [
            'id' => $promotionId,
        ];

        if ($code !== null) {
            $data['code'] = $code;
            $data['useCodes'] = true;
        }

        return $this->createPromotionWithCustomData($data$promotionRepository$context);
    }

    /** * @param array<string, mixed> $data */
    private function createPromotionWithCustomData(array $data, EntityRepository $promotionRepository, SalesChannelContext $context): EntityWrittenContainerEvent
    {
        $data = array_merge([
            'id' => Uuid::randomHex(),
            'name' => 'Black Friday',
            'active' => true,
            
'active' => true,
            'salesChannels' => [
                ['salesChannelId' => $this->context->getSalesChannel()->getId(), 'priority' => 1],
            ],
        ]$data);

        if ($code !== null) {
            $data['code'] = $code;
            $data['useCodes'] = true;
        }

        $this->createPromotionWithCustomData($data$this->promotionRepository, $this->context);

        return $this->createTestFixtureDiscount($promotionId, PromotionDiscountEntity::TYPE_PERCENTAGE, PromotionDiscountEntity::SCOPE_CART, $percentage$maxValue$this->getContainer()$this->context);
    }

    private function createCustomer(): string
    {
        $customerId = Uuid::randomHex();
        $addressId = Uuid::randomHex();

        $customer = [
            'id' => $customerId,
            
public function testReplaceIndividualCodesWithDuplicatePattern(): void
    {
        $promotionRepository = $this->getContainer()->get('promotion.repository');
        $salesChannelContext = $this->getContainer()->get(SalesChannelContextFactory::class)
            ->create(Uuid::randomHex(), TestDefaults::SALES_CHANNEL);

        $id = Uuid::randomHex();
        $duplicatePattern = 'TEST_%d%s_END';

        // Create 2 Promotions. The first one has a pattern, which the second will try to use as well later on         $this->createPromotionWithCustomData(['individualCodePattern' => $duplicatePattern]$promotionRepository$salesChannelContext);
        $this->createPromotionWithCustomData(['id' => $id]$promotionRepository$salesChannelContext);

        $this->expectExceptionMessage('Code pattern already exists in another promotion. Please provide a different pattern.');
        $this->codesService->replaceIndividualCodes($id$duplicatePattern, 1, $salesChannelContext->getContext());
    }

    public function testAddIndividualCodes(): void
    {
        $id = Uuid::randomHex();
        $pattern = 'somePattern_%d%d%d';
        $data = [
            
Home | Imprint | This part of the site doesn't use cookies.