public override void SetLimits(int orderMonth, IPurchaseRestrictionManager manager, PurchasingLimits_V01 limits) { if (manager.PurchasingLimits == null) { manager.PurchasingLimits = new Dictionary <int, PurchasingLimits_V01>(); } var FOPlimits = GetFOPLimits(manager); if (FOPlimits != null && FOPlimits.maxVolumeLimit != -1 && !FOPlimits.Completed) { manager.PurchasingLimits[orderMonth] = CopyPurchasingLimits(FOPlimits); } else { manager.PurchasingLimits[orderMonth] = CopyPurchasingLimits(limits); } switch (manager.PurchasingLimits[orderMonth].LimitsRestrictionType) { // Purchasing Limits case LimitsRestrictionType.PurchasingLimits: { PurchaseRestrictionProvider.SetValues(manager.PurchasingLimits[orderMonth], HLConfigManager.Configurations.DOConfiguration.PurchasingLimitRestrictionPeriod, manager.PurchasingLimits[orderMonth].PurchaseLimitType); } break; default: // FOP and OT is volume PurchaseRestrictionProvider.SetValues(manager.PurchasingLimits[orderMonth], PurchasingLimitRestrictionPeriod.OneTime, manager.PurchasingLimits[orderMonth].maxVolumeLimit > -1 ? PurchaseLimitType.Volume : PurchaseLimitType.None); break; } }
private bool CanBuy_eLearningRule(MyHLShoppingCart hlCart) { bool retVal = true; if (PurchaseRestrictionProvider.RequireTraining(hlCart.DistributorID, hlCart.Locale, hlCart.CountryCode)) { //var currentLimits = PurchasingLimitProvider.GetCurrentPurchasingLimits(hlCart.DistributorID); var currentLimits = GetCurrentPurchasingLimits(hlCart.DistributorID, GetCurrentOrderMonth()); decimal currentVolumePoints = hlCart.VolumeInCart; if (hlCart.ItemsBeingAdded != null && hlCart.ItemsBeingAdded.Any()) { foreach (var i in hlCart.ItemsBeingAdded) { var currentItem = CatalogProvider.GetCatalogItem(i.SKU, Country); currentVolumePoints += currentItem.VolumePoints * i.Quantity; } } currentVolumePoints += (currentLimits.maxVolumeLimit - currentLimits.RemainingVolume); if (currentVolumePoints > HLConfigManager.Configurations.ShoppingCartConfiguration.eLearningMaxPPV) { if (hlCart.ItemsBeingAdded != null) { hlCart.ItemsBeingAdded.Clear(); } retVal = false; } } return(retVal); }
public override void SetPurchaseRestriction(List <TaxIdentification> tins, int orderMonth, string distributorId, IPurchaseRestrictionManager manager) { //check if is a elearning and set the new limits for the second order base.SetPurchaseRestriction(tins, orderMonth, distributorId, manager); var currentLimits = GetLimits(LimitsRestrictionType.PurchasingLimits, orderMonth, manager); if (HLConfigManager.Configurations.ShoppingCartConfiguration.CheckELearning) { PurchaseLimitType limitType = PurchaseLimitType.Volume; currentLimits.PurchaseLimitType = limitType; var session = SessionInfo.GetSessionInfo(distributorId, Locale); if (PurchaseRestrictionProvider.RequireTraining(distributorId, this.Locale, this.Country)) { if (currentLimits.RemainingVolume != currentLimits.maxVolumeLimit && !session.LimitsHasModified) { var used = (currentLimits.maxVolumeLimit - currentLimits.RemainingVolume); var shouldbe = 1100 - used; currentLimits.PurchaseLimitType = limitType; if (currentLimits.RemainingVolume != shouldbe && shouldbe > 0 && !session.LimitsHasModified) { currentLimits.RemainingVolume = HLConfigManager.Configurations.ShoppingCartConfiguration.eLearningMaxPPV - (currentLimits.maxVolumeLimit - currentLimits.RemainingVolume); session.LimitsHasModified = true; } } //check for the members without limits and create else if (currentLimits.RemainingVolume == -1 && currentLimits.maxVolumeLimit == -1 && !session.LimitsHasModified) { var currentLoggedInCounrtyCode = Locale.Substring(3); DistributorLoader distributorLoader = new DistributorLoader(); var distributorProfile = distributorLoader.Load(distributorId, currentLoggedInCounrtyCode); var remainingVolume = HLConfigManager.Configurations.ShoppingCartConfiguration.eLearningMaxPPV - distributorProfile.PersonallyPurchasedVolume; //PurchasingLimits_V01 newLimits = new PurchasingLimits_V01(); currentLimits.Month = currentLimits.Month; currentLimits.LastRead = DateTime.UtcNow; currentLimits.RemainingVolume = distributorProfile.PersonallyPurchasedVolume != 0 ? remainingVolume : 0; currentLimits.LimitsRestrictionType = LimitsRestrictionType.PurchasingLimits; currentLimits.PurchaseLimitType = limitType; currentLimits.LastRead = DateTime.UtcNow; currentLimits.maxVolumeLimit = HLConfigManager.Configurations.ShoppingCartConfiguration.eLearningMaxPPV; session.LimitsHasModified = true; } } } else { base.SetPurchaseRestriction(tins, orderMonth, distributorId, manager); } if (currentLimits == null) { return; } SetLimits(orderMonth, manager, currentLimits); }
protected Control loadPurchasingLimitsControl(bool displayStatic) { if (SessionInfo.IsHAPMode) { return(null); } string controlName = HLConfigManager.Configurations.DOConfiguration.PurchasingLimitsControl; if (FOPEnabled && PurchaseRestrictionProvider.HasPurchaseRestriction(this.DistributorID, this.DistributorProfileModel.ProcessingCountry, this.Level)) { controlName = String.IsNullOrEmpty(controlName) ? "~/Ordering/Controls/PurchasingLimits.ascx" : controlName; } if (!String.IsNullOrEmpty(controlName)) { var _purchasingLimits = LoadControl(controlName) as IPurchasingLimits; _purchasingLimits.HideEmptyListItem = false; _purchasingLimits.DisplayStatic = displayStatic; return((Control)_purchasingLimits); } return(null); }
protected override ShoppingCartRuleResult PerformRules(MyHLShoppingCart cart, ShoppingCartRuleReason reason, ShoppingCartRuleResult Result) { //if (!GetPurchaseRestrictionManager(cart.DistributorID).CanPurchase) //{ // cart.ItemsBeingAdded.Clear(); // Result.AddMessage( // string.Format( // HttpContext.GetGlobalResourceObject( // string.Format("{0}_ErrorMessage", HLConfigManager.Platform), "CantBuy").ToString())); // Result.Result = RulesResult.Failure; // return Result; //} var currentlimits = GetCurrentPurchasingLimits(cart.DistributorID, GetCurrentOrderMonth()); if (cart == null || currentlimits == null) { return(Result); } if (cart.ItemsBeingAdded == null || cart.ItemsBeingAdded.Count == 0) { return(Result); } string processingCountryCode = DistributorProfileModel.ProcessingCountryCode; bool bCanPurchase = CanPurchase(cart.DistributorID); bool bCanPurchasePType = CanPurchasePType(cart.DistributorID); var errors = new List <string>(); decimal NewVolumePoints = decimal.Zero; decimal cartVolume = cart.VolumeInCart; bool bLimitExceeded = false; List <string> skuToAdd = new List <string>(); foreach (var item in cart.ItemsBeingAdded) { var currentItem = CatalogProvider.GetCatalogItem(item.SKU, Country); if (currentItem == null) { continue; } if (APFDueProvider.IsAPFSku(item.SKU) || cart.OrderCategory == ServiceProvider.CatalogSvc.OrderCategoryType.ETO) { skuToAdd.Add(item.SKU); } else { if (bCanPurchase) { if (!bCanPurchasePType) { if (currentItem.ProductType == ServiceProvider.CatalogSvc.ProductType.Product) { Result.Result = RulesResult.Failure; errors.Add( string.Format( HttpContext.GetGlobalResourceObject( string.Format("{0}_Rules", HLConfigManager.Platform), "PurchaseLimitTypeProductCategory").ToString(), item.SKU)); continue; } } } else { Result.Result = RulesResult.Failure; errors.Add( string.Format( HttpContext.GetGlobalResourceObject( string.Format("{0}_ErrorMessage", HLConfigManager.Platform), "CantBuy").ToString())); continue; } if (currentlimits.PurchaseLimitType == PurchaseLimitType.Volume || currentlimits.RestrictionPeriod == PurchasingLimitRestrictionPeriod.PerOrder) { if (currentlimits.maxVolumeLimit == -1) { skuToAdd.Add(item.SKU); continue; } NewVolumePoints += currentItem.VolumePoints * item.Quantity; //verifying VP limits didn't exceed if (currentlimits.RemainingVolume - (cartVolume + NewVolumePoints) < 0) { if (currentlimits.LimitsRestrictionType == LimitsRestrictionType.FOP || currentlimits.LimitsRestrictionType == LimitsRestrictionType.OrderThreshold) //MPE FOP { Result.Result = RulesResult.Failure; ///Order exceeds the allowable volume for First Order Program. The Volume on the order needs to be reduced by {0:F2} VPs. The following SKU(s) have not been added to the cart. if (!bLimitExceeded) // to add this message only once { errors.Add( string.Format( HttpContext.GetGlobalResourceObject( string.Format("{0}_Rules", HLConfigManager.Platform), "FOPVolumePointExceeds").ToString(), 1100, PurchaseRestrictionProvider.GetVolumeLimitsAfterFirstOrderFOP( processingCountryCode), PurchaseRestrictionProvider.GetThresholdPeriod(processingCountryCode), -999)); // -999 should be replaced with caluclated value. bLimitExceeded = true; } /// Item SKU:{0}. errors.Add( string.Format( HttpContext.GetGlobalResourceObject( string.Format("{0}_Rules", HLConfigManager.Platform), "VolumePointExceedsThreshold").ToString(), item.SKU)); } else //it exceeded VP but it's not FOP { var itemExists = cart.CartItems.Find(i => i.SKU == item.SKU); if (itemExists != null) //item already exists in cart { Result.Result = RulesResult.Failure; errors.Add( string.Format( HttpContext.GetGlobalResourceObject( string.Format("{0}_Rules", HLConfigManager.Platform), "VolumePointExceedsByIncreasingQuantity").ToString(), item.SKU, item.Quantity)); } else { Result.Result = RulesResult.Failure; errors.Add( string.Format( HttpContext.GetGlobalResourceObject( string.Format("{0}_Rules", HLConfigManager.Platform), "VolumePointExceeds").ToString(), item.SKU)); } } } else // // VP limits didn't exceeded, add item { skuToAdd.Add(item.SKU); } } else //purchasing limits are not per VP nor per order: add item { skuToAdd.Add(item.SKU); } } } if (Result.Result == RulesResult.Failure && errors.Count > 0) { if (cart.OnCheckout && (currentlimits.LimitsRestrictionType == LimitsRestrictionType.FOP || currentlimits.LimitsRestrictionType == LimitsRestrictionType.OrderThreshold)) { Result.AddMessage(string.Format(HttpContext.GetGlobalResourceObject( string.Format("{0}_Rules", HLConfigManager.Platform), "FOPVolumePointExceedsOnCheckout").ToString(), 1100, PurchaseRestrictionProvider.GetVolumeLimitsAfterFirstOrderFOP(processingCountryCode), PurchaseRestrictionProvider.GetThresholdPeriod(processingCountryCode), (cartVolume + NewVolumePoints) - currentlimits.RemainingVolume)); } else { errors = errors.Select(x => x.Replace("-999", ((cartVolume + NewVolumePoints) - currentlimits.RemainingVolume).ToString())).ToList <string>(); Array.ForEach(errors.ToArray(), a => Result.AddMessage(a)); } } cart.ItemsBeingAdded.RemoveAll(s => !skuToAdd.Contains(s.SKU)); return(Result); }
private ShoppingCartRuleResult performRules(MyHLShoppingCart cart, ShoppingCartRuleResult Result, PurchasingLimits_V01 currentlimits) { if (!GetPurchaseRestrictionManager(cart.DistributorID).CanPurchase) { cart.ItemsBeingAdded.Clear(); Result.AddMessage( string.Format( HttpContext.GetGlobalResourceObject( string.Format("{0}_ErrorMessage", HLConfigManager.Platform), "CantBuy").ToString())); Result.Result = RulesResult.Failure; return(Result); } if (cart.ItemsBeingAdded == null || cart.ItemsBeingAdded.Count == 0) { return(Result); } bool bCanPurchasePType = CanPurchasePType(cart.DistributorID); var errors = new List <string>(); decimal NewVolumePoints = decimal.Zero; decimal cartVolume = cart.VolumeInCart; bool bLimitExceeded = false; List <string> skuToAdd = new List <string>(); foreach (var item in cart.ItemsBeingAdded) { var currentItem = CatalogProvider.GetCatalogItem(item.SKU, Country); if (currentItem == null) { continue; } if (!bCanPurchasePType) { if (currentItem.ProductType == ServiceProvider.CatalogSvc.ProductType.Product) { Result.Result = RulesResult.Failure; errors.Add( string.Format( HttpContext.GetGlobalResourceObject( string.Format("{0}_Rules", HLConfigManager.Platform), "PurchaseLimitTypeProductCategory").ToString(), item.SKU)); continue; } } if (currentlimits.PurchaseLimitType == PurchaseLimitType.Volume) { if (currentlimits.maxVolumeLimit == -1) { skuToAdd.Add(item.SKU); continue; } NewVolumePoints += currentItem.VolumePoints * item.Quantity; if (currentlimits.RemainingVolume - (cartVolume + NewVolumePoints) < 0) { Result.Result = RulesResult.Failure; if (currentlimits.LimitsRestrictionType == LimitsRestrictionType.FOP) //MPE FOP { string processingCountryCode = DistributorProfileModel.ProcessingCountryCode; ///Order exceeds the allowable volume for First Order Program. The Volume on the order needs to be reduced by {0:F2} VPs. The following SKU(s) have not been added to the cart. if (!bLimitExceeded) // to add this message only once { if (currentlimits.PurchaseType == OrderPurchaseType.Consignment) { errors.Add( string.Format( HttpContext.GetGlobalResourceObject( string.Format("{0}_Rules", HLConfigManager.Platform), "FOPConsignmentVolumePointExceeds").ToString(), 1100, PurchaseRestrictionProvider.GetVolumeLimitsAfterFirstOrderFOP(processingCountryCode), PurchaseRestrictionProvider.GetThresholdPeriod(processingCountryCode))); } else if (currentlimits.PurchaseType == OrderPurchaseType.PersonalConsumption) { errors.Add( string.Format( HttpContext.GetGlobalResourceObject( string.Format("{0}_Rules", HLConfigManager.Platform), "FOPPersonalConsumptionVolumePointExceeds").ToString(), 1100, PurchaseRestrictionProvider.GetThresholdPeriod(processingCountryCode))); } else { errors.Add( string.Format( HttpContext.GetGlobalResourceObject( string.Format("{0}_Rules", HLConfigManager.Platform), "FOPVolumePointExceeds").ToString(), 1100, PurchaseRestrictionProvider.GetVolumeLimitsAfterFirstOrderFOP( processingCountryCode), PurchaseRestrictionProvider.GetThresholdPeriod(processingCountryCode), -999)); // -999 should be replaced with caluclated value. } bLimitExceeded = true; } /// Item SKU:{0}. //errors.Add( // string.Format( // HttpContext.GetGlobalResourceObject( // string.Format("{0}_Rules", HLConfigManager.Platform), // "VolumePointExceedsThreshold").ToString(), item.SKU)); } else { if (cart.CartItems.Exists(i => i.SKU == item.SKU)) { ///The quantity of the item SKU:{0} can not be increased by {1} because it exceeds your volume points limit. errors.Add( string.Format( HttpContext.GetGlobalResourceObject( string.Format("{0}_Rules", HLConfigManager.Platform), "VolumePointExceedsByIncreasingQuantity").ToString(), item.SKU, item.Quantity)); } else { ///Item SKU:{0} has not been added to the cart since by adding that into the cart, you exceeded your volume points limit. errors.Add( string.Format( HttpContext.GetGlobalResourceObject( string.Format("{0}_Rules", HLConfigManager.Platform), "VolumePointExceeds").ToString(), item.SKU)); } } } else { skuToAdd.Add(item.SKU); } } else { skuToAdd.Add(item.SKU); } } if (Result.Result == RulesResult.Failure && errors.Count > 0) { errors = errors.Select(x => x.Replace("-999", ((cartVolume + NewVolumePoints) - currentlimits.RemainingVolume).ToString())).ToList <string>(); Array.ForEach(errors.ToArray(), a => Result.AddMessage(a)); } cart.ItemsBeingAdded.RemoveAll(s => !skuToAdd.Contains(s.SKU)); return(Result); }