Esempio n. 1
0
        public double GetCouponDiscount()
        {
            if (AppliedCoupon == null)
            {
                return(default(double));
            }

            var cartTotal = LineItems.Sum(a => a.Product.UnitPrice * a.Quantity) - GetCampaignDiscount();

            return(_couponCalculator.CalculateFor(AppliedCoupon, cartTotal));
        }
Esempio n. 2
0
        public double GetCampaignDiscount()
        {
            if (AppliedCampaigns.Any())
            {
                foreach (var appliedCampaign in AppliedCampaigns.OrderByDescending(a => a.AmountOfDiscount))
                {
                    var applicableLineItems = LineItems.Where(a => a.Product.Category.Equals(appliedCampaign.Category)).ToList();

                    if (applicableLineItems.Count <= appliedCampaign.MinimumItemQuantity)
                    {
                        continue;
                    }

                    var applicableLineItemsCartTotal = applicableLineItems.Sum(a => a.Product.UnitPrice * a.Quantity);

                    return(_campaignCalculator.CalculateFor(appliedCampaign, applicableLineItemsCartTotal));
                }
            }

            return(default(double));
        }