A checker to check if a promotion can be used for the current context.
        private PromotionMatch TryMatchPromotion(Promotion promotion, PriceCalculationContext context)
        {
            if (promotion.RequireCouponCode && context.CouponCode != promotion.CouponCode)
            {
                return(null);
            }

            var isMatch = false;
            var conditionMatchedItems = new List <PriceCalculationItem>();

            if (!promotion.Conditions.Any())
            {
                isMatch = true;
            }
            else
            {
                var conditionChecker = new PromotionConditionChecker(_ruleEngine);
                var result           = conditionChecker.CheckConditions(promotion, context);
                if (result.Success)
                {
                    isMatch = true;
                    foreach (var item in result.MatchedItems)
                    {
                        if (!conditionMatchedItems.Contains(item))
                        {
                            conditionMatchedItems.Add(item);
                        }
                    }
                }
            }

            if (isMatch)
            {
                return(new PromotionMatch(promotion, conditionMatchedItems));
            }

            return(null);
        }
示例#2
0
        private PromotionMatch TryMatchPromotion(Promotion promotion, PriceCalculationContext context)
        {
            if (promotion.RequireCouponCode && context.CouponCode != promotion.CouponCode)
            {
                return null;
            }

            var isMatch = false;
            var conditionMatchedItems = new List<PriceCalculationItem>();

            if (!promotion.Conditions.Any())
            {
                isMatch = true;
            }
            else
            {
                var conditionChecker = new PromotionConditionChecker(_ruleEngine);
                var result = conditionChecker.CheckConditions(promotion, context);
                if (result.Success)
                {
                    isMatch = true;
                    foreach (var item in result.MatchedItems)
                    {
                        if (!conditionMatchedItems.Contains(item))
                        {
                            conditionMatchedItems.Add(item);
                        }
                    }
                }
            }

            if (isMatch)
            {
                return new PromotionMatch(promotion, conditionMatchedItems);
            }

            return null;
        }