CheckConditions() public method

public CheckConditions ( Kooboo.Commerce.Promotions.Promotion promotion, PriceCalculationContext context ) : CheckPromotionConditionResult
promotion Kooboo.Commerce.Promotions.Promotion
context Kooboo.Commerce.Orders.Pricing.PriceCalculationContext
return CheckPromotionConditionResult
Ejemplo n.º 1
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);
        }
Ejemplo n.º 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;
        }