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

Fix custom function definitions and their calls in the plugin

parent bb821b8e
No related branches found
No related tags found
No related merge requests found
...@@ -167,6 +167,10 @@ class RulesShippingFramework { ...@@ -167,6 +167,10 @@ class RulesShippingFramework {
return array (); return array ();
} }
function getCustomFunctionDefinitions() {
return $this->custom_functions;
}
/** @tag system-specific /** @tag system-specific
* @function printWarning() * @function printWarning()
* Print a warning in the system-specific way. * Print a warning in the system-specific way.
...@@ -203,22 +207,14 @@ class RulesShippingFramework { ...@@ -203,22 +207,14 @@ class RulesShippingFramework {
*/ */
public function setup() { public function setup() {
$custfuncdefs = $this->getCustomFunctions(); $custfuncdefs = $this->getCustomFunctions();
// Loop through the return values of all plugins: // Now loop through all custom function definitions of this plugin
foreach ($custfuncdefs as $custfuncs) { // If a function was registered before, print a warning and use the first definition
if (empty($custfuncs)) foreach ($custfuncdefs as $fname => $func) {
continue; if (isset($this->custom_functions[$fname]) && $this->custom_functions[$fname]!=$custfuncs[$fname]) {
if (!is_array($custfuncs)) { $this->warning('OTSHIPMENT_RULES_CUSTOMFUNCTIONS_ALREADY_DEFINED', $fname);
$this->warning('OTSHIPMENT_RULES_CUSTOMFUNCTIONS_NOARRAY'); } else {
} $this->debug("Defining custom function $fname");
// Now loop through all custom function definitions of this plugin $this->custom_functions[strtolower($fname)] = $func;
// 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;
}
} }
} }
} }
...@@ -831,9 +827,10 @@ class ShippingRule { ...@@ -831,9 +827,10 @@ class ShippingRule {
$func = strtolower($function); $func = strtolower($function);
// Check if we have a custom function definition and use that if so. // 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! // 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"); $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: // 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