diff --git a/rules_shipping_base.php b/rules_shipping_base.php index 5811056b22669ed39d037aa223af31b311c34a37..819bc9ce31d5664db217291e37b661eeb213ffc2 100644 --- a/rules_shipping_base.php +++ b/rules_shipping_base.php @@ -1113,7 +1113,31 @@ class ShippingRule { } } - function evaluateFunction ($function, $args) { + /** Evaluate the given expression $expr only for the products that match the filter given by the scoping + * function and the corresponding conditions */ + protected function evaluateScoping($expr, $scoping, $conditionvals, $vals) { + if (count($conditions)<1) + return $this->evaluateTerm($expr, $vals); + + $filterkeys = array( + "evaluate_for_categories" => 'categories', + "evaluate_for_products" => 'products', + "evaluate_for_vendors" => 'vendors', + "evaluate_for_manufacturers" => 'manufacturers' + ); + + $conditions = array(); + if (isset($filterkeys[$scoping])) + $conditions[$filterkeys[$scoping]] = $conditionsvals; + + // Pass the conditions to the parent plugin class to filter the current list of products: + $products = filterProducts($currentproducts, $conditions); + $vals = $this->plugin->getCartValues ($cart, $products, /* FIXME: method*/ $this->method, $cart_prices); + // FIXME: IMPLEMENT + // TODO + } + + protected function evaluateFunction ($function, $args) { $func = strtolower($function); // Check if we have a custom function definition and use that if so. // This is done first to allow plugins to override even built-in functions! @@ -1225,6 +1249,13 @@ class ShippingRule { } else { return $this->evaluateVariable($expr, $vals); } + } elseif ($is_scoping) { + $op = array_shift($expr); // ignore the "FUNCTION" + $func = array_shift($expr); // The scoping function name + $expression = array_shift($expr); // The expression to be evaluated + $conditions = $expr; // the remaining $expr list now contains the conditions + return $this->evaluateScoping ($expression, $func, $conditions, $vals); + } elseif (is_array($expr)) { // Operator $op = array_shift($expr);