Skip to content
Snippets Groups Projects
Commit 61d615a8 authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

Version 2.0: Add AND operator to the list of parsed operators

parent 12f47b48
No related branches found
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
...@@ -71,8 +71,8 @@ class ShippingRule_Advanced extends ShippingRule { ...@@ -71,8 +71,8 @@ class ShippingRule_Advanced extends ShippingRule {
"+" => 50, "-" => 50, "+" => 50, "-" => 50,
"<" => 40, "<=" => 40, ">" => 40, ">=" => 40, "=>" => 40, "=<" => 40, "<" => 40, "<=" => 40, ">" => 40, ">=" => 40, "=>" => 40, "=<" => 40,
"==" => 40, "!=" => 40, "<>" => 40, "==" => 40, "!=" => 40, "<>" => 40,
"&" => 21, "&&" => 21, " AND " => 21, "AND" => 21,
" OR " => 20, " OR " => 20, "OR" => 20,
"=" => 10, "=" => 10,
"(" => 0, ")" =>0 ); "(" => 0, ")" =>0 );
...@@ -86,7 +86,7 @@ class ShippingRule_Advanced extends ShippingRule { ...@@ -86,7 +86,7 @@ class ShippingRule_Advanced extends ShippingRule {
$str_re = '/("(?:\\"|[^"])*"|\'(?:\\\'|[^\'])*\')/'; $str_re = '/("(?:\\"|[^"])*"|\'(?:\\\'|[^\'])*\')/';
$strings = preg_split($str_re, $expression, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY); $strings = preg_split($str_re, $expression, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
// Then split all other parts of the expression at the operators // Then split all other parts of the expression at the operators
$op_re = ':\s*( OR |<=|=>|>=|=>|<>|!=|==|<|=|>|\+|-|\*|/|%|\(|\)|\^)\s*:'; $op_re = ':\s*( OR |&&| AND |<=|=>|>=|=>|<>|!=|==|<|=|>|\+|-|\*|/|%|\(|\)|\^)\s*:';
$atoms = array(); $atoms = array();
foreach ($strings as $s) { foreach ($strings as $s) {
if (preg_match($str_re, $s)) { if (preg_match($str_re, $s)) {
...@@ -155,7 +155,7 @@ class ShippingRule_Advanced extends ShippingRule { ...@@ -155,7 +155,7 @@ class ShippingRule_Advanced extends ShippingRule {
$atoms = $this->tokenize_expression ($rulepart); $atoms = $this->tokenize_expression ($rulepart);
// Any of these indicate a comparison and thus a condition: // Any of these indicate a comparison and thus a condition:
$comparison_ops = array('<', '<=', '=<', '<>', '!=', '==', '>', '>=', '=>'); $comparison_ops = array('<', '<=', '=<', '<>', '!=', '==', '>', '>=', '=>', ' OR ', 'OR', 'AND', ' AND ', '&&');
$is_comparison = false; $is_comparison = false;
$is_assignment = false; $is_assignment = false;
......
...@@ -633,6 +633,7 @@ class ShippingRule { ...@@ -633,6 +633,7 @@ class ShippingRule {
switch ($op) { switch ($op) {
case 'OR': case 'OR':
case ' OR ': foreach ($args as $a) { $res = ($res || $a); }; break; case ' OR ': foreach ($args as $a) { $res = ($res || $a); }; break;
case '&&':
case 'AND': case 'AND':
case ' AND ': $res = true; foreach ($args as $a) { $res = ($res && $a); }; break; case ' AND ': $res = true; foreach ($args as $a) { $res = ($res && $a); }; break;
case 'in': $needle = array_shift($args); $res = in_array($needle, $args); break; case 'in': $needle = array_shift($args); $res = in_array($needle, $args); break;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment