From a485d27a26455a70625ea496846799fd1beafadf Mon Sep 17 00:00:00 2001 From: Reinhold Kainhofer <reinhold@kainhofer.com> Date: Sat, 6 Feb 2016 23:57:02 +0100 Subject: [PATCH] Fix custom function calls (merged fixed from VirtueMart's copy) --- library/rules_shipping_framework.php | 35 +++++++++++++--------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/library/rules_shipping_framework.php b/library/rules_shipping_framework.php index 1a48ec6..aa0ebb4 100644 --- a/library/rules_shipping_framework.php +++ b/library/rules_shipping_framework.php @@ -167,6 +167,10 @@ class RulesShippingFramework { return array (); } + function getCustomFunctionDefinitions() { + return $this->custom_functions; + } + /** @tag system-specific * @function printWarning() * Print a warning in the system-specific way. @@ -203,22 +207,14 @@ class RulesShippingFramework { */ public function setup() { $custfuncdefs = $this->getCustomFunctions(); - // Loop through the return values of all plugins: - foreach ($custfuncdefs as $custfuncs) { - if (empty($custfuncs)) - continue; - if (!is_array($custfuncs)) { - $this->warning('OTSHIPMENT_RULES_CUSTOMFUNCTIONS_NOARRAY'); - } - // Now loop through all custom function definitions of this plugin - // If a function was registered before, print a warning and use the first definition - foreach ($custfuncs as $fname => $func) { - if (isset($this->custom_functions[$fname])) { - $this->warning('OTSHIPMENT_RULES_CUSTOMFUNCTIONS_ALREADY_DEFINED', $fname); - } else { - $this->debug("Defining custom function $fname"); - $this->custom_functions[strtolower($fname)] = $func; - } + // Now loop through all custom function definitions of this plugin + // If a function was registered before, print a warning and use the first definition + foreach ($custfuncdefs as $fname => $func) { + if (isset($this->custom_functions[$fname]) && $this->custom_functions[$fname]!=$custfuncs[$fname]) { + $this->warning('OTSHIPMENT_RULES_CUSTOMFUNCTIONS_ALREADY_DEFINED', $fname); + } else { + $this->debug("Defining custom function $fname"); + $this->custom_functions[strtolower($fname)] = $func; } } } @@ -644,7 +640,7 @@ class ShippingRule { /* In the advanced version, all conditions and costs can be given as a full mathematical expression */ /* Both versions create an expression tree, which can be easily evaluated in evaluateTerm */ $rulepart = trim($rulepart); - if (empty($rulepart)) return; + if (!isset($rulepart) || $rulepart==='') return; // Special-case the name assignment, where we don't want to interpret the value as an arithmetic expression! @@ -831,9 +827,10 @@ class ShippingRule { $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! - if (isset($this->plugin->custom_functions[$func])) { + $customfunctions = $this->framework->getCustomFunctionDefinitions(); + if (isset($customfunctions[$func])) { $this->framework->debug("Evaluating custom function $function, defined by a plugin"); - return call_user_func_array($this->plugin->custom_functions[$func], $args, $this); + return call_user_func($customfunctions[$func], $args, $this); } // Functions with no argument: -- GitLab