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 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); }