public function getLineItemsByDiscount(PromotionDiscountEntity $discount, Cart $cart, SalesChannelContext $context): array
    {
        /** @var array $nonPromotionLineItemsKeys */
        $nonPromotionLineItemsKeys = $this->getNonPromotionLineItemsKeys($cart);

        if (count($nonPromotionLineItemsKeys) === 0) {
            return [];
        }

        if (!$discount->isConsiderAdvancedRules()) {
            return $nonPromotionLineItemsKeys;
        }

        /** @var RuleCollection|null $discountRuleCollection */
        $discountRuleCollection = $discount->getDiscountRules();

        // discount has no rules, therefore all lineItems match discount
        if (!$discountRuleCollection instanceof RuleCollection) {
            return $nonPromotionLineItemsKeys;
        }

        /** @var array $lineItems */
        $lineItems = $this->getNonPromotionLineItems($cart);

        $matchingLineItems = [];

        // get all lineItems where rule is matching without respecting any advanced rule
        /** @var LineItem $lineItem */
        foreach ($lineItems as $lineItem) {
            $itemScope = new LineItemScope($lineItem, $context);
            if ($this->doesRuleCollectionMatchsLineItem($discountRuleCollection, $itemScope)) {
                $matchingLineItems[$lineItem->getKey()] = $lineItem;
            }
        }

        return $matchingLineItems;
    }
public function getLineItemsByDiscount(PromotionDiscountEntity $discount, Cart $cart, SalesChannelContext $context): array
    {
        /** @var array $nonPromotionLineItemsKeys */
        $nonPromotionLineItemsKeys = $this->getNonPromotionLineItemsKeys($cart);

        if (count($nonPromotionLineItemsKeys) === 0) {
            return [];
        }

        if (!$discount->isConsiderAdvancedRules()) {
            return $nonPromotionLineItemsKeys;
        }

        /** @var RuleCollection|null $discountRuleCollection */
        $discountRuleCollection = $discount->getDiscountRules();

        // discount has no rules, therefore all lineItems match discount
        if (!$discountRuleCollection instanceof RuleCollection) {
            return $nonPromotionLineItemsKeys;
        }

        /** @var array $lineItems */
        $lineItems = $this->getNonPromotionLineItems($cart);

        $matchingLineItems = [];

        // get all lineItems where rule is matching without respecting any advanced rule
        /** @var LineItem $lineItem */
        foreach ($lineItems as $lineItem) {
            $itemScope = new LineItemScope($lineItem, $context);
            if ($this->doesRuleCollectionMatchsLineItem($discountRuleCollection, $itemScope)) {
                $matchingLineItems[$lineItem->getKey()] = $lineItem;
            }
        }

        return $matchingLineItems;
    }
public function getLineItemsByDiscount ( PromotionDiscountEntity $ discount , Cart $ cart , SalesChannelContext $ context ) : array { /** @var array $nonPromotionLineItemsKeys */ $ nonPromotionLineItemsKeys = $ this -> getNonPromotionLineItemsKeys ( $ cart ) ; if ( count ( $ nonPromotionLineItemsKeys ) === 0 ) { return [ ] ; } if ( ! $ discount -> isConsiderAdvancedRules ( ) ) { return $ nonPromotionLineItemsKeys ; } /** @var RuleCollection|null $discountRuleCollection */ $ discountRuleCollection = $ discount -> getDiscountRules ( ) ; // discount has no rules, therefore all lineItems match discount if ( ! $ discountRuleCollection instanceof RuleCollection ) { return $ nonPromotionLineItemsKeys ; } /** @var array $lineItems */ $ lineItems = $ this -> getNonPromotionLineItems ( $ cart ) ; $ matchingLineItems = [ ] ; // get all lineItems where rule is matching without respecting any advanced rule /** @var LineItem $lineItem */ foreach ( $ lineItems as $ lineItem ) { $ itemScope = new LineItemScope ( $ lineItem , $ context ) ; if ( $ this -> doesRuleCollectionMatchsLineItem ( $ discountRuleCollection , $ itemScope ) ) { $ matchingLineItems [ $ lineItem -> getKey ( ) ] = $ lineItem ; } } return $ matchingLineItems ; }
returns all lineItem keys that match the rules of the promotion
returns all lineItem keys that match the rules of the promotion