getExclusionIds example


    public function testUpsertPromotionIndexerLogic(): void
    {
        $promotionA = $this->createPromotion([], 'Promotion A');
        $promotionB = $this->createPromotion([$promotionA], 'Promotion B');
        $promotionC = $this->createPromotion([$promotionA$promotionB], 'Promotion C');

        $promotions = $this->promotionRepository->search(new Criteria([$promotionA$promotionB$promotionC])$this->context)->getEntities();

        static::assertEquals([$promotionB$promotionC]$promotions->get($promotionA)?->getExclusionIds(), 'Exclusion Promotion A has errors after creation');
        static::assertEquals([$promotionA$promotionC]$promotions->get($promotionB)?->getExclusionIds(), 'Exclusion Promotion B has errors after creation');
        static::assertEquals([$promotionA$promotionB]$promotions->get($promotionC)?->getExclusionIds(), 'Exclusion Promotion C has errors after creation');

        $this->promotionRepository->update([[
            'id' => $promotionC,
            'exclusionIds' => [],
        ]]$this->context);

        $promos = $this->promotionRepository->search(new Criteria()$this->context)->getEntities();

        static::assertEquals([$promotionB]$promos->get($promotionA)?->getExclusionIds(), 'Exclusion Promotion A has errors after update');
        

    public function update(array $ids): void
    {
        // if there are no ids, we don't have to do anything         if (empty($ids)) {
            return;
        }

        foreach ($ids as $id) {
            // get exclusions for this id and prepare it as hex array             $exclusions = $this->getExclusionIds($id);

            // create empty array if there are no exclusions             $promotionExclusions = [];

            if (\count($exclusions) > 0) {
                $firstResult = array_shift($exclusions);
                if (\array_key_exists('exclusion_ids', $firstResult)) {
                    // if there are exclusions, set them in array                     $promotionExclusions = json_decode((string) $firstResult['exclusion_ids'], null, 512, \JSON_THROW_ON_ERROR);
                }
            }

            
$payload['maxValue'] = (string) $this->getCurrencySpecificValue($discount$discount->getMaxValue()$currencyId$currencyFactor);
        }

        // set the scope of the discount cart, delivery....         $payload['discountScope'] = $discount->getScope();

        // specifies if the promotion is not combinable with any other promotion         $payload['preventCombination'] = $promotion->isPreventCombination();

        // If all combinations are prevented the exclusions dont matter         // otherwise sets a list of excluded promotion ids         $payload['exclusions'] = $payload['preventCombination'] ? [] : $promotion->getExclusionIds();

        $payload['groupId'] = '';
        // if we have set a custom setgroup scope, then the group id         // is used as suffix in the scopeKey...         if ($discount->isScopeSetGroup()) {
            $payload['groupId'] = $discount->getSetGroupId();
            $payload['discountScope'] = PromotionDiscountEntity::SCOPE_SETGROUP;
        }

        // add all our set groups to our configuration         // if existing. always make sure to have at least a node
Home | Imprint | This part of the site doesn't use cookies.