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