public override IPromotionValidationResult Validate(IPromotionController promotionController, IRuleContext ruleContext) { if (!ruleContext.IsRegistered) { return(new SimplePromotionValidationResult(false, "Promotion.Reason.MinimumProductAmountOrdered.NotLoggedIn")); } IDataLookupResult dataLookupResult = promotionController.LookupData(new SimpleDataLookupContext() { LookupType = LookupType.TotalProductOrderedAmount, CustomerId = ruleContext.CustomerId, Skus = this.Skus, ProductIds = this.ProductIds, StartDateType = this.StartDateType, EndDateType = this.EndDateType, CustomStartDate = this.CustomStartDate, CustomEndDate = this.CustomEndDate, }); var reason = new PromotionValidationResultReason("Promotion.Reason.MinimumProductAmountOrdered.InsufficientAmount"); reason.ContextItems.Add("OrderAmountDelta", String.Format("{0:C2}", MinimumProductAmountOrderedAllowed - dataLookupResult.DecimalResult)); reason.ContextItems.Add("PromotionEndDate", this.CustomEndDate.ToShortDateString()); reason.ContextItems.Add("ProductNames", dataLookupResult.StringResult); return(new SimplePromotionValidationResult(dataLookupResult.DecimalResult >= MinimumProductAmountOrderedAllowed, reason)); }
public override IPromotionValidationResult Validate(IPromotionController promotionController, IRuleContext ruleContext) { if (!ruleContext.IsRegistered) { return(new SimplePromotionValidationResult(false, "Promotion.Reason.MinimumOrders.NotLoggedIn")); } IDataLookupResult dataLookupResult = promotionController.LookupData(new SimpleDataLookupContext() { CustomerId = ruleContext.CustomerId, LookupType = LookupType.TotalOrders, StartDateType = this.StartDateType, EndDateType = this.EndDateType, CustomStartDate = this.CustomStartDate, CustomEndDate = this.CustomEndDate, }); var orderQuantityDelta = MinimumOrdersAllowed - dataLookupResult.Int32Result; var reason = orderQuantityDelta == 1 ? new PromotionValidationResultReason("Promotion.Reason.MinimumOrders.InsufficientQuantitySingular") : new PromotionValidationResultReason("Promotion.Reason.MinimumOrders.InsufficientQuantityPlural"); reason.ContextItems.Add("OrderQuantityDelta", orderQuantityDelta); reason.ContextItems.Add("PromotionEndDate", this.CustomEndDate.ToShortDateString()); return(new SimplePromotionValidationResult(dataLookupResult.Int32Result >= MinimumOrdersAllowed, reason)); }
public override IPromotionValidationResult Validate(IPromotionController promotionController, IRuleContext ruleContext) { if (ruleContext.MultiShipEnabled) { return(new SimplePromotionValidationResult(false, "Promotion.Reason.Shipping.MultishipEnabled")); } return(new SimplePromotionValidationResult(true)); }
public override IPromotionValidationResult Validate(IPromotionController promotionController, IRuleContext ruleContext) { if (!ruleContext.IsRegistered) { return(new SimplePromotionValidationResult(false, "Promotion.Reason.Country.NotLoggedIn")); } return(new SimplePromotionValidationResult(this.CountryCodes.Any(c => c.ToUpperInvariant() == ruleContext.CountryCode.ToUpperInvariant()), "Promotion.Reason.Country.NoMatch")); }
public override IPromotionValidationResult Validate(IPromotionController promotionController, IRuleContext ruleContext) { if (!String.IsNullOrEmpty(ruleContext.State) && ruleContext.ExcludeStates != null && ruleContext.ExcludeStates.Contains(ruleContext.State)) { return(new SimplePromotionValidationResult(false, "Promotion.Reason.State.NoMatch")); } return(new SimplePromotionValidationResult(true)); }
public override IPromotionValidationResult Validate(IPromotionController promotionController, IRuleContext ruleContext) { if (!ruleContext.IsRegistered) { return(new SimplePromotionValidationResult(false, "Promotion.Reason.CustomerLevel.NotLoggedIn")); } return(new SimplePromotionValidationResult(this.CustomerLevels.Any(cl => cl == ruleContext.CustomerLevel), "Promotion.Reason.CustomerLevel.NoMatch")); }
public override IPromotionValidationResult Validate(IPromotionController promotionController, IRuleContext ruleContext) { if (!ruleContext.IsRegistered) { return(new SimplePromotionValidationResult(false, "Promotion.Reason.ZipCode.NotLoggedIn")); } return(new SimplePromotionValidationResult(this.ZipCodes.Any(z => ruleContext.ZipCode.StartsWith(z)), "Promotion.Reason.ZipCode.NoMatch")); }
public override IPromotionValidationResult Validate(IPromotionController promotionController, IRuleContext ruleContext) { decimal cartSubTotal = ruleContext.ShoppingCartItems.Any() ? ruleContext.ShoppingCartItems.Sum(sci => sci.Subtotal) : 0.0M; var reason = new PromotionValidationResultReason("Promotion.Reason.MinimumCartAmount.InsufficientAmount"); reason.ContextItems.Add("CartAmountDelta", String.Format("{0:C2}", CartAmount - cartSubTotal)); return(new SimplePromotionValidationResult(cartSubTotal >= CartAmount, reason)); }
public override IPromotionValidationResult Validate(IPromotionController promotionController, IRuleContext ruleContext) { IDataLookupResult dataLookupResult = promotionController.LookupData(new SimpleDataLookupContext() { PromotionId = ruleContext.PromotionId, LookupType = LookupType.TotalPromotionUses, }); return(new SimplePromotionValidationResult(dataLookupResult.Int32Result < NumberOfUsesAllowed, "Promotion.Reason.ExpirationNumberOfUses")); }
public override IPromotionValidationResult Validate(IPromotionController promotionController, IRuleContext ruleContext) { if (this.AndTogether) { // validate all in list are in cart foreach (Int32 productId in ProductIds) { if (!ruleContext.ShoppingCartItems.Select(s => s.ProductId).Contains(productId)) { return(new SimplePromotionValidationResult(false, "Promotion.Reason.ProductId.NoMatch")); } } } else { if (!ruleContext.ShoppingCartItems.Where(w => ProductIds.Contains(w.ProductId)).Any()) { return(new SimplePromotionValidationResult(false, "Promotion.Reason.ProductId.NoMatch")); } } if (RequireQuantity) { var requiredProductsInCart = ruleContext.ShoppingCartItems .Where(w => ProductIds.Contains(w.ProductId)) .Select(item => new { CartItem = item, SufficientQuantity = item.Quantity >= Quantity, }); var sufficientQuantityItems = requiredProductsInCart .Where(o => o.SufficientQuantity) .Select(o => o.CartItem); var insufficientQuantityItems = requiredProductsInCart .Where(o => !o.SufficientQuantity) .Select(o => o.CartItem); if (!sufficientQuantityItems.Any() || (this.AndTogether && insufficientQuantityItems.Any())) { var reason = new PromotionValidationResultReason("Promotion.Reason.ProductId.InsufficientQuantity"); reason.ContextItems.Add("ProductName", insufficientQuantityItems.First().Name); reason.ContextItems.Add("QuantityDelta", Quantity - insufficientQuantityItems.First().Quantity); return(new SimplePromotionValidationResult(false, reason)); } } return(new SimplePromotionValidationResult(true)); }
public override IPromotionValidationResult Validate(IPromotionController promotionController, IRuleContext ruleContext) { if (this.ManufacturerIds == null) { return(new SimplePromotionValidationResult(false, "Promotion.Reason.Manufacturer.InvalidRuleDefined")); } foreach (ShoppingCartItem item in ruleContext.ShoppingCartItems) { if (this.ManufacturerIds.Intersect(item.ManufacturerIds).Any()) { return(new SimplePromotionValidationResult(true)); } } return(new SimplePromotionValidationResult(false, "Promotion.Reason.Manufacturer.NoMatch")); }
public override IPromotionValidationResult Validate(IPromotionController promotionController, IRuleContext ruleContext) { return(new SimplePromotionValidationResult(EmailAddresses.Any(ea => ea.ToUpperInvariant() == ruleContext.EmailAddress.ToUpperInvariant()), "Promotion.Reason.EmailAddress.NoMatch")); }
public IDiscountResult ApplyPromotion(IPromotionUsage promotionUsage, IRuleContext ruleContext, IDiscountContext discountContext, Func <IDiscountResult> resultFactory, IPromotionController promotionController) { if (!ValidatePromotion(promotionUsage.Promotion, ruleContext, true).All(vr => vr.IsValid)) { return(null); } IDiscountResult retVal = resultFactory(); retVal.Promotion = promotionUsage.Promotion; List <DiscountedItem> discountedItems = new List <DiscountedItem>(); foreach (IPromotionDiscount promotionDiscount in promotionUsage.Promotion.PromotionDiscounts) { IDiscountResult result = promotionDiscount.ApplyPromotion(promotionUsage, ruleContext, discountContext, resultFactory); if (result.DiscountedItems != null) { discountedItems.AddRange(result.DiscountedItems); } retVal.LineItemTotal += result.LineItemTotal; retVal.ShippingTotal += result.ShippingTotal; retVal.OrderTotal += result.OrderTotal; retVal.GiftProductTotal += result.GiftProductTotal; } retVal.DiscountedItems = discountedItems; return(retVal); }
public override IPromotionValidationResult Validate(IPromotionController promotionController, IRuleContext ruleContext) { //If this gets implemented we will have to figure out how to filter out gift items from the total //return ruleContext.CartTotal >= MinimumCartTotalAllowed; throw new NotImplementedException(); }
public override IPromotionValidationResult Validate(IPromotionController promotionController, IRuleContext ruleContext) { return(new SimplePromotionValidationResult(true)); }
public override IPromotionValidationResult Validate(IPromotionController promotionController, IRuleContext ruleContext) { return(new SimplePromotionValidationResult(DateTime.Now < ExpirationDate, "Promotion.Reason.ExpirationDate")); }
public abstract IPromotionValidationResult Validate(IPromotionController promotionController, IRuleContext ruleContext);