Пример #1
0
        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));
        }
Пример #2
0
        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));
        }
Пример #3
0
        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));
        }
Пример #4
0
        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 reason = new PromotionValidationResultReason("Promotion.Reason.MinimumOrders.InsufficientQuantity");

            reason.ContextItems.Add("OrderQuantityDelta", MinimumOrdersAllowed - dataLookupResult.Int32Result);
            reason.ContextItems.Add("PromotionEndDate", this.CustomEndDate.ToShortDateString());

            return(new SimplePromotionValidationResult(dataLookupResult.Int32Result >= MinimumOrdersAllowed, reason));
        }