Example #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));
        }
Example #2
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 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));
        }
Example #3
0
        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"));
        }