Exemple #1
0
        public void ApplyRewards(IEnumerable <PromotionReward> rewards)
        {
            var productRewards = rewards.Where(r => r.RewardType == PromotionRewardType.CatalogItemAmountReward && (r.ProductId.IsNullOrEmpty() || r.ProductId.EqualsInvariant(Id)));

            if (productRewards == null)
            {
                return;
            }

            Discounts.Clear();
            Price.DiscountAmount = new Money(Math.Max(0, (Price.ListPrice - Price.SalePrice).Amount), Currency);

            foreach (var reward in productRewards)
            {
                //Initialize tier price discount amount by default values
                var discount = reward.ToDiscountModel(Price.SalePrice);
                foreach (var tierPrice in Price.TierPrices)
                {
                    tierPrice.DiscountAmount = new Money(Math.Max(0, (Price.ListPrice - tierPrice.Price).Amount), Currency);
                }

                if (reward.IsValid)
                {
                    Discounts.Add(discount);
                    Price.DiscountAmount += discount.Amount;

                    //apply discount to tier prices
                    foreach (var tierPrice in Price.TierPrices)
                    {
                        discount = reward.ToDiscountModel(tierPrice.Price);
                        tierPrice.DiscountAmount += discount.Amount;
                    }
                }
            }
        }
Exemple #2
0
        public void ApplyRewards(IEnumerable <PromotionReward> rewards)
        {
            var productRewards = rewards.Where(r => r.RewardType == PromotionRewardType.CatalogItemAmountReward && (r.ProductId.IsNullOrEmpty() || r.ProductId.EqualsInvariant(Id)));

            if (productRewards == null)
            {
                return;
            }

            Discounts.Clear();

            foreach (var reward in productRewards)
            {
                //Apply discount to main price
                var discount = reward.ToDiscountModel(Price.SalePrice);
                if (reward.IsValid)
                {
                    Discounts.Add(discount);
                    Price.ActiveDiscount = discount;
                    //apply discount to tier prices
                    foreach (var tierPrice in Price.TierPrices)
                    {
                        discount = reward.ToDiscountModel(tierPrice.Price);
                        tierPrice.ActiveDiscount = discount;
                    }
                }
            }
        }
        private void resetDiscountApplication()
        {
            foreach (Discount d in discountsApplied)
            {
                d.Amount        = 0.00M;
                d.ItemAppliedTo = "";
                discountsAvailable.Add(d);
            }

            discountsApplied.Clear();

            populateDiscountsList();
        }
        public void ApplyRewards(IEnumerable <PromotionReward> rewards)
        {
            Discounts.Clear();

            var cartRewards = rewards.Where(r => r.RewardType == PromotionRewardType.CartSubtotalReward);

            foreach (var reward in cartRewards)
            {
                var discount = reward.ToDiscountModel(SubTotal.Amount, Currency);

                if (reward.IsValid)
                {
                    Discounts.Add(discount);
                }
            }

            var lineItemRewards = rewards.Where(r => r.RewardType == PromotionRewardType.CatalogItemAmountReward);

            foreach (var lineItem in Items)
            {
                lineItem.ApplyRewards(lineItemRewards);
            }

            var shipmentRewards = rewards.Where(r => r.RewardType == PromotionRewardType.ShipmentReward);

            foreach (var shipment in Shipments)
            {
                shipment.ApplyRewards(shipmentRewards);
            }

            if (Coupon != null && !string.IsNullOrEmpty(Coupon.Code))
            {
                var couponRewards = rewards.Where(r => r.Promotion.Coupons != null && r.Promotion.Coupons.Any());
                if (!couponRewards.Any())
                {
                    Coupon.AppliedSuccessfully = false;
                    Coupon.ErrorCode           = "InvalidCouponCode";
                }
                foreach (var reward in couponRewards)
                {
                    var couponCode = reward.Promotion.Coupons.FirstOrDefault(c => c == Coupon.Code);
                    if (!string.IsNullOrEmpty(couponCode))
                    {
                        Coupon.AppliedSuccessfully = reward.IsValid;
                        Coupon.Description         = reward.Promotion.Description;
                    }
                }
            }
        }
        public void ApplyRewards(IEnumerable <PromotionReward> rewards)
        {
            Discounts.Clear();
            DiscountAmount = new Money(Currency);

            var cartRewards = rewards.Where(x => x.RewardType == PromotionRewardType.CartSubtotalReward);

            foreach (var reward in cartRewards)
            {
                //When a discount is applied to the cart subtotal, the tax calculation has already been applied, and is reflected in the tax subtotal.
                //Therefore, a discount applying to the cart subtotal will occur after tax.
                //For instance, if the cart subtotal is $100, and $15 is the tax subtotal, a cart - wide discount of 10 % will yield a total of $105($100 subtotal – $10 discount + $15 tax on the original $100).

                var discount = reward.ToDiscountModel(ExtendedPriceTotal);

                if (reward.IsValid)
                {
                    Discounts.Add(discount);
                }
                DiscountAmount = discount.Amount;
            }

            var lineItemRewards = rewards.Where(x => x.RewardType == PromotionRewardType.CatalogItemAmountReward);

            foreach (var lineItem in Items)
            {
                lineItem.ApplyRewards(lineItemRewards);
            }

            var shipmentRewards = rewards.Where(x => x.RewardType == PromotionRewardType.ShipmentReward);

            foreach (var shipment in Shipments)
            {
                shipment.ApplyRewards(shipmentRewards);
            }

            var paymentRewards = rewards.Where(x => x.RewardType == PromotionRewardType.PaymentReward);

            foreach (var payment in Payments)
            {
                payment.ApplyRewards(paymentRewards);
            }

            if (Coupon != null && !string.IsNullOrEmpty(Coupon.Code))
            {
                Coupon.AppliedSuccessfully = rewards.Any(x => x.IsValid && x.Coupon != null);
            }
        }
Exemple #6
0
        public void ApplyRewards(IEnumerable <PromotionReward> rewards)
        {
            var shipmentRewards = rewards.Where(r => r.RewardType == PromotionRewardType.ShipmentReward && r.ShippingMethodCode == ShipmentMethodCode);

            Discounts.Clear();

            foreach (var reward in shipmentRewards)
            {
                var discount = reward.ToDiscountModel(ShippingPrice.Amount, Currency);

                if (reward.IsValid)
                {
                    Discounts.Add(discount);
                }
            }
        }
Exemple #7
0
        public void ApplyRewards(IEnumerable <PromotionReward> rewards)
        {
            var shipmentRewards = rewards.Where(r => r.RewardType == PromotionRewardType.ShipmentReward && (r.ShippingMethodCode.IsNullOrEmpty() || r.ShippingMethodCode.EqualsInvariant(ShipmentMethodCode)));

            Discounts.Clear();

            foreach (var reward in shipmentRewards)
            {
                var discount = reward.ToDiscountModel(ShippingPrice, ShippingPriceWithTax);

                if (reward.IsValid)
                {
                    Discounts.Add(discount);
                }
            }
        }
Exemple #8
0
        public void ApplyRewards(IEnumerable <PromotionReward> rewards)
        {
            var shipmentRewards = rewards.Where(r => r.RewardType == PromotionRewardType.ShipmentReward && (string.IsNullOrEmpty(r.ShippingMethodCode) || r.ShippingMethodCode.EqualsInvariant(ShipmentMethodCode)));

            Discounts.Clear();

            DiscountAmount = new Money(0m, Currency);

            foreach (var reward in shipmentRewards)
            {
                var discount = reward.ToDiscountModel(Price - DiscountAmount);

                if (reward.IsValid)
                {
                    Discounts.Add(discount);
                    DiscountAmount += discount.Amount;
                }
            }
        }
Exemple #9
0
        public void ApplyRewards(IEnumerable <PromotionReward> rewards)
        {
            var lineItemRewards = rewards.Where(r => r.RewardType == PromotionRewardType.CatalogItemAmountReward && r.ProductId == ProductId);

            if (lineItemRewards == null)
            {
                return;
            }

            Discounts.Clear();

            foreach (var reward in lineItemRewards)
            {
                var discount = reward.ToDiscountModel(SalePrice.Amount, Currency);

                if (reward.IsValid)
                {
                    Discounts.Add(discount);
                }
            }
        }
Exemple #10
0
        public void ApplyRewards(IEnumerable <PromotionReward> rewards)
        {
            var productRewards = rewards.Where(r => r.RewardType == PromotionRewardType.CatalogItemAmountReward && r.ProductId == Id);

            if (productRewards == null)
            {
                return;
            }

            Discounts.Clear();

            foreach (var reward in productRewards)
            {
                var discount = reward.ToDiscountModel(Price.SalePrice);

                if (reward.IsValid)
                {
                    Discounts.Add(discount);
                    Price.ActiveDiscount = discount;
                }
            }
        }
Exemple #11
0
        protected void Load(bool refresh)
        {
            if (!refresh && Discounts.Count > 0)
            {
                IsLoading = false;
                return;
            }

            IsLoading = true;

            Task.Factory.StartNew(() =>
            {
                Discounts.Clear();
                Discounts.AddRange(DiscountService.GetDiscounts());
            }).ContinueWith(t =>
            {
                Execute.OnUIThread(() =>
                {
                    IsLoading = false;
                });
            });
        }
Exemple #12
0
 private void DeleteDiscounts()
 {
     Discounts.Clear();
     Company.Discounts.Clear();
 }