public bool Evaluate(IRuleExecutionContext context)
        {
            var commerceContext = context.Fact <CommerceContext>();

            //Get configuration
            string  specificCategory     = Hc_SpecificCategory.Yield(context);
            decimal specificValue        = Hc_SpecificValue.Yield(context);
            bool    includeSubCategories = Hc_IncludeSubCategories.Yield(context);

            if (string.IsNullOrEmpty(specificCategory) || specificValue == 0 || Hc_Compares == null)
            {
                return(false);
            }

            //Get data
            IEnumerable <CartLineComponent> categoryLines =
                categoryCartLinesResolver.Resolve(commerceContext, specificCategory, includeSubCategories);

            if (categoryLines == null)
            {
                return(false);
            }

            //Validate data against configuration
            decimal categoryTotal = categoryLines.Sum(line => line.Totals.GrandTotal.Amount);

            return(Hc_Compares.Evaluate(categoryTotal, specificValue));
        }
Esempio n. 2
0
        public bool Evaluate(IRuleExecutionContext context)
        {
            //Get configuration
            string  specificCategory     = Hc_SpecificCategory.Yield(context);
            decimal specificValue        = Hc_SpecificValue.Yield(context);
            bool    includeSubCategories = Hc_IncludeSubCategories.Yield(context);

            if (string.IsNullOrEmpty(specificCategory) || specificValue == 0 || Hc_Compares == null)
            {
                return(false);
            }

            //Get Data
            var commerceContext = context.Fact <CommerceContext>();
            List <CartLineComponent> categoryLines = AsyncHelper.RunSync(() =>
                                                                         categoryOrderLinesResolver.Resolve(commerceContext, specificCategory, includeSubCategories));

            if (categoryLines == null)
            {
                return(false);
            }

            //Validate data against configuration
            decimal productAmount = categoryLines.Sum(x => x.Quantity);

            return(Hc_Compares.Evaluate(productAmount, specificValue));
        }
Esempio n. 3
0
        public void Execute(IRuleExecutionContext context)
        {
            var commerceContext = context.Fact <CommerceContext>();

            //Get configuration
            string  specificCategory     = Hc_SpecificCategory.Yield(context);
            decimal specificValue        = Hc_SpecificValue.Yield(context);
            bool    includeSubCategories = Hc_IncludeSubCategories.Yield(context);
            decimal percentageOff        = Hc_PercentageOff.Yield(context);
            string  applyActionTo        = Hc_ApplyActionTo.Yield(context);
            int     actionLimit          = Hc_ActionLimit.Yield(context);

            if (string.IsNullOrEmpty(specificCategory) ||
                specificValue == 0 ||
                percentageOff == 0 ||
                string.IsNullOrEmpty(applyActionTo) ||
                actionLimit == 0 ||
                Hc_Operator == null)
            {
                return;
            }

            //Get data
            IEnumerable <CartLineComponent> categoryLines =
                categoryCartLinesResolver.Resolve(commerceContext, specificCategory, includeSubCategories);

            if (categoryLines == null)
            {
                return;
            }

            //Validate and apply action
            decimal productAmount = categoryLines.Sum(x => x.Quantity);

            if (!Hc_Operator.Evaluate(productAmount, specificValue))
            {
                return;
            }

            var discountApplicator = new DiscountApplicator(commerceContext);

            discountApplicator.ApplyPercentageDiscount(categoryLines, percentageOff, new DiscountOptions
            {
                ActionLimit      = actionLimit,
                ApplicationOrder = ApplicationOrder.Parse(applyActionTo),
                AwardingBlock    = nameof(CartItemsMatchingInCategoryPercentageDiscountAction)
            });
        }