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
92d8fcad
Commit
92d8fcad
authored
Feb 07, 2016
by
Reinhold Kainhofer
Browse files
Implement convert_from_currency and convet_to_currency functions
parent
c7a0983f
Changes
2
Hide whitespace changes
Inline
Side-by-side
language/en-GB/en-GB.plg_vmshipment_rules_shipping.ini
View file @
92d8fcad
...
...
@@ -63,6 +63,7 @@ OTSHIPMENT_RULES_NOSHIPPING_MESSAGE="%s"
OTSHIPMENT_RULES_UNKNOWN_TYPE
=
"Unknown rule type '%s' encountered for rule '%s'"
OTSHIPMENT_RULES_SCOPING_UNKNOWN="Unknown scoping function 'evaluate_for_%s' encountered in rule '%s'"
OTSHIPMENT_RULES_CURRENCY_CONVERSION_FAILED
=
"Unable to find currency '%s' used in rule '%s'"
ORSHIPMENT_RULES_CUSTOMFUNCTIONS_NOARRAY="Definition of custom functions (returned by a vmshipmentrules plugin) is not a proper array. Ignoring."
OTSHIPMENT_RULES_CUSTOMFUNCTIONS_ALREADY_DEFINED
=
"Custom function %s already defined. Ignoring this definition and using previous one."
...
...
rules_shipping_framework_joomla.php
View file @
92d8fcad
...
...
@@ -38,6 +38,8 @@ class RulesShippingFrameworkJoomla extends RulesShippingFramework {
JPluginHelper
::
importPlugin
(
'vmshipmentrules'
);
$dispatcher
=
JDispatcher
::
getInstance
();
$custfuncdefs
=
$dispatcher
->
trigger
(
'onVmShippingRulesRegisterCustomFunctions'
,
array
());
$custfuncdefs
[
'convertfromcurrency'
]
=
array
(
$this
,
'convert_from_currency'
);
$custfuncdefs
[
'converttocurrency'
]
=
array
(
$this
,
'convert_to_currency'
);
return
$custfuncdefs
;
}
...
...
@@ -391,4 +393,46 @@ class RulesShippingFrameworkJoomla extends RulesShippingFramework {
return
$result
;
}
/** Currency conversion function
*/
protected
function
getCurrencyDisplay
(
$curr
)
{
if
(
!
class_exists
(
'ShopFunctions'
))
require
(
VMPATH_ADMIN
.
'/'
.
'helpers'
.
'/'
.
'shopfunctions.php'
);
if
(
is_string
(
$curr
))
{
$currID
=
ShopFunctions
::
getCurrencyIDByName
(
$curr
);
}
elseif
(
is_numeric
(
$curr
))
{
$currID
=
$curr
;
}
else
{
$this
->
printWarning
(
JText
::
sprintf
(
'OTSHIPMENT_RULES_CURRENCY_CONVERSION_FAILED'
,
$curr
,
$rule
->
rulestring
));
$currID
=
0
;
}
return
CurrencyDisplay
::
getInstance
(
$currID
);
}
public
function
convert_from_currency
(
$args
,
$rule
)
{
$value
=
$args
[
0
];
$curr
=
$args
[
1
];
$currency
=
$this
->
getCurrencyDisplay
(
$curr
);
if
(
$currency
)
{
return
$currency
->
convertCurrencyTo
(
$curr
,
$value
,
TRUE
);
}
else
{
$this
->
printWarning
(
JText
::
sprintf
(
'OTSHIPMENT_RULES_CURRENCY_CONVERSION_FAILED'
,
$curr
,
$rule
->
rulestring
));
return
0
;
}
}
public
function
convert_to_currency
(
$args
,
$rule
)
{
$value
=
$args
[
0
];
$curr
=
$args
[
1
];
$currency
=
$this
->
getCurrencyDisplay
(
$curr
);
if
(
$currency
)
{
return
$currency
->
convertCurrencyTo
(
$curr
,
$value
,
FALSE
);
}
else
{
$this
->
printWarning
(
JText
::
sprintf
(
'OTSHIPMENT_RULES_CURRENCY_CONVERSION_FAILED'
,
$curr
,
$rule
->
rulestring
));
return
0
;
}
}
}
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