Exemplo n.º 1
0
        public void SetDiscountApplication(DiscountApplicationInfo discountApplicationInfo)
        {
            Items.ForEach(item => item.ResetDiscountInfo());

            OrderTotalDiscount = discountApplicationInfo.OrderTotalDiscount;
            ShippingDiscount   = discountApplicationInfo.ShippingDiscount;
            foreach (var key in discountApplicationInfo.ItemDiscounts.Keys)
            {
                var cartItem = Items.FirstOrDefault(x => x.Id == key);
                if (cartItem != null)
                {
                    cartItem.SetDiscountAmount(discountApplicationInfo.ItemDiscounts[key]);
                }
            }
            foreach (var key in discountApplicationInfo.ItemPercentages.Keys)
            {
                var cartItem = Items.FirstOrDefault(x => x.Id == key);
                if (cartItem != null)
                {
                    cartItem.SetDiscountPercentage(discountApplicationInfo.ItemPercentages[key]);
                }
            }
            foreach (var key in discountApplicationInfo.ItemsFree.Keys)
            {
                var item = Items.FirstOrDefault(x => x.Id == key);
                if (item != null)
                {
                    item.SetFreeItems(discountApplicationInfo.ItemsFree[key]);
                }
            }
        }
Exemplo n.º 2
0
 public void Add(DiscountApplicationInfo info)
 {
     OrderTotalDiscount += info.OrderTotalDiscount;
     ShippingDiscount += info.ShippingDiscount;
     foreach (var key in info.ItemDiscounts.Keys)
     {
         if (!ItemDiscounts.ContainsKey(key))
             ItemDiscounts[key] = info.ItemDiscounts[key];
         else
             ItemDiscounts[key] += info.ItemDiscounts[key];
     }
 }
Exemplo n.º 3
0
 public void SetDiscountApplication(DiscountApplicationInfo discountApplicationInfo)
 {
     OrderTotalDiscount = discountApplicationInfo.OrderTotalDiscount;
     ShippingDiscount   = discountApplicationInfo.ShippingDiscount;
     foreach (var key in discountApplicationInfo.ItemDiscounts.Keys)
     {
         var cartItem = Items.FirstOrDefault(x => x.Id == key);
         if (cartItem != null)
         {
             cartItem.SetDiscountInfo(discountApplicationInfo.ItemDiscounts[key]);
         }
     }
 }
Exemplo n.º 4
0
 public void Add(DiscountApplicationInfo info)
 {
     OrderTotalDiscount += info.OrderTotalDiscount;
     ShippingDiscount   += info.ShippingDiscount;
     foreach (var key in info.ItemDiscounts.Keys)
     {
         if (!ItemDiscounts.ContainsKey(key))
         {
             ItemDiscounts[key] = info.ItemDiscounts[key];
         }
         else
         {
             ItemDiscounts[key] += info.ItemDiscounts[key];
         }
     }
 }
Exemplo n.º 5
0
        private DiscountApplicationResult GetDiscountApplication(List<DiscountInfo> discounts, CartModel cart)
        {
            var discountApplicationInfo = new DiscountApplicationInfo();
            var hashSet = new List<Discount>();
            foreach (var discountInfo in discounts.FindAll(x => x.Status == DiscountStatus.ValidButNotApplied))
            {
                var applicationInfo = _cartDiscountApplicationService.ApplyDiscount(discountInfo, cart);
                if (!applicationInfo.IsApplied)
                    continue;

                discountApplicationInfo.Add(applicationInfo);
                hashSet.Add(discountInfo.Discount);
            }
            return new DiscountApplicationResult
            {
                Info = discountApplicationInfo,
                AppliedDiscounts = hashSet
            };
        }
        public DiscountApplicationInfo ApplyDiscount(DiscountInfo discountInfo, CartModel cart)
        {
            var applications = _session.QueryOver<DiscountApplication>()
                .Where(application => application.Discount.Id == discountInfo.Discount.Id)
                .Cacheable()
                .List();
            var discountApplicationInfo = new DiscountApplicationInfo();
            foreach (var application in applications)
            {
                var fullName = application.GetType().FullName;
                if (!ApplicationApplierTypes.ContainsKey(fullName))
                    continue;

                var applier = _kernel.Get(ApplicationApplierTypes[fullName]) as DiscountApplicationApplier;
                if (applier != null)
                    discountApplicationInfo.Add(applier.Apply(application, cart, discountInfo.CheckLimitationsResult));
            }
            return discountApplicationInfo;
        }