private void ReadFromData() { DistributorOrderingProfile distributorOrderingProfile = DistributorOrderingProfileProvider.GetProfile(DistributorID, CountryCode); _distributorId = DistributorID; _apfDueDate = distributorOrderingProfile.ApfDueDate; if (_testing) { APFDueProvider.UpdateAPFDuePaid(_distributorId, _apfDueDate); } _apfSku = APFDueProvider.GetAPFSku(); _cart = (Page as ProductsBase).ShoppingCart; _apfIsDue = APFDueProvider.IsAPFDueAndNotPaid(_distributorId, HLConfigManager.Configurations.Locale); _apfDueWithinOneYear = APFDueProvider.IsAPFDueWithinOneYear(_distributorId, CountryCode); _apfDueGreaterThanOneYear = APFDueProvider.IsAPFDueGreaterThanOneYear(_distributorId, CountryCode); if (_apfIsDue) { _apfsDue = APFDueProvider.APFQuantityDue(_distributorId, HLConfigManager.Configurations.Locale); } List <ShoppingCartItem_V01> item = (from c in _cart.CartItems where c.SKU == _apfSku select c).ToList(); _apfsInCart = 0; if (item.Count > 0) { _apfsInCart = item[0].Quantity; } }
private ShoppingCartRuleResult CartItemBeingDeletedRuleHandler(ShoppingCart_V01 cart, ShoppingCartRuleResult result, string level) { if (APFDueProvider.IsAPFDueAndNotPaid(cart.DistributorID, Locale) && HLConfigManager.Configurations.APFConfiguration.StandaloneAPFOnlyAllowed) { result.Result = RulesResult.Failure; result.AddMessage( HttpContext.GetGlobalResourceObject(string.Format("{0}_ErrorMessage", HLConfigManager.Platform), "CompleteAPFPurchase") as string); var sku = APFDueProvider.GetAPFSku(); SetApfRuleResponse(result, ApfAction.None, sku, "ApfRule", TypeOfApf.StandaloneAPFOnlyAllowed, "CompleteAPFPurchase"); cart.RuleResults.Add(result); return(result); } //Deleting is a little different than Inserting, because delete handles multiple skus while insert only does one //so we can use the cart.CurrentItems to control this. Anything the rule says to not delete, we remove from the CurrentItems //Delete post-rule will only delete what is left in there bool isStandaloneAPF = APFDueProvider.hasOnlyAPFSku(cart.CartItems, Locale); var toRemove = new List <ShoppingCartItem_V01>(); var hlCart = cart as MyHLShoppingCart; if (null != hlCart) { foreach (ShoppingCartItem_V01 item in cart.CurrentItems) { if (APFDueProvider.IsAPFSku(item.SKU)) { if ( !APFDueProvider.CanRemoveAPF(cart.DistributorID, Thread.CurrentThread.CurrentCulture.Name, level)) { result.Result = RulesResult.Failure; result.AddMessage( HttpContext.GetGlobalResourceObject( string.Format("{0}_ErrorMessage", HLConfigManager.Platform), "CannotRemoveAPFSku") as string); var sku = APFDueProvider.GetAPFSku(); SetApfRuleResponse(result, ApfAction.None, sku, "ApfRule", TypeOfApf.StandaloneAPFOnlyAllowed, "CannotRemoveAPFSku"); cart.RuleResults.Add(result); } else { if (APFDueProvider.IsAPFDueAndNotPaid(cart.DistributorID, Locale)) { var originalItem = (from c in cart.CartItems where c.SKU == cart.CurrentItems[0].SKU select c).ToList(); int requiredQuantity = APFDueProvider.APFQuantityDue(cart.DistributorID, Locale); if (level == "SP") { item.Quantity = requiredQuantity; result.Result = RulesResult.Recalc; result.AddMessage( HttpContext.GetGlobalResourceObject( string.Format("{0}_ErrorMessage", HLConfigManager.Platform), "RequiredAPFLeftInCart") as string); var sku = APFDueProvider.GetAPFSku(); SetApfRuleResponse(result, ApfAction.None, sku, "ApfRule", TypeOfApf.StandaloneAPFOnlyAllowed, "RequiredAPFLeftInCart"); cart.RuleResults.Add(result); //toRemove.Add(item); cart.APFEdited = false; return(result); } //Add for ChinaDO if (HLConfigManager.Configurations.APFConfiguration.CantDSRemoveAPF) { result.Result = RulesResult.Recalc; result.AddMessage( HttpContext.GetGlobalResourceObject( string.Format("{0}_ErrorMessage", HLConfigManager.Platform), "RequiredAPFLeftInCart") as string); var sku = APFDueProvider.GetAPFSku(); SetApfRuleResponse(result, ApfAction.None, sku, "ApfRule", TypeOfApf.StandaloneAPFOnlyAllowed, "RequiredAPFLeftInCart"); cart.RuleResults.Add(result); //toRemove.Add(item); cart.APFEdited = false; return(result); } } cart.APFEdited = true; toRemove.Add(item); // added } } else { toRemove.Add(item); // added } } //if (toRemove.Count > 0) //{ // cart.CurrentItems.Remove(toRemove[0]); //} var remainingItems = (from c in cart.CartItems where !toRemove.Any(x => x.SKU == c.SKU) select c).ToList(); //List<ShoppingCartItem_V01> remainingItems = (from c in cart.CartItems where c.SKU != cart.CurrentItems[0].SKU select c).ToList(); var mags = CartHasOnlyTodaysMagazine(remainingItems); if (mags.Count > 0) { foreach (ShoppingCartItem_V01 item in mags) { (cart as MyHLShoppingCart).DeleteTodayMagazine(item.SKU); remainingItems.Remove(item); if (!cart.CurrentItems.Exists(c => c.SKU == item.SKU)) { cart.CurrentItems.Add(item); } } result.Result = RulesResult.Failure; result.AddMessage( HttpContext.GetGlobalResourceObject( string.Format("{0}_ErrorMessage", HLConfigManager.Platform), "NoTodayMagazineWithStandalonAPF") as string); var sku = APFDueProvider.GetAPFSku(); SetApfRuleResponse(result, ApfAction.None, sku, "ApfRule", TypeOfApf.StandaloneAPFOnlyAllowed, "NoTodayMagazineWithStandalonAPF"); cart.RuleResults.Add(result); } // added if (remainingItems.Count > 0) { var list = new ShoppingCartItemList(); list.AddRange(remainingItems); isStandaloneAPF = APFDueProvider.hasOnlyAPFSku(list, Locale); if (isStandaloneAPF) { SetAPFDeliveryOption(hlCart); } else { if (APFDueProvider.IsAPFSkuPresent(cart.CurrentItems)) { SetNonStandAloneAPFDeliveryOption(hlCart); } } } else { SetNonStandAloneAPFDeliveryOption(hlCart); } } //if((from c in cart.CurrentItems where APFDueProvider.IsAPFSku(c.SKU) select c).Count() >0) //{ // if (isStandaloneAPF) // { // SetAPFDeliveryOption(hlCart); // } //} return(result); }
private ShoppingCartRuleResult CartItemBeingAddedRuleHandler(ShoppingCart_V01 cart, ShoppingCartRuleResult result, string level) { var distributorId = cart.DistributorID; var isAPFDueandNotPaid = APFDueProvider.IsAPFDueAndNotPaid(distributorId, Locale); if (isAPFDueandNotPaid && HLConfigManager.Configurations.APFConfiguration.StandaloneAPFOnlyAllowed) { result.Result = RulesResult.Failure; result.AddMessage( HttpContext.GetGlobalResourceObject(string.Format("{0}_ErrorMessage", HLConfigManager.Platform), "CompleteAPFPurchase") as string); var sku = APFDueProvider.GetAPFSku(); SetApfRuleResponse(result, ApfAction.None, sku, "ApfRule", TypeOfApf.StandaloneAPFOnlyAllowed, "CompleteAPFPurchase"); cart.RuleResults.Add(result); return(result); } else if (isAPFDueandNotPaid && HLConfigManager.Configurations.DOConfiguration.IsChina) { string cacheKey = string.Empty; bool reloadAPFs = (null != cart && null != cart.CartItems) && isAPFDueandNotPaid && !APFDueProvider.IsAPFSkuPresent(cart.CartItems); DoApfDue(cart.DistributorID, cart, cacheKey, Locale, reloadAPFs, result, true); } if ((cart as MyHLShoppingCart).OrderCategory == OrderCategoryType.ETO) //No APFs allowed in ETO cart { result.Result = RulesResult.Success; return(result); } //cart.CurrentItems[0] contains the current item being added //because the provider only adds one at a time, we just need to return a single error, but aggregate to the cart errors for the UI if (APFDueProvider.IsAPFSku(cart.CurrentItems[0].SKU)) { if (APFDueProvider.CanRemoveAPF(distributorId, Locale, level)) { if (APFDueProvider.IsAPFSku(cart.CurrentItems[0].SKU)) { var originaItem = (from c in cart.CartItems where c.SKU == cart.CurrentItems[0].SKU select c).ToList(); int previousQuantity = 0; if (null != originaItem && originaItem.Count > 0) { previousQuantity = originaItem[0].Quantity; } if (APFDueProvider.IsAPFDueAndNotPaid(distributorId, Locale)) { int requiredQuantity = APFDueProvider.APFQuantityDue(distributorId, Locale); if (cart.CurrentItems[0].Quantity + previousQuantity <= requiredQuantity) { if (level == "SP") { cart.CurrentItems[0].Quantity = requiredQuantity - previousQuantity; result.Result = RulesResult.Recalc; result.AddMessage( HttpContext.GetGlobalResourceObject( string.Format("{0}_ErrorMessage", HLConfigManager.Platform), "RequiredAPFLeftInCart") as string); var sku = APFDueProvider.GetAPFSku(); SetApfRuleResponse(result, ApfAction.None, sku, "ApfRule", TypeOfApf.CantDSRemoveAPF, "RequiredAPFLeftInCart"); cart.RuleResults.Add(result); cart.APFEdited = false; return(result); } else { result.Result = RulesResult.Recalc; result.AddMessage(string.Empty); cart.RuleResults.Add(result); cart.APFEdited = true; return(result); } } else if (cart.CurrentItems[0].Quantity + previousQuantity > requiredQuantity) { cart.CurrentItems[0].Quantity = requiredQuantity - previousQuantity; result.Result = RulesResult.Recalc; result.AddMessage( HttpContext.GetGlobalResourceObject( string.Format("{0}_ErrorMessage", HLConfigManager.Platform), "RequiredAPFLeftInCart") as string); var sku = APFDueProvider.GetAPFSku(); SetApfRuleResponse(result, ApfAction.None, sku, "ApfRule", TypeOfApf.CantDSRemoveAPF, "RequiredAPFLeftInCart"); cart.RuleResults.Add(result); cart.APFEdited = false; return(result); } } else { if (cart.CurrentItems[0].Quantity + previousQuantity > 1) { if (APFDueProvider.CanAddAPF(distributorId)) { result.Result = RulesResult.Failure; result.AddMessage( HttpContext.GetGlobalResourceObject( string.Format("{0}_ErrorMessage", HLConfigManager.Platform), "CanOnlyPrepayOneAPF") as string); var sku = APFDueProvider.GetAPFSku(); SetApfRuleResponse(result, ApfAction.None, sku, "ApfRule", TypeOfApf.CantDSRemoveAPF, "CanOnlyPrepayOneAPF"); cart.RuleResults.Add(result); cart.APFEdited = true; return(result); } } } } } if (!APFDueProvider.CanAddAPF(distributorId)) { result.Result = RulesResult.Failure; result.AddMessage( HttpContext.GetGlobalResourceObject( string.Format("{0}_ErrorMessage", HLConfigManager.Platform), "CannotAddAPFSku") as string); var sku = APFDueProvider.GetAPFSku(); SetApfRuleResponse(result, ApfAction.None, sku, "ApfRule", TypeOfApf.CannotAddAPFSku, "CannotAddAPFSku"); cart.RuleResults.Add(result); return(result); } else { string apfSku = APFDueProvider.GetAPFSku(); if (cart.CurrentItems[0].SKU == apfSku) { cart.APFEdited = true; } else { result.Result = RulesResult.Failure; result.AddMessage( HttpContext.GetGlobalResourceObject( string.Format("{0}_ErrorMessage", HLConfigManager.Platform), "SkuNotValid") as string); var sku = APFDueProvider.GetAPFSku(); SetApfRuleResponse(result, ApfAction.None, sku, "ApfRule", TypeOfApf.CannotAddAPFSku, "SkuNotValid"); cart.RuleResults.Add(result); return(result); } } } if (APFDueProvider.IsAPFSkuPresent(cart.CartItems)) { var currentSession = SessionInfo.GetSessionInfo(cart.DistributorID, cart.Locale); if ((!APFDueProvider.CanEditAPFOrder(cart.DistributorID, Thread.CurrentThread.CurrentCulture.Name, level)) || (currentSession.IsAPFOrderFromPopUp)) { result.Result = RulesResult.Failure; result.AddMessage( HttpContext.GetGlobalResourceObject( string.Format("{0}_ErrorMessage", HLConfigManager.Platform), "CompleteAPFPurchase") as string); var sku = APFDueProvider.GetAPFSku(); SetApfRuleResponse(result, ApfAction.None, sku, "ApfRule", TypeOfApf.StandaloneAPFOnlyAllowed, "CompleteAPFPurchase"); cart.RuleResults.Add(result); return(result); } else { if (APFDueProvider.containsOnlyAPFSku(cart.CartItems)) { CatalogItem item = CatalogProvider.GetCatalogItem(cart.CurrentItems[0].SKU, Country); if (null != item) { if (!HLConfigManager.Configurations.APFConfiguration.AllowNonProductItemsWithStandaloneAPF) { if (item.ProductType != ProductType.Product) { result.Result = RulesResult.Failure; result.AddMessage( HttpContext.GetGlobalResourceObject( string.Format("{0}_ErrorMessage", HLConfigManager.Platform), "NoNonProductToStandaloneAPF") as string); var sku = APFDueProvider.GetAPFSku(); SetApfRuleResponse(result, ApfAction.None, sku, "ApfRule", TypeOfApf.AllowNonProductItemsWithStandaloneAPF, "NoNonProductToStandaloneAPF"); cart.RuleResults.Add(result); return(result); } } if (item.SKU == HLConfigManager.Configurations.DOConfiguration.TodayMagazineSku || item.SKU == HLConfigManager.Configurations.DOConfiguration.TodayMagazineSecondarySku) { result.Result = RulesResult.Failure; result.AddMessage( HttpContext.GetGlobalResourceObject( string.Format("{0}_ErrorMessage", HLConfigManager.Platform), "NoTodayMagazineWithStandalonAPF") as string); var sku = APFDueProvider.GetAPFSku(); SetApfRuleResponse(result, ApfAction.None, sku, "ApfRule", TypeOfApf.StandaloneAPFOnlyAllowed, "NoTodayMagazineWithStandalonAPF"); cart.RuleResults.Add(result); return(result); } //To the standalone APF, DS trying to add product then change the Freight code & warehouse code. else if (item.ProductType == ProductType.Product || item.ProductType == ProductType.Literature || item.ProductType == ProductType.PromoAccessory) { SetNonStandAloneAPFDeliveryOption(cart as MyHLShoppingCart); } } } } } //Can add if (APFDueProvider.IsAPFSku(cart.CurrentItems[0].SKU)) { if (cart.CurrentItems[0].Quantity < 0) { var originaItem = (from c in cart.CartItems where c.SKU == cart.CurrentItems[0].SKU select c).ToList(); int previousQuantity = originaItem[0].Quantity; if (APFDueProvider.IsAPFDueAndNotPaid(distributorId, Locale)) { int requiredQuantity = APFDueProvider.APFQuantityDue(distributorId, Locale); if (level == "SP" || !HLConfigManager.Configurations.APFConfiguration.AllowDSRemoveAPFWhenDue) { if (cart.CurrentItems[0].Quantity + previousQuantity < requiredQuantity) { cart.CurrentItems[0].Quantity = (previousQuantity - requiredQuantity) * -1; result.Result = RulesResult.Recalc; result.AddMessage( HttpContext.GetGlobalResourceObject( string.Format("{0}_ErrorMessage", HLConfigManager.Platform), "RequiredAPFLeftInCart") as string); var sku = APFDueProvider.GetAPFSku(); SetApfRuleResponse(result, ApfAction.None, sku, "ApfRule", TypeOfApf.StandaloneAPFOnlyAllowed, "RequiredAPFLeftInCart"); cart.RuleResults.Add(result); cart.APFEdited = false; return(result); } } } } } return(result); }