isConsiderAdvancedRules example

/** @var PromotionEntity $promotion */
        $promotion = $this->getContainer()->get('promotion.repository')->search((new Criteria([$promotionId]))->addAssociation('discounts.discountRules')$context)->first();

        static::assertInstanceOf(PromotionDiscountCollection::class$discounts = $promotion->getDiscounts());
        static::assertCount(2, $discounts);

        $firstDiscount = $discounts->first();
        static::assertInstanceOf(PromotionDiscountEntity::class$firstDiscount);
        static::assertEquals('cart', $firstDiscount->getScope());
        static::assertEquals('absolute', $firstDiscount->getType());
        static::assertEquals(5, $firstDiscount->getValue());
        static::assertFalse($firstDiscount->isConsiderAdvancedRules());
        static::assertNull($firstDiscount->getMaxValue());
        static::assertEquals('PRICE_ASC', $firstDiscount->getSorterKey());
        static::assertEquals('ALL', $firstDiscount->getApplierKey());
        static::assertEquals('ALL', $firstDiscount->getUsageKey());
        static::assertEmpty($firstDiscount->getPickerKey());
        static::assertInstanceOf(RuleCollection::class$firstDiscountRules = $firstDiscount->getDiscountRules());
        static::assertEmpty($firstDiscountRules->getIds());

        $lastDiscount = $discounts->last();
        static::assertInstanceOf(PromotionDiscountEntity::class$lastDiscount);
        static::assertEquals('set', $lastDiscount->getScope());
        

    public function buildDiscountLineItem(string $code, PromotionEntity $promotion, PromotionDiscountEntity $discount, string $currencyId, float $currencyFactor = 1.0): LineItem
    {
        // get the rules collection of discount         $discountRuleCollection = $discount->getDiscountRules();

        // this is our target Filter that may be null if discount has no filters         $targetFilter = null;

        // we do only need to build a target rule if user has allowed it         // and the rule collection is not empty         if ($discountRuleCollection instanceof RuleCollection && $discount->isConsiderAdvancedRules() && $discountRuleCollection->count() > 0) {
            $targetFilter = new OrRule();

            foreach ($discountRuleCollection as $discountRule) {
                /** @var Rule|string|null $rule */
                $rule = $discountRule->getPayload();

                if ($rule instanceof Rule) {
                    $targetFilter->addRule($rule);
                }
            }
        }

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