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

Fix custom function calls (merged fixed from VirtueMart's copy)

parent 016f92ea
Branches
Tags
No related merge requests found
......@@ -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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment