Skip to content
GitLab
About GitLab
GitLab: the DevOps platform
Explore GitLab
Install GitLab
How GitLab compares
Get started
GitLab docs
GitLab Learn
Pricing
Talk to an expert
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Projects
Groups
Snippets
Sign up now
Login
Sign in
Toggle navigation
Menu
Open sidebar
VirtueMart
Shipping by Rules for VirtueMart
Commits
422d5b50
Commit
422d5b50
authored
Nov 13, 2014
by
Reinhold Kainhofer
Browse files
Implement plugin API for custom functions
parent
42a971be
Changes
3
Hide whitespace changes
Inline
Side-by-side
language/de-DE/de-DE.plg_vmshipment_rules_shipping.ini
View file @
422d5b50
...
...
@@ -51,3 +51,6 @@ VMSHIPMENT_RULES_EVALUATE_LISTFUNCTION_CONTAIN_ARGS="List function '%s' requires
VMSHIPMENT_RULES_EVALUATE_LISTFUNCTION_UNKNOWN="Unknown list function '%s' encountered. (Full rule: '%s')"
VMSHIPMENT_RULES_NOSHIPPING_MESSAGE
=
"%s"
VMSHIPMENT_RULES_CUSTOMFUNCTIONS_NOARRAY="Definition of custom functions (returned by a vmshipmentrules plugin) is not a proper array. Ignoring."
VMSHIPMENT_RULES_CUSTOMFUNCTIONS_ALREADY_DEFINED
=
"Custom function %s already defined. Ignoring this definition and using previous one."
language/en-GB/en-GB.plg_vmshipment_rules_shipping.ini
View file @
422d5b50
...
...
@@ -59,3 +59,9 @@ VMSHIPMENT_RULES_EVALUATE_LISTFUNCTION_CONTAIN_ARGS="List function '%s' requires
VMSHIPMENT_RULES_EVALUATE_LISTFUNCTION_UNKNOWN
=
"Unknown list function '%s' encountered. (Full rule: '%s')"
VMSHIPMENT_RULES_NOSHIPPING_MESSAGE="%s"
VMSHIPMENT_RULES_UNKNOWN_TYPE
=
"Unknown rule type '%s' encountered for rule '%s'"
VMSHIPMENT_RULES_CUSTOMFUNCTIONS_NOARRAY="Definition of custom functions (returned by a vmshipmentrules plugin) is not a proper array. Ignoring."
VMSHIPMENT_RULES_CUSTOMFUNCTIONS_ALREADY_DEFINED
=
"Custom function %s already defined. Ignoring this definition and using previous one."
rules_shipping_base.php
View file @
422d5b50
...
...
@@ -64,6 +64,34 @@ class plgVmShipmentRules_Shipping_Base extends vmPSPlugin {
$this
->
tableFields
=
array_keys
(
$this
->
getTableSQLFields
());
$varsToPush
=
$this
->
getVarsToPush
();
$this
->
setConfigParameterable
(
$this
->
_configTableFieldName
,
$varsToPush
);
// PLUGIN FUNCTIONALITY:
// Let other plugins add custom functions!
// The onVmShippingRulesRegisterCustomFunctions() trigger is expected to return an array of the form:
// array ('functionname1' => 'function-to-be-called',
// 'functionname2' => array($classobject, 'memberfunc')),
// ...);
JPluginHelper
::
importPlugin
(
'vmshipmentrules'
);
$dispatcher
=
JDispatcher
::
getInstance
();
$custfuncdefs
=
$dispatcher
->
trigger
(
'onVmShippingRulesRegisterCustomFunctions'
,
array
());
// Loop through the return values of all plugins:
foreach
(
$custfuncdefs
as
$custfuncs
)
{
if
(
empty
(
$custfuncs
))
continue
;
if
(
!
is_array
(
$custfuncs
))
{
$this
->
printWarning
(
JText
::
sprintf
(
'VMSHIPMENT_RULES_CUSTOMFUNCTIONS_NOARRAY'
,
$method
->
rule_name
));
}
// 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
->
printWarning
(
JText
::
sprintf
(
'VMSHIPMENT_RULES_CUSTOMFUNCTIONS_ALREADY_DEFINED'
,
$fname
));
}
else
{
vmDebug
(
"Defining custom function
$fname
"
);
$this
->
custom_functions
[
strtolower
(
$fname
)]
=
$func
;
}
}
}
}
/**
...
...
@@ -1087,6 +1115,13 @@ class ShippingRule {
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!
if
(
isset
(
$this
->
plugin
->
custom_functions
[
$func
]))
{
vmDebug
(
"Evaluating custom function
$function
, defined by a plugin"
);
return
call_user_func
(
$this
->
plugin
->
custom_functions
[
$func
],
$args
);
}
// Functions with no argument:
if
(
count
(
$args
)
==
0
)
{
$dt
=
getdate
();
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment