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); }
public async Task <bool> MatchAsync(CartRuleContext context, RuleExpression expression) { var match = false; foreach (var expr in _group.Expressions.Cast <RuleExpression>()) { if (expr.Descriptor is not CartRuleDescriptor descriptor) { continue; } var processor = _cartRuleProvider.GetProcessor(expr); match = await processor.MatchAsync(context, expr); if (!match && _group.LogicalOperator == LogicalRuleOperator.And) { break; } if (match && _group.LogicalOperator == LogicalRuleOperator.Or) { break; } } return(match); }