Exemplo n.º 1
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
            });
        }
Exemplo n.º 2
0
        public List <PaymentDetailsItemType> GetPaymentDetailsItems(CartModel cart)
        {
            var paymentDetailsItemTypes = cart.Items.Select(item => new PaymentDetailsItemType
            {
                Name         = item.Name,
                Amount       = item.UnitPricePreTax.GetAmountType(),
                ItemCategory = item.RequiresShipping ? ItemCategoryType.PHYSICAL : ItemCategoryType.DIGITAL,
                Quantity     = item.Quantity,
                Tax          = item.UnitTax.GetAmountType(),
            }).ToList();
            var applications = (from discountInfo in cart.Discounts
                                let info = _cartDiscountApplicationService.ApplyDiscount(discountInfo, cart)
                                           select new { info, discountInfo }).ToHashSet();

            paymentDetailsItemTypes.AddRange(from application in applications

                                             where application.info.OrderTotalDiscount > 0
                                             select new PaymentDetailsItemType
            {
                Name         = "Order Total Discount - " + application.discountInfo.Discount.Name,
                Amount       = (-application.info.OrderTotalDiscount).GetAmountType(),
                ItemCategory = ItemCategoryType.PHYSICAL,
                Quantity     = 1,
                Tax          = 0m.GetAmountType()
            });

            paymentDetailsItemTypes.AddRange(from application in applications
                                             where application.info.ShippingDiscount > 0
                                             select new PaymentDetailsItemType
            {
                Name         = "Shipping Discount - " + application.discountInfo.Discount.Name,
                Amount       = (-application.info.ShippingDiscount).GetAmountType(),
                ItemCategory = ItemCategoryType.PHYSICAL,
                Quantity     = 1,
                Tax          = 0m.GetAmountType()
            });

            paymentDetailsItemTypes.AddRange(from giftCard in cart.AppliedGiftCards
                                             where giftCard.AvailableAmount > 0
                                             select new PaymentDetailsItemType
            {
                Name         = "Gift Card - " + giftCard.Code,
                Amount       = (-giftCard.AvailableAmount).GetAmountType(),
                ItemCategory = ItemCategoryType.PHYSICAL,
                Quantity     = 1,
                Tax          = 0m.GetAmountType()
            });

            if (cart.AppliedRewardPointsAmount > 0)
            {
                paymentDetailsItemTypes.Add(new PaymentDetailsItemType
                {
                    Name         = string.Format("Reward Points ({0})", cart.AppliedRewardPoints),
                    Amount       = (-cart.AppliedRewardPointsAmount).GetAmountType(),
                    ItemCategory = ItemCategoryType.PHYSICAL,
                    Quantity     = 1,
                    Tax          = 0m.GetAmountType()
                });
            }

            return(paymentDetailsItemTypes);
        }