private IEnumerable <PromotionRecord> CalculateCartDiscounts()
        {
            var records = new List <PromotionRecord>();

            foreach (var form in CurrentOrderGroup.OrderForms)
            {
                var set = GetPromotionEntrySetFromOrderForm(form);

                // create context
                var ctx = new Dictionary <string, object> {
                    { PromotionEvaluationContext.TargetSet, set }
                };

                var couponCode = CustomerSessionService.CustomerSession.CouponCode;

                //1. Prepare marketing context
                var evaluationContext = new PromotionEvaluationContext
                {
                    ContextObject    = ctx,
                    CustomerId       = CustomerSessionService.CustomerSession.CustomerId,
                    CouponCode       = CustomerSessionService.CustomerSession.CouponCode,
                    PromotionType    = PromotionType.CartPromotion,
                    Currency         = CustomerSessionService.CustomerSession.Currency,
                    Store            = CustomerSessionService.CustomerSession.StoreId,
                    IsRegisteredUser = CustomerSessionService.CustomerSession.IsRegistered,
                    IsFirstTimeBuyer = CustomerSessionService.CustomerSession.IsFirstTimeBuyer
                };

                //2. Evaluate
                //var evaluator = new DefaultPromotionEvaluator(MarketingRepository, PromotionUsageProvider, new IEvaluationPolicy[] { new GlobalExclusivityPolicy(), new CartSubtotalRewardCombinePolicy(), new ShipmentRewardCombinePolicy() }, CacheRepository);
                var promotions = PromotionEvaluator.EvaluatePromotion(evaluationContext);
                var rewards    = promotions.SelectMany(x => x.Rewards);

                //3. Generate warnings
                if (!string.IsNullOrEmpty(couponCode) && !promotions.Any(p => (p.CouponId != null && p.Coupon.Code == couponCode) ||
                                                                         (p.CouponSetId != null && p.CouponSet.Coupons.Any(c => c.Code == couponCode))))
                {
                    RegisterWarning(WorkflowMessageCodes.COUPON_NOT_APPLIED, "Coupon doesn't exist or is not applied");
                }

                records.AddRange(rewards.Select(reward => new PromotionRecord
                {
                    AffectedEntriesSet = set,
                    TargetEntriesSet   = set,
                    Reward             = reward,
                    PromotionType      = PromotionType.CartPromotion
                }));
            }

            return(records.ToArray());
        }
        private IEnumerable <PromotionRecord> CalculateLineItemDiscounts()
        {
            var records = new List <PromotionRecord>();

            foreach (var form in CurrentOrderGroup.OrderForms)
            {
                foreach (var lineItem in form.LineItems)
                {
                    var set   = new PromotionEntrySet();
                    var entry = GetPromotionEntryFromLineItem(lineItem);
                    set.Entries.Add(entry);

                    // create context
                    var ctx = new Dictionary <string, object> {
                        { PromotionEvaluationContext.TargetSet, set }
                    };

                    //1. Prepare marketing context
                    var evaluationContext = new PromotionEvaluationContext
                    {
                        ContextObject    = ctx,
                        CustomerId       = CustomerSessionService.CustomerSession.CustomerId,
                        CouponCode       = CustomerSessionService.CustomerSession.CouponCode,
                        Currency         = CustomerSessionService.CustomerSession.Currency,
                        PromotionType    = PromotionType.CatalogPromotion,
                        Store            = CustomerSessionService.CustomerSession.StoreId,
                        IsRegisteredUser = CustomerSessionService.CustomerSession.IsRegistered,
                        IsFirstTimeBuyer = CustomerSessionService.CustomerSession.IsFirstTimeBuyer
                    };

                    //2. Evaluate
                    var promotions = PromotionEvaluator.EvaluatePromotion(evaluationContext);
                    var rewards    = promotions.SelectMany(x => x.Rewards);

                    records.AddRange(rewards.Select(reward => new PromotionRecord
                    {
                        AffectedEntriesSet = set,
                        TargetEntriesSet   = set,
                        Reward             = reward,
                        PromotionType      = PromotionType.CatalogPromotion
                    }));
                }
            }

            return(records.ToArray());
        }