private ShoppingCartRuleResult PerformRules(ShoppingCart_V02 cart, ShoppingCartRuleReason reason, ShoppingCartRuleResult result) { if (reason == ShoppingCartRuleReason.CartItemsBeingAdded && cart.CartItems != null) { DefineRuleSkus(); // Check for isolated skus var isolated = cart.CartItems.FirstOrDefault(i => IsolatedSkus.Contains(i.SKU)); string error = string.Empty; if (isolated != null && !isolated.SKU.Equals(cart.CurrentItems[0].SKU)) { error = string.Format(HttpContext.GetGlobalResourceObject(string.Format("{0}_Rules", HLConfigManager.Platform), "StandaloneSku").ToString(), isolated.SKU); result.Result = RulesResult.Failure; if (!cart.RuleResults.Exists(r => r.Messages != null ? r.Messages.Any(m => m.Equals(error)) : false)) { result.AddMessage(error); cart.RuleResults.Add(result); } return(result); } if (cart.CartItems.Any() && cart.CartItems.Select(s => s.SKU).Except(IsolatedSkus.Select(i => i)).Count() > 0 && IsolatedSkus.Contains(cart.CurrentItems[0].SKU)) { error = string.Format(HttpContext.GetGlobalResourceObject(string.Format("{0}_Rules", HLConfigManager.Platform), "StandaloneSku").ToString(), cart.CurrentItems[0].SKU); result.Result = RulesResult.Failure; if (!cart.RuleResults.Exists(r => r.Messages != null ? r.Messages.Any(m => m.Equals(error)) : false)) { result.AddMessage(error); cart.RuleResults.Add(result); } return(result); } // Check for not combinable skus if ((cart.CartItems.Any(i => StandaloneSkus.Contains(i.SKU)) && !StandaloneSkus.Contains(cart.CurrentItems[0].SKU)) || (cart.CartItems.Any(i => !StandaloneSkus.Contains(i.SKU)) && StandaloneSkus.Contains(cart.CurrentItems[0].SKU))) { error = HttpContext.GetGlobalResourceObject(string.Format("{0}_Rules", HLConfigManager.Platform), "StandaloneSkus").ToString(); result.Result = RulesResult.Failure; if (!cart.RuleResults.Exists(r => r.Messages != null ? r.Messages.Any(m => m.Equals(error)) : false)) { result.AddMessage(error); cart.RuleResults.Add(result); } return(result); } } return(result); }
protected override ShoppingCartRuleResult PerformRules(MyHLShoppingCart cart, ShoppingCartRuleReason reason, ShoppingCartRuleResult Result) { Result.Result = RulesResult.Success; if (null == cart) { LoggerHelper.Error( string.Format("{0} cart is null {1}, MyHerbalife3.Ordering.Rules.PurchaseRestriction.HR.PurchaseRestrictionRules.", Locale, cart.DistributorID)); Result.Result = RulesResult.Failure; return(Result); } DateTime currentLocalDatetime = HL.Common.Utilities.DateUtils.ConvertToLocalDateTime(DateTime.Now, Country); if (currentLocalDatetime.Subtract(DistributorOrderingProfileProvider.GetProfile(cart.DistributorID, Country).ApplicationDate).TotalHours < 24) { Result.Result = RulesResult.Failure; Result.AddMessage( HttpContext.GetGlobalResourceObject( string.Format("{0}_Rules", HLConfigManager.Platform), "CroatiaNewMemberError").ToString()); cart.RuleResults.Add(Result); cart.ItemsBeingAdded.Clear(); return(Result); } List <TaxIdentification> tins = DistributorOrderingProfileProvider.GetTinList(cart.DistributorID, true); if (tins != null && tins.Find(t => t.IDType.Key == "OBRT") != null) { ///Poštovani - ukoliko imate registriran OBRT, možete platisa sa vašom Business karticom ili vašom osobnom kreditnom karticom ukoliko kupnja ne prelazi 5000 HRK. U slučaju da plaćate bankovnim transferom možete platiti sa vašeg Business transakcijskog računa vezanog uz vaš Obrt ili sa vašeg osobnog računa ukoliko kupnja ne prelazi 5000 HRK Result.Result = RulesResult.Failure; Result.AddMessage( string.Format( HttpContext.GetGlobalResourceObject( string.Format("{0}_Rules", HLConfigManager.Platform), "Croatia_SpecialMessage").ToString())); cart.RuleResults.Add(Result); } if (reason == ShoppingCartRuleReason.CartItemsBeingAdded && cart.ItemsBeingAdded != null && cart.ItemsBeingAdded.Count > 0) { DefineRuleSkus(); // Check for isolated skus been added var isolated = cart.ItemsBeingAdded.FirstOrDefault(i => IsolatedSkus.Contains(i.SKU)); if (isolated != null && cart.ItemsBeingAdded.Select(s => s.SKU).Except(IsolatedSkus.Select(i => i)).Count() > 0) { Result.Result = RulesResult.Failure; Result.AddMessage( string.Format( HttpContext.GetGlobalResourceObject(string.Format("{0}_Rules", HLConfigManager.Platform), "StandaloneSku").ToString(), string.Join(" ", IsolatedSkus.ToArray()))); cart.RuleResults.Add(Result); cart.ItemsBeingAdded.Clear(); return(Result); } // Check for isolated skus against skus in cart if (isolated != null && cart.CartItems.Any() && cart.CartItems.Where(s => s.SKU != isolated.SKU).Count() > 0) { Result.Result = RulesResult.Failure; Result.AddMessage( string.Format( HttpContext.GetGlobalResourceObject(string.Format("{0}_Rules", HLConfigManager.Platform), "StandaloneSku").ToString(), string.Join(" ", IsolatedSkus.ToArray()))); cart.RuleResults.Add(Result); cart.ItemsBeingAdded.Clear(); return(Result); } // Check for not combinable skus if ((cart.ItemsBeingAdded.Any(i => StandaloneSkus.Contains(i.SKU)) && cart.ItemsBeingAdded.Select(s => s.SKU).Except(StandaloneSkus.Select(i => i)).Count() > 0) || (cart.CartItems.Any(i => StandaloneSkus.Contains(i.SKU)) && !cart.ItemsBeingAdded.Any(i => StandaloneSkus.Contains(i.SKU))) || (cart.CartItems.Any(i => !StandaloneSkus.Contains(i.SKU)) && cart.ItemsBeingAdded.Any(i => StandaloneSkus.Contains(i.SKU)))) { Result.Result = RulesResult.Failure; Result.AddMessage( string.Format( HttpContext.GetGlobalResourceObject(string.Format("{0}_Rules", HLConfigManager.Platform), "StandaloneSkus").ToString())); cart.RuleResults.Add(Result); cart.ItemsBeingAdded.Clear(); return(Result); } } base.PerformRules(cart, reason, Result); return(Result); }