Ejemplo n.º 1
0
        private void checkPerOrderLimit(MyHLShoppingCart myCart, ShoppingCartRuleResult Result)
        {
            ShoppingCartItem_V01 backupItem = null;
            var existingItem =
                myCart.ShoppingCartItems.FirstOrDefault(p => p.SKU == myCart.CurrentItems[0].SKU);

            if (null != existingItem)
            {
                backupItem = new ShoppingCartItem_V01(existingItem.ID, existingItem.SKU,
                                                      existingItem.Quantity,
                                                      DateTime.Now, existingItem.MinQuantity);
            }

            myCart.AddItemsToCart(myCart.CurrentItems, true);

            var Totals = myCart.Calculate() as OrderTotals_V01;

            if (Totals != null && Totals.AmountDue > MaxAmount)
            {
                var globalResourceObject =
                    HttpContext.GetGlobalResourceObject(
                        string.Format("{0}_Rules", HLConfigManager.Platform), "AmountLimitExceeds");
                if (globalResourceObject != null)
                {
                    Result.AddMessage(
                        string.Format(
                            globalResourceObject
                            .ToString(), MaxAmount.ToString()));
                }
                globalResourceObject =
                    HttpContext.GetGlobalResourceObject(
                        string.Format("{0}_Rules", HLConfigManager.Platform),
                        "DisgardCommonMessage");
                if (globalResourceObject != null)
                {
                    Result.AddMessage(globalResourceObject.ToString());
                }
                Result.Result = RulesResult.Failure;
            }

            myCart.DeleteItemsFromCart(new List <string> {
                myCart.CurrentItems[0].SKU
            }, true);

            if (backupItem != null)
            {
                myCart.AddItemsToCart(new List <ShoppingCartItem_V01> {
                    backupItem
                }, true);
                myCart.Calculate();
            }
        }
        public static decimal TotalsExcludeAPF(MyHLShoppingCart cart, string countryCode)
        {
            if (APFDueProvider.IsAPFSkuPresent(cart.CartItems))
            {
                var calcTheseItems = new List <ShoppingCartItem_V01>();
                calcTheseItems.AddRange(from i in cart.CartItems
                                        where !APFDueProvider.IsAPFSku(i.SKU)
                                        select
                                        new ShoppingCartItem_V01(i.ID, i.SKU, i.Quantity, i.Updated,
                                                                 i.MinQuantity));

                // remove A and L type
                var allItems =
                    CatalogProvider.GetCatalogItems(
                        (from s in calcTheseItems where s.SKU != null select s.SKU).ToList(), countryCode);
                if (null != allItems && allItems.Count > 0)
                {
                    var skuExcluded = (from c in allItems.Values
                                       where (c as CatalogItem_V01).ProductType != ServiceProvider.CatalogSvc.ProductType.Product
                                       select c.SKU);
                    calcTheseItems.RemoveAll(s => skuExcluded.Contains(s.SKU));
                }

                var totals = cart.Calculate(calcTheseItems);
                return(totals != null ? (totals as OrderTotals_V01).AmountDue : decimal.Zero);
            }
            return(cart.Totals != null ? (cart.Totals as OrderTotals_V01).AmountDue : decimal.Zero);
        }
 /// <summary>
 /// Gets the shipment information to import into HMS.
 /// </summary>
 /// <param name="shoppingCart">The shopping cart.</param>
 /// <param name="shippment">The order shipment.</param>
 /// <returns></returns>
 public override bool GetDistributorShippingInfoForHMS(MyHLShoppingCart shoppingCart, Shipment shippment)
 {
     if (shoppingCart != null && shoppingCart.DeliveryInfo != null)
     {
         string freightCodeInCart = shoppingCart.DeliveryInfo.FreightCode;
         var    session           = SessionInfo.GetSessionInfo(shoppingCart.DistributorID, shoppingCart.Locale);
         if (session.IsEventTicketMode)
         {
             shippment.ShippingMethodID = shoppingCart.FreightCode = shoppingCart.DeliveryInfo.FreightCode = HLConfigManager.Configurations.CheckoutConfiguration.EventTicketFreightCode;
         }
         else if (APFDueProvider.hasOnlyAPFSku(shoppingCart.CartItems, shoppingCart.Locale))
         {
             shippment.ShippingMethodID = shoppingCart.FreightCode = shoppingCart.DeliveryInfo.FreightCode = HLConfigManager.Configurations.APFConfiguration.APFFreightCode;
         }
         else
         {
             string defaultFreight = HLConfigManager.Configurations.ShoppingCartConfiguration.DefaultFreightCode;
             shippment.WarehouseCode = shoppingCart.DeliveryInfo.WarehouseCode = HLConfigManager.Configurations.ShoppingCartConfiguration.DefaultWarehouse;
             if (shoppingCart.DeliveryInfo.Option == DeliveryOptionType.Shipping)
             {
                 shippment.ShippingMethodID = shoppingCart.FreightCode = shoppingCart.DeliveryInfo.FreightCode = defaultFreight;
             }
             else
             {
                 shippment.ShippingMethodID = shoppingCart.FreightCode = shoppingCart.DeliveryInfo.FreightCode = "PU";
             }
         }
         if (!freightCodeInCart.Equals(shoppingCart.FreightCode))
         {
             shoppingCart.Calculate();
             ShoppingCartProvider.UpdateShoppingCart(shoppingCart);
         }
     }
     return(true);
 }
        /// <summary>
        /// Gets the shipment information to import into HMS.
        /// </summary>
        /// <param name="shoppingCart">The shopping cart.</param>
        /// <param name="shippment">The order shipment.</param>
        /// <returns></returns>
        public override bool GetDistributorShippingInfoForHMS(MyHLShoppingCart shoppingCart, MyHerbalife3.Ordering.ServiceProvider.SubmitOrderBTSvc.Shipment shippment)
        {
            if (shoppingCart != null && shoppingCart.DeliveryInfo != null)
            {
                string freightCodeInCart = shoppingCart.DeliveryInfo.FreightCode;
                var    session           = SessionInfo.GetSessionInfo(shoppingCart.DistributorID, shoppingCart.Locale);
                if (session.IsEventTicketMode || APFDueProvider.hasOnlyAPFSku(shoppingCart.CartItems, shoppingCart.Locale))
                {
                    return(true);
                }

                if (shoppingCart.FreightCode == "NOF")
                {
                    shippment.ShippingMethodID = shoppingCart.FreightCode = shoppingCart.DeliveryInfo.FreightCode = shoppingCart.DeliveryInfo.Option == DeliveryOptionType.Shipping ? "UAF" : "PU";
                }
                if (shoppingCart.DeliveryInfo.Option == DeliveryOptionType.Shipping)
                {
                    shoppingCart.DeliveryInfo.WarehouseCode = HLConfigManager.Configurations.ShoppingCartConfiguration.DefaultWarehouse;
                }
                if (!freightCodeInCart.Equals(shoppingCart.FreightCode))
                {
                    shoppingCart.Calculate();
                    ShoppingCartProvider.UpdateShoppingCart(shoppingCart);
                }
            }
            return(true);
        }
        public void OnOrderMonthChanged(object sender, EventArgs e)
        {
            MyHLShoppingCart shoppingCart = (Page as ProductsBase).ShoppingCart;

            if (null != shoppingCart && null != shoppingCart.CartItems && shoppingCart.CartItems.Count > 0)
            {
                shoppingCart.Calculate();
            }
            BindTotals();
        }
        protected override ShoppingCartRuleResult PerformRules(MyHLShoppingCart cart,
                                                               ShoppingCartRuleReason reason,
                                                               ShoppingCartRuleResult Result)
        {
            var currentlimits = GetCurrentPurchasingLimits(cart.DistributorID, GetCurrentOrderMonth());

            if (cart == null || currentlimits == null)
            {
                return(Result);
            }
            Result = performRules(cart, Result, currentlimits);
            if (cart.ItemsBeingAdded != null && cart.ItemsBeingAdded.Count > 0)
            {
                if (currentlimits.PurchaseLimitType == PurchaseLimitType.Earnings && cart.OrderSubType == "B1")
                {
                    bool          bExceed  = false;
                    List <string> skuToAdd = new List <string>();

                    var itemsToCalc = new List <ShoppingCartItem_V01>();
                    itemsToCalc.AddRange(cart.CartItems);

                    foreach (var item in cart.ItemsBeingAdded)
                    {
                        if (bExceed == true)
                        {
                            Result = reportError(cart, item, Result);
                            continue;
                        }
                        itemsToCalc.Add(item);
                        OrderTotals_V01 orderTotals = cart.Calculate(itemsToCalc, false) as OrderTotals_V01;
                        if (orderTotals != null)
                        {
                            decimal earningsInCart = ProductEarningsInCart(itemsToCalc, orderTotals.DiscountPercentage);

                            if (currentlimits.RemainingEarnings - earningsInCart < 0)
                            {
                                bExceed = true;
                                Result  = reportError(cart, item, Result);
                            }
                            else
                            {
                                skuToAdd.Add(item.SKU);
                            }
                        }
                    }
                    cart.ItemsBeingAdded.RemoveAll(s => !skuToAdd.Contains(s.SKU));
                }
            }

            return(Result);
        }
        protected override ShoppingCartRuleResult PerformRules(MyHLShoppingCart cart,
                                                               ShoppingCartRuleReason reason,
                                                               ShoppingCartRuleResult Result)
        {
            base.PerformRules(cart, reason, Result);
            if (cart.ItemsBeingAdded != null && cart.ItemsBeingAdded.Count > 0)
            {
                var currentlimits = GetCurrentPurchasingLimits(cart.DistributorID, GetCurrentOrderMonth());
                if (currentlimits.PurchaseLimitType == PurchaseLimitType.DiscountedRetail)
                {
                    var itemsToCalc = new List <ShoppingCartItem_V01>();
                    itemsToCalc.AddRange(cart.CartItems);

                    bool          bExceed  = false;
                    List <string> skuToAdd = new List <string>();

                    foreach (var item in cart.ItemsBeingAdded)
                    {
                        if (bExceed == true)
                        {
                            Result = reportError(cart, item, Result);
                            continue;
                        }
                        itemsToCalc.Add(item);
                        OrderTotals_V01 orderTotals = cart.Calculate(itemsToCalc, false) as OrderTotals_V01;
                        if (orderTotals != null)
                        {
                            decimal discountedRetailInCart = orderTotals.ItemTotalsList.Sum(x => (x as ItemTotal_V01).DiscountedPrice);
                            var     currentItem            = CatalogProvider.GetCatalogItem(item.SKU, Country);
                            if ((currentlimits.RemainingVolume - discountedRetailInCart < 0) && currentItem.ProductType == MyHerbalife3.Ordering.ServiceProvider.CatalogSvc.ProductType.Product)
                            {
                                Result.Result = RulesResult.Failure;
                                bExceed       = true;
                                Result        = reportError(cart, item, Result);
                                continue;
                            }
                            else
                            {
                                skuToAdd.Add(item.SKU);
                            }
                        }
                    }

                    cart.ItemsBeingAdded.RemoveAll(s => !skuToAdd.Contains(s.SKU));
                }
            }

            return(Result);
        }
        private bool checkPerOrderLimit(MyHLShoppingCart cart, List <ShoppingCartItem_V01> previousItems, ShoppingCartRuleResult Result, string sku, int qty)
        {
            decimal MaxAmount = 999.99m;

            var calcTheseItems = new List <ShoppingCartItem_V01>();

            calcTheseItems.AddRange(from i in cart.CartItems
                                    where !APFDueProvider.IsAPFSku(i.SKU)
                                    select
                                    new ShoppingCartItem_V01(i.ID, i.SKU, i.Quantity, i.Updated,
                                                             i.MinQuantity));
            calcTheseItems.AddRange(previousItems);

            var existingItem =
                calcTheseItems.Find(ci => ci.SKU == sku);

            if (null != existingItem)
            {
                existingItem.Quantity += qty;
            }
            else
            {
                calcTheseItems.Add(new ShoppingCartItem_V01(0, sku, qty, DateTime.Now));
            }

            var Totals = cart.Calculate(calcTheseItems, false) as OrderTotals_V01;

            if (Totals != null && Totals.AmountDue > MaxAmount)
            {
                var globalResourceObject =
                    HttpContext.GetGlobalResourceObject(
                        string.Format("{0}_Rules", HLConfigManager.Platform), "AmountLimitExceeds");
                if (globalResourceObject != null)
                {
                    Result.AddMessage(
                        string.Format(
                            globalResourceObject
                            .ToString(), MaxAmount.ToString()));
                }
                Result.Result = RulesResult.Failure;
                return(false);
            }
            return(true);
        }
        private CartWidgetModel GetCartWidgetModelFromShoppingCart(MyHLShoppingCart myHLShoppingCart)
        {
            CartWidgetModel response = new CartWidgetModel();

            if (myHLShoppingCart != null)
            {
                if (myHLShoppingCart.Totals == null)
                {
                    myHLShoppingCart.Calculate(myHLShoppingCart.CartItems);
                }
                var total = myHLShoppingCart.Totals as OrderTotals_V01;

                if (total != null)
                {
                    if (myHLShoppingCart.Locale == "ko-KR")
                    {
                        decimal subtotal = 0m;
                        if (total.ItemTotalsList != null)
                        {
                            subtotal = total.ItemTotalsList.Sum(itemTotal => getDistributorPrice(itemTotal as ItemTotal_V01, total.DiscountPercentage, myHLShoppingCart.Locale));
                        }
                        response.Subtotal = subtotal;
                    }
                    else if (myHLShoppingCart.Locale.Equals("es-MX"))
                    {
                        response.Subtotal = OrderProvider.getPriceWithAllCharges(total);
                    }
                    else
                    {
                        response.Subtotal = total.DiscountedItemsTotal;
                    }

                    response.VolumePoints    = total.VolumePoints;
                    response.DisplaySubtotal = getAmountString(response.Subtotal);
                }
                response.Id       = myHLShoppingCart.ShoppingCartID;
                response.Quantity = myHLShoppingCart.CartItems.Sum(x => x.Quantity);
            }
            return(response);
        }
Ejemplo n.º 10
0
        public static decimal TotalsExcludeAPF(MyHLShoppingCart cart, string countryCode)
        {
            var calcTheseItems = new List <ShoppingCartItem_V01>();

            calcTheseItems.AddRange(from i in cart.CartItems
                                    where !APFDueProvider.IsAPFSku(i.SKU)
                                    select
                                    new ShoppingCartItem_V01(i.ID, i.SKU, i.Quantity, i.Updated,
                                                             i.MinQuantity));

            // remove A and L type
            var allItems =
                CatalogProvider.GetCatalogItems(
                    (from s in calcTheseItems where s.SKU != null select s.SKU).ToList(), countryCode);

            if (null != allItems && allItems.Count > 0)
            {
                var totals = cart.Calculate(calcTheseItems);
                return(totals != null ? (totals as OrderTotals_V01).AmountDue : decimal.Zero);
            }

            return(decimal.Zero);
        }
        protected override ShoppingCartRuleResult PerformRules(MyHLShoppingCart cart,
                                                               ShoppingCartRuleReason reason,
                                                               ShoppingCartRuleResult Result)
        {
            Result.Result = RulesResult.Success;

            if (cart == null)
            {
                return(Result);
            }

            base.PerformRules(cart, reason, Result);

            var currentlimits = GetCurrentPurchasingLimits(cart.DistributorID, GetCurrentOrderMonth());

            if (currentlimits.PurchaseLimitType == PurchaseLimitType.None || currentlimits.LimitsRestrictionType != LimitsRestrictionType.PurchasingLimits)
            {
                return(Result);
            }

            if (cart.ItemsBeingAdded != null && cart.ItemsBeingAdded.Count > 0)
            {
                var calcTheseItems = new List <ShoppingCartItem_V01>();
                calcTheseItems.AddRange(from i in cart.CartItems
                                        where !APFDueProvider.IsAPFSku(i.SKU)
                                        select
                                        new ShoppingCartItem_V01(i.ID, i.SKU, i.Quantity, i.Updated,
                                                                 i.MinQuantity));
                bool          bExceed  = false;
                List <string> skuToAdd = new List <string>();

                foreach (var item in cart.ItemsBeingAdded)
                {
                    if (bExceed == true)
                    {
                        Result = reportError(cart, item, Result);
                        continue;
                    }
                    var existingItem =
                        calcTheseItems.Find(ci => ci.SKU == item.SKU);
                    if (null != existingItem)
                    {
                        existingItem.Quantity += item.Quantity;
                    }
                    else
                    {
                        calcTheseItems.Add(new ShoppingCartItem_V01(0, item.SKU, item.Quantity, DateTime.Now));
                    }

                    // remove A and L type
                    var allItems =
                        CatalogProvider.GetCatalogItems(
                            (from s in calcTheseItems where s.SKU != null select s.SKU).ToList(), Country);
                    if (null != allItems && allItems.Count > 0)
                    {
                        var skuExcluded = (from c in allItems.Values
                                           where (c as CatalogItem_V01).ProductType != ServiceProvider.CatalogSvc.ProductType.Product
                                           select c.SKU);
                        calcTheseItems.RemoveAll(s => skuExcluded.Contains(s.SKU));
                    }

                    var totals = cart.Calculate(calcTheseItems, false);
                    if (null == totals)
                    {
                        var message =
                            string.Format(
                                "Purchasing Limits DiscountedRetail calculation failed due to Order Totals returning a null for Distributor {0}",
                                cart.DistributorID);
                        LoggerHelper.Error(message);
                        throw new ApplicationException(message);
                    }

                    if (currentlimits.RemainingVolume - (totals as OrderTotals_V01).AmountDue < 0)
                    {
                        bExceed = true;
                        Result  = reportError(cart, item, Result);
                    }
                    else
                    {
                        skuToAdd.Add(item.SKU);
                    }
                }

                cart.ItemsBeingAdded.RemoveAll(s => !skuToAdd.Contains(s.SKU));
            }
            return(Result);
        }
        /// <summary>
        /// Gets the shopping cart.
        /// </summary>
        /// <param name="distributorId">The distributor id.</param>
        /// <param name="locale">The locale.</param>
        /// <param name="freightCode">The freight code.</param>
        /// <param name="wareHouseCode">The ware house code.</param>
        /// <param name="calculate">if set to <c>true</c> [calculate].</param>
        /// <param name="totals">The totals.</param>
        /// <returns>
        /// Shopping cart with the parameters.
        /// </returns>
        internal static MyHLShoppingCart GetBasicShoppingCart(string distributorId, string locale, string freightCode, string wareHouseCode, bool calculate, OrderTotals_V01 totals)
        {
            if (string.IsNullOrEmpty(locale))
            {
                locale = "en-US";
            }

            if (string.IsNullOrEmpty(freightCode))
            {
                freightCode = HLConfigManager.CurrentPlatformConfigs[locale].ShoppingCartConfiguration.DefaultFreightCode;
            }

            if (string.IsNullOrEmpty(wareHouseCode))
            {
                wareHouseCode = HLConfigManager.CurrentPlatformConfigs[locale].ShoppingCartConfiguration.DefaultWarehouse;
            }

            var shoppingCart = new MyHLShoppingCart
            {
                Locale            = locale,
                ShoppingCartItems = new List <DistributorShoppingCartItem>
                {
                    ShoppingCartItemHelper.GetShoppingCartItem(1, 1, "1231"),
                    ShoppingCartItemHelper.GetShoppingCartItem(2, 1, "0138"),
                    ShoppingCartItemHelper.GetShoppingCartItem(3, 1, "0139")
                },
                CartItems = new ShoppingCartItemList
                {
                    ShoppingCartItemHelper.GetCartItem(1, 1, "1231"),
                    ShoppingCartItemHelper.GetCartItem(2, 1, "0138"),
                    ShoppingCartItemHelper.GetCartItem(3, 1, "0139")
                },
                DistributorID = string.IsNullOrEmpty(distributorId) ? "webtest1" : distributorId,
                FreightCode   = freightCode,
                DeliveryInfo  = new ShippingInfo
                {
                    FreightCode   = freightCode,
                    WarehouseCode = wareHouseCode,
                    Option        = DeliveryOptionType.Shipping,
                    Address       = new ShippingAddress_V02
                    {
                        FirstName = string.Empty,
                        LastName  = string.Empty,
                        Recipient = string.Empty
                    }
                },
                CountryCode = locale.Substring(3)
            };

            // Calculate totals.
            if (calculate)
            {
                shoppingCart.Totals = shoppingCart.Calculate();
            }
            else
            {
                // Use dummy totals
                shoppingCart.Totals = totals ?? new OrderTotals_V01
                {
                    AmountDue          = 1000M,
                    BalanceAmount      = 900M,
                    DiscountPercentage = 50M,
                    VolumePoints       = 1000
                };
            }

            return(shoppingCart);
        }
        /// <summary>
        /// Gets the basic shopping cart.
        /// </summary>
        /// <param name="distributorId">The distributor id.</param>
        /// <param name="locale">The locale.</param>
        /// <param name="freightCode">The freight code.</param>
        /// <param name="wareHouseCode">The ware house code.</param>
        /// <param name="calculate">if set to <c>true</c> [calculate].</param>
        /// <param name="totals">The totals.</param>
        /// <param name="shoppingCartItem">The shopping cart item.</param>
        /// <param name="orderCType">Type of the order C.</param>
        /// <returns></returns>
        internal static MyHLShoppingCart GetBasicShoppingCart(string distributorId, string locale, string freightCode, string wareHouseCode, bool calculate, OrderTotals_V01 totals, List <DistributorShoppingCartItem> shoppingCartItem, OrderCategoryType orderCType)
        {
            if (string.IsNullOrEmpty(locale))
            {
                locale = "en-US";
            }

            if (string.IsNullOrEmpty(freightCode))
            {
                freightCode = HLConfigManager.CurrentPlatformConfigs[locale].ShoppingCartConfiguration.DefaultFreightCode;
            }

            if (string.IsNullOrEmpty(wareHouseCode))
            {
                wareHouseCode = HLConfigManager.CurrentPlatformConfigs[locale].ShoppingCartConfiguration.DefaultWarehouse;
            }

            var cartItemList = new ShoppingCartItemList();

            cartItemList.AddRange(shoppingCartItem.Select(i => new ShoppingCartItem_V01
            {
                ID                 = i.ID,
                MinQuantity        = i.MinQuantity,
                PartialBackordered = i.PartialBackordered,
                Quantity           = i.Quantity,
                SKU                = i.SKU,
                Updated            = i.Updated
            }));

            var shoppingCart = new MyHLShoppingCart
            {
                Locale            = locale,
                ShoppingCartItems = shoppingCartItem,
                CartItems         = cartItemList,
                DistributorID     = string.IsNullOrEmpty(distributorId) ? "webtest1" : distributorId,
                FreightCode       = freightCode,
                CurrentItems      = cartItemList,
                DeliveryInfo      = new ShippingInfo
                {
                    FreightCode   = freightCode,
                    WarehouseCode = wareHouseCode,
                    Option        = DeliveryOptionType.Shipping,
                    Address       = new ShippingAddress_V02
                    {
                        FirstName = string.Empty,
                        LastName  = string.Empty,
                        Recipient = string.Empty
                    }
                },
                CountryCode   = locale.Substring(3),
                OrderCategory = orderCType
            };

            // Calculate totals.
            if (calculate)
            {
                shoppingCart.Totals = shoppingCart.Calculate();
            }
            else
            {
                // Use dummy totals
                shoppingCart.Totals = totals ?? new OrderTotals_V01
                {
                    AmountDue          = 1000M,
                    BalanceAmount      = 900M,
                    DiscountPercentage = 50M,
                    VolumePoints       = 1000
                };
            }

            // Rules results
            shoppingCart.RuleResults = new List <ShoppingCartRuleResult>();

            return(shoppingCart);
        }
        protected override ShoppingCartRuleResult PerformRules(MyHLShoppingCart cart,
                                                               ShoppingCartRuleReason reason,
                                                               ShoppingCartRuleResult Result)
        {
            Result.Result = RulesResult.Success;

            if (cart == null)
            {
                return(Result);
            }

            Result = base.PerformRules(cart, reason, Result);
            if (Result.Result == RulesResult.Failure)
            {
                return(Result);
            }

            var manager = GetPurchaseRestrictionManager(cart.DistributorID);

            if (manager == null)
            {
                return(Result);
            }

            var currentLimits = manager.ApplicableLimits == null ? null : manager.ApplicableLimits.Where(x => (x as PurchasingLimits_V01).LimitsRestrictionType == LimitsRestrictionType.PurchasingLimits && (x as PurchasingLimits_V01).maxVolumeLimit > -1);

            if (currentLimits == null || currentLimits.Count() == 0)
            {
                return(Result);
            }
            var limits = currentLimits.First() as PurchasingLimits_V01;

            if (limits != null && limits.maxVolumeLimit > -1)
            {
                if (!cart.OnCheckout)
                {
                    if (limits.RemainingVolume > decimal.Zero)
                    {
                        Result.Result = RulesResult.Failure;
                        ///New Members are subject to a 7 day cooling off period.  During this time Members are limited to £163.92.  Your cooling off period began on <date1> and ends on <date2>
                        Result.AddMessage(
                            string.Format(
                                HttpContext.GetGlobalResourceObject(
                                    string.Format("{0}_Rules", HLConfigManager.Platform),
                                    "LimitsInfoWithinDays").ToString(), limits.maxVolumeLimit, getBeginDate(cart.DistributorID, cart.CountryCode), getEndDate(cart.DistributorID, cart.CountryCode)));
                    }
                    else
                    {
                        Result.Result = RulesResult.Failure;
                        /// Member is subject to 7 Day Cooling Off Purchase Limit of  £163.92 and has already reached the limit. Member can only purchase items after the Cooling Off Period has been completed. The Cooling Off Period will end on: <DATE>
                        Result.AddMessage(
                            string.Format(
                                HttpContext.GetGlobalResourceObject(
                                    string.Format("{0}_Rules", HLConfigManager.Platform),
                                    "LimitsExceededWithinDays").ToString(), limits.maxVolumeLimit, getEndDate(cart.DistributorID, cart.CountryCode)));
                        return(Result);
                    }
                }
                var calcTheseItems = new List <ShoppingCartItem_V01>();
                calcTheseItems.AddRange(from i in cart.CartItems
                                        where !APFDueProvider.IsAPFSku(i.SKU)
                                        select
                                        new ShoppingCartItem_V01(i.ID, i.SKU, i.Quantity, i.Updated,
                                                                 i.MinQuantity));

                foreach (var item in cart.ItemsBeingAdded)
                {
                    var existingItem =
                        calcTheseItems.Find(ci => ci.SKU == item.SKU);
                    if (null != existingItem)
                    {
                        existingItem.Quantity += item.Quantity;
                    }
                    else
                    {
                        calcTheseItems.Add(new ShoppingCartItem_V01(0, item.SKU, item.Quantity, DateTime.Now));
                    }
                }
                var totals = cart.Calculate(calcTheseItems, false) as OrderTotals_V01;
                if (null == totals)
                {
                    var message =
                        string.Format(
                            "Purchasing Limits DiscountedRetail calculation failed due to Order Totals returning a null for Distributor {0}",
                            cart.DistributorID);
                    LoggerHelper.Error(message);
                    throw new ApplicationException(message);
                }
                decimal discountedRetailInCart = totals.ItemTotalsList.Sum(x => (x as ItemTotal_V01).DiscountedPrice);
                if (limits.RemainingVolume - discountedRetailInCart < 0)
                {
                    Result = reportError(cart, Result, discountedRetailInCart - limits.RemainingVolume, limits.maxVolumeLimit);
                    cart.ItemsBeingAdded.Clear();
                }
            }

            return(Result);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (HLConfigManager.Configurations.DOConfiguration.IsChina && HLConfigManager.Configurations.PaymentsConfiguration.ShowBigGrandTotal)
            {
                lblGrandTotal.Attributes.Add("class", "Title");
                lblDisplayGrandTotal.Attributes.Add("class", "Title");
            }
            if (IsChina)
            {
                blErrors.Items.Clear();
            }

            MyHLShoppingCart shoppingCart = (Page as ProductsBase).ShoppingCart;

            OrderMonth.RegisterOrderMonthControls(pnlOrderMonth, lblOrderMonthChanged, ProductsBase.IsEventTicketMode,
                                                  pnlOrderMonthLabel);

            var control = loadPurchasingLimitsControl(false);

            if (control != null)
            {
                pnlPurchaseLimits.Visible = true;
                pnlPurchaseLimits.Controls.Add(control);
            }

            if (HLConfigManager.Configurations.CheckoutConfiguration.YourPriceWithAllCharges)
            {
                shoppingCart.Calculate();
            }
            BindTotals();
            if (trYourLevel != null)
            {
                trYourLevel.Visible = false;                      // Hide row by default
            }
            if (shoppingCart.OrderCategory == OrderCategoryType.ETO ||
                !HLConfigManager.Configurations.CheckoutConfiguration.HasEarnBase)
            {
                if (shoppingCart.OrderCategory == OrderCategoryType.ETO ||
                    !HLConfigManager.Configurations.CheckoutConfiguration.HasSummaryEarnBase)
                {
                    trEarnBase.Visible = false;
                }
            }
            if (!HLConfigManager.Configurations.CheckoutConfiguration.HasSubTotal)
            {
                divDistributorSubtotal.Visible = false;
            }
            if (HLConfigManager.Configurations.CheckoutConfiguration.HidePHShippingForETO)
            {
                if (SessionInfo.IsEventTicketMode)
                {
                    trPackingHandling.Visible = false;
                    if (HLConfigManager.Configurations.CheckoutConfiguration.ShowDistributorSubTotalForETO)
                    {
                        divDistributorSubtotal.Visible = true;
                    }
                    else
                    {
                        divDistributorSubtotal.Visible = false;
                    }
                    if (HLConfigManager.Configurations.CheckoutConfiguration.ShowVolumePoinsForETO)
                    {
                        trVolumePoints.Visible = true;
                    }
                    else
                    {
                        trVolumePoints.Visible = false;
                    }
                }
            }
            if (!HLConfigManager.Configurations.CheckoutConfiguration.HasOrderMonthVolumePoints)
            {
                trOrderMonthVP.Visible = false;
            }
            string levelDSType = (Page as ProductsBase).Level;

            if (levelDSType == "DS")
            {
                imgOrderMonth.Visible = true;
            }
            else
            {
                imgOrderMonth.Visible = false;
            }

            if (imgEarnBase != null)
            {
                imgEarnBase.Visible = CheckoutTotalsDetailed.ShowEarnBaseHelpInfo();
            }

            if (HLConfigManager.Configurations.DOConfiguration.IsChina)
            {
                if (HLConfigManager.Configurations.CheckoutConfiguration.HasOtherCharges)
                {
                    trOtherCharges.Visible = true;
                }

                // Conditioning tax vat row visibility.
                if (trTaxVat != null)
                {
                    trTaxVat.Visible = HLConfigManager.Configurations.CheckoutConfiguration.HasTaxVat;
                }

                if (HLConfigManager.Configurations.CheckoutConfiguration.HasLocalTax)
                {
                    trLocalTax.Visible = true;
                }

                if (HLConfigManager.Configurations.CheckoutConfiguration.HideFreightCharges && ShoppingCart.DeliveryInfo.Option == DeliveryOptionType.Pickup)
                {
                    trShippingCharge.Visible = false;
                }

                if (HLConfigManager.Configurations.CheckoutConfiguration.HideShippingCharges)
                {
                    trShippingCharge.Visible = false;
                }

                if (!HLConfigManager.Configurations.CheckoutConfiguration.HasRetailPrice)
                {
                    if (trRetailPrice != null)
                    {
                        trRetailPrice.Visible = false;
                    }
                }
                else if (SessionInfo.IsEventTicketMode && trRetailPrice != null)
                {
                    trRetailPrice.Visible = HLConfigManager.Configurations.CheckoutConfiguration.HasRetailPriceForETO;
                }

                if (trPackingHandling != null)
                {
                    trPackingHandling.Visible = false;
                }

                if (HLConfigManager.Configurations.CheckoutConfiguration.HasLogisticCharges)
                {
                    if (trLogisticCharge != null)
                    {
                        trLogisticCharge.Visible = true;
                    }
                }

                if (ShoppingCart.DeliveryInfo != null)
                {
                    if (ShoppingCart.DeliveryInfo.Option == DeliveryOptionType.Pickup)
                    {
                        if (HLConfigManager.Configurations.CheckoutConfiguration.HasPickupCharge)
                        {
                            if (lblDisplayShippingCharges != null)
                            {
                                lblDisplayShippingCharges.Text = (string)GetLocalResourceObject("lblDisplayPickupCharges");
                            }
                        }
                        else
                        {
                            trShippingCharge.Visible = false;
                        }
                    }
                }

                if (DistributorOrderingProfile != null && DistributorOrderingProfile.IsPC)
                {
                    if ((ShoppingCart.PcLearningDeliveryoption == ServiceProvider.CatalogSvc.DeliveryOptionType.Unknown &&
                         shoppingCart.DeliveryOption == ServiceProvider.CatalogSvc.DeliveryOptionType.Shipping) || ShoppingCart.PcLearningDeliveryoption == ServiceProvider.CatalogSvc.DeliveryOptionType.Shipping)
                    {
                        trPCLearningPoint.Visible      = true;
                        trPCLearningPointLimit.Visible = true;
                        GetEligibleUsePoint();
                    }
                    else
                    {
                        trPCLearningPoint.Visible      = false;
                        trPCLearningPointLimit.Visible = false;
                    }
                }
                else if (ShoppingCart.OrderCategory == OrderCategoryType.ETO && SessionInfo != null && !SessionInfo.IsReplacedPcOrder)
                {
                    trPCLearningPoint.Visible      = true;
                    trPCLearningPointLimit.Visible = true;
                    GetEligibleUseETOPoints();
                }
                else
                {
                    trPCLearningPoint.Visible      = false;
                    trPCLearningPointLimit.Visible = false;
                }
            }
            else
            {
                if (trDiscountTotal != null)
                {
                    trDiscountTotal.Visible = HLConfigManager.Configurations.CheckoutConfiguration.ShowDisocuntTotal;
                }
            }

            if (DistributorOrderingProfile != null && DistributorOrderingProfile.IsPC)
            {
                trVolumePoints.Visible = false;
            }

            if (!HLConfigManager.Configurations.CheckoutConfiguration.HasRetailPrice)
            {
                if (trRetailPrice != null)
                {
                    trRetailPrice.Visible = false;
                }
            }
            else if (SessionInfo.IsEventTicketMode && trRetailPrice != null)
            {
                trRetailPrice.Visible = HLConfigManager.Configurations.CheckoutConfiguration.HasRetailPriceForETO;
            }

            if (HLConfigManager.Configurations.DOConfiguration.IsChina)
            {
                if (!HLConfigManager.Configurations.CheckoutConfiguration.HasRetailPrice)
                {
                    if (trRetailPrice != null)
                    {
                        trRetailPrice.Visible = false;
                    }
                }
                else if (SessionInfo.IsEventTicketMode && trRetailPrice != null)
                {
                    trRetailPrice.Visible = HLConfigManager.Configurations.CheckoutConfiguration.HasRetailPriceForETO;
                }
                trWeight.Visible = false;
            }
            else
            {
                trGrandTotal.Visible              = false;
                trPackingHandling.Visible         = false;
                lblDisplayPackageHandling.Visible = false;
                lblPackageHandling.Visible        = false;
                trOtherCharges.Visible            = false;
                trLogisticCharge.Visible          = false;
                trShippingCharge.Visible          = !string.IsNullOrEmpty(lblShippingCharges.Text) && HLConfigManager.Configurations.DOConfiguration.ShowFreightChrageonCOP1 &&
                                                    shoppingCart.DeliveryInfo != null && shoppingCart.DeliveryInfo.Option == DeliveryOptionType.Shipping;
                trTaxVat.Visible               = false;
                trLocalTax.Visible             = false;
                trPCLearningPoint.Visible      = false;
                trPCLearningPointLimit.Visible = false;
            }

            if (HLConfigManager.Configurations.DOConfiguration.AllowHAP && ShoppingCart.OrderCategory == OrderCategoryType.HSO)
            {
                trOrderMonth.Visible   = false;
                trOrderMonthVP.Visible = false;
                if (ShoppingCart.DsType != null && ShoppingCart.DsType == ServiceProvider.DistributorSvc.Scheme.Member)
                {
                    trEarnBase.Visible = trDiscountRate.Visible = false;
                    if (trYourLevel != null)
                    {
                        trYourLevel.Visible = true;
                    }
                    lblYourLevel.Text = GetGlobalResourceString(string.Format("DisplayLevel_{0}", ProductsBase.LevelSubType), defaultValue: string.Empty);
                }
            }

            if (trWeight != null)
            {
                trWeight.Visible = HLConfigManager.Configurations.CheckoutConfiguration.DisplayWeight && !SessionInfo.IsEventTicketMode;
            }

            if (HLConfigManager.Configurations.DOConfiguration.DisplayBifurcationKeys &&
                ShoppingCart.DsType != null && ShoppingCart.DsType == ServiceProvider.DistributorSvc.Scheme.Member)
            {
                lblDisplayVolumePoints.Text = (string)GetLocalResourceObject("lblDisplayVolumePointsResource1MB.Text");
            }
        }