getDiscountRules example

$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());
        static::assertEquals('percentage', $lastDiscount->getType());
        static::assertEquals(2.5, $lastDiscount->getValue());
        static::assertTrue($lastDiscount->isConsiderAdvancedRules());
        static::assertEquals(4, $lastDiscount->getMaxValue());
        static::assertEquals('PRICE_DESC', $lastDiscount->getSorterKey());
        static::assertEquals('1', $lastDiscount->getApplierKey());
        
/** * Builds a new Line Item for the provided discount and its promotion. * It will automatically reference all provided "product" item Ids within the payload. * * @throws CartException * @throws UnknownPromotionDiscountTypeException */
    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 */
                
Home | Imprint | This part of the site doesn't use cookies.