public decimal GetItemDiscountPrice(Item item, Price lowestPrice, Hashtable tags = null)
        {
            var price = lowestPrice.Sale ?? lowestPrice.List;

            var session = _customerSession.CustomerSession;

            // apply discounts
            // create context
            var ctx = new Dictionary <string, object>();
            var set = GetPromotionEntrySetFromItem(item, price, tags);

            ctx.Add(PromotionEvaluationContext.TargetSet, set);

            var evaluationContext = new PromotionEvaluationContext
            {
                ContextObject    = ctx,
                CustomerId       = session.CustomerId,
                CouponCode       = null,
                Currency         = session.Currency,
                PromotionType    = PromotionType.CatalogPromotion,
                Store            = session.StoreId,
                IsRegisteredUser = session.IsRegistered,
                IsFirstTimeBuyer = session.IsFirstTimeBuyer
            };

            var promotions = _evaluator.EvaluatePromotion(evaluationContext);
            var rewards    = promotions.SelectMany(x => x.Rewards).ToArray();
            var records    = new List <PromotionRecord>();

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

            //Filter by policies
            var allRecords = _evaluator.EvaluatePolicies(records.ToArray());

            var lineItemRewards = allRecords.Select(x => x.Reward).OfType <CatalogItemReward>().ToArray();

            var discountTotal = 0m;

            foreach (var reward in lineItemRewards)
            {
                if (reward.QuantityLimit > 1)                 // skip everything for higher quantity
                {
                    continue;
                }

                if (!String.IsNullOrEmpty(reward.SkuId))                 // filter out free item rewards
                {
                    if (!item.ItemId.Equals(reward.SkuId, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }
                }

                var       discountAmount = 0m;
                const int quantity       = 1;
                if (reward.AmountTypeId == (int)RewardAmountType.Relative)
                {
                    discountAmount = Math.Round(quantity * price * reward.Amount * 0.01m, 2);
                }
                else if (reward.AmountTypeId == (int)RewardAmountType.Absolute)
                {
                    discountAmount = Math.Round(quantity * reward.Amount, 2);
                }
                discountTotal += discountAmount;
            }

            return(discountTotal);
        }
 public Model.Promotion[] EvaluatePromotions(IPromotionEvaluationContext context)
 {
     return(_evaluator.EvaluatePromotion(context));
 }