protected virtual bool shouldApplyRules(DateTime startDate, DateTime endDate, int limtDays) { int currentLocalDate = RecentOrdersHelper.ConvertDate(DateUtils.GetCurrentLocalTime(this.Country)); int intStartDate = RecentOrdersHelper.ConvertDate(startDate); int intEndDate = limtDays <= 0 ? RecentOrdersHelper.ConvertDate(endDate) : RecentOrdersHelper.ConvertDate(startDate.AddDays(limtDays)); if (currentLocalDate >= intStartDate && currentLocalDate <= intEndDate) { return(true); } return(false); }
private ShoppingCartRuleResult PerformRules(ShoppingCart_V02 cart, ShoppingCartRuleReason reason, ShoppingCartRuleResult Result) { if (reason == ShoppingCartRuleReason.CartItemsBeingAdded) { int skuLimit = 1; try { skuLimit = int.Parse(Settings.GetRequiredAppSetting("USNumSkuLimitSku")); } catch { } if (cart.CurrentItems == null) { return(Result); } string sku = cart.CurrentItems[0].SKU.Trim(); if (_limitQtySku.Equals(sku)) { bool bSKUQtyOverLimit = false; if (cart.CurrentItems[0].Quantity > skuLimit) { bSKUQtyOverLimit = true; } MyHLShoppingCart myCart = cart as MyHLShoppingCart; if (bSKUQtyOverLimit == false) { if (myCart.CartItems != null && myCart.CartItems.Where(x => x.SKU == sku).Any()) // already in cart { bSKUQtyOverLimit = true; } } if (bSKUQtyOverLimit == false) { int numSkusOrders = 0; RecentOrdersHelper orders = getInternetOrders(cart.DistributorID, this.Locale, DateUtils.GetCurrentLocalTime(this.Country)); if (orders != null) { foreach (var o in orders.Orders) { foreach (var i in o.CartItems) { if (i.SKU == sku) { numSkusOrders = numSkusOrders + i.Quantity; break; } } } } if (numSkusOrders >= skuLimit) { bSKUQtyOverLimit = true; } else { if (cart.CurrentItems[0].Quantity + numSkusOrders > skuLimit) { bSKUQtyOverLimit = true; } } } if (bSKUQtyOverLimit == true) { if (Locale == "es-US" || Locale == "es-PR") { Result.AddMessage(string.Format("Tu pedido de {0} excede la cantidad máxima de 1 por Asociado cada {1} días.", sku, HLConfigManager.Configurations.ShoppingCartConfiguration.SKUQuantityLimitPeriodByDay)); } else { Result.AddMessage(string.Format("Your order of {0} exceeds the maximum quantity of 1 per member every {1} calendar days.", sku, HLConfigManager.Configurations.ShoppingCartConfiguration.SKUQuantityLimitPeriodByDay)); } cart.RuleResults.Add(Result); Result.Result = RulesResult.Failure; } } } //else if (reason == ShoppingCartRuleReason.CartCreated) only get orders when adding 017A to cart //{ // DateTime currentLocalTime = DateUtils.GetCurrentLocalTime(this.Country); // RecentOrders orders = getInternetOrders(cart.DistributorID, this.Locale, currentLocalTime); // if (orders.LastRetrieveDateTime.Date < currentLocalTime.Date) // { // _Cache.Expire(typeof(RecentOrders), getCacheKey(cart.DistributorID, Locale)); // getInternetOrders(cart.DistributorID, this.Locale, currentLocalTime); // } //} else if (reason == ShoppingCartRuleReason.CartClosed) // order placed { _Cache.Expire(typeof(RecentOrdersHelper), getCacheKey(cart.DistributorID, Locale)); } return(Result); }
private ShoppingCartRuleResult checkSKULimitForCountry(MyHLShoppingCart myCart, ShoppingCartRuleResult Result) { Dictionary <string, List <SKULimitationInfo> > limits = SKULimitationProvider.GetSKULimitationInfo(); if (limits != null) { if (limits.ContainsKey(Country)) { List <SKULimitationInfo> limitInfo = limits[Country]; foreach (var l in limitInfo) { if (limitInfo != null && limitInfo.Count > 0 && shouldApplyRules(l.StartDate, l.EndDate, l.LimitPeriodByDay)) { if (myCart.CurrentItems == null) { return(Result); } string sku = myCart.CurrentItems[0].SKU.Trim(); if (l.SKU.Trim().Equals(sku)) { _skuQuantityLimitPeriodByDay = l.LimitPeriodByDay; _startDate = RecentOrdersHelper.ConvertDate(l.StartDate); bool bSKUQtyOverLimit = false; int SKUQtyBeingAdded = myCart.CurrentItems[0].Quantity; if (SKUQtyBeingAdded > l.MaxQuantity) { bSKUQtyOverLimit = true; } int qtyInCart = 0; if (bSKUQtyOverLimit == false) { if (myCart.CartItems != null && myCart.CartItems.Where(x => x.SKU == sku).Any()) // already in cart { qtyInCart = myCart.CartItems.Where(x => x.SKU == sku).Sum(x => x.Quantity); if ((qtyInCart + SKUQtyBeingAdded) > l.MaxQuantity) { bSKUQtyOverLimit = true; } } } if (bSKUQtyOverLimit == false) { int numSkusOrders = qtyInCart + SKUQtyBeingAdded; // what's in cart plus what's being added RecentOrdersHelper orders = getInternetOrders(myCart.DistributorID, this.Locale, DateUtils.GetCurrentLocalTime(this.Country)); if (orders != null) { foreach (var o in orders.Orders) { foreach (var i in o.CartItems) { if (i.SKU == sku) { numSkusOrders += i.Quantity; //break; } } } } if (numSkusOrders > l.MaxQuantity) { bSKUQtyOverLimit = true; } //else //{ // if (myCart.CurrentItems[0].Quantity + numSkusOrders > l.MaxQuantity) // { // bSKUQtyOverLimit = true; // } //} } if (bSKUQtyOverLimit == true) { /// Your order of {0} exceeds the maximum quantity of {1} per member every {2} calendar days. Result.AddMessage( string.Format( HttpContext.GetGlobalResourceObject( string.Format("{0}_Rules", HLConfigManager.Platform), "SKULimitExceedByDay").ToString(), myCart.CurrentItems[0].SKU, l.MaxQuantity, l.LimitPeriodByDay)); myCart.RuleResults.Add(Result); Result.Result = RulesResult.Failure; } } } } } } return(Result); }