Ejemplo n.º 1
0
        public bool RuleMatches(RuleExpression[] expressions, LogicalRuleOperator logicalOperator)
        {
            Guard.NotNull(expressions, nameof(expressions));

            if (expressions.Length == 0)
            {
                return(true);
            }

            RuleExpressionGroup group;

            if (expressions.Length == 1 && expressions[0] is RuleExpressionGroup group2)
            {
                group = group2;
            }
            else
            {
                group = new RuleExpressionGroup {
                    LogicalOperator = logicalOperator
                };
                group.AddExpressions(expressions);
            }

            var context = new CartRuleContext
            {
                Customer    = _services.WorkContext.CurrentCustomer,
                Store       = _services.StoreContext.CurrentStore,
                WorkContext = _services.WorkContext
            };

            var processor = GetProcessor(group);

            return(processor.Match(context, group));
        }
Ejemplo n.º 2
0
        public async Task <bool> RuleMatchesAsync(RuleExpression[] expressions, LogicalRuleOperator logicalOperator)
        {
            Guard.NotNull(expressions, nameof(expressions));

            if (expressions.Length == 0)
            {
                return(true);
            }

            RuleExpressionGroup group;

            if (expressions.Length == 1 && expressions[0] is RuleExpressionGroup group2)
            {
                group = group2;
            }
            else
            {
                group = new RuleExpressionGroup {
                    LogicalOperator = logicalOperator
                };
                group.AddExpressions(expressions);
            }

            var context = new CartRuleContext(() => group.GetHashCode())
            {
                Customer    = _workContext.CurrentCustomer,
                Store       = _storeContext.CurrentStore,
                WorkContext = _workContext
            };

            var processor = GetProcessor(group);
            var result    = await processor.MatchAsync(context, group);

            return(result);
        }