Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Shipping by Rules for VirtueMart
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VirtueMart
Shipping by Rules for VirtueMart
Commits
92d8fcad
Commit
92d8fcad
authored
9 years ago
by
Reinhold Kainhofer
Browse files
Options
Downloads
Patches
Plain Diff
Implement convert_from_currency and convet_to_currency functions
parent
c7a0983f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
language/en-GB/en-GB.plg_vmshipment_rules_shipping.ini
+1
-0
1 addition, 0 deletions
language/en-GB/en-GB.plg_vmshipment_rules_shipping.ini
rules_shipping_framework_joomla.php
+44
-0
44 additions, 0 deletions
rules_shipping_framework_joomla.php
with
45 additions
and
0 deletions
language/en-GB/en-GB.plg_vmshipment_rules_shipping.ini
+
1
−
0
View file @
92d8fcad
...
@@ -63,6 +63,7 @@ OTSHIPMENT_RULES_NOSHIPPING_MESSAGE="%s"
...
@@ -63,6 +63,7 @@ OTSHIPMENT_RULES_NOSHIPPING_MESSAGE="%s"
OTSHIPMENT_RULES_UNKNOWN_TYPE
=
"Unknown rule type '%s' encountered for rule '%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_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."
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."
OTSHIPMENT_RULES_CUSTOMFUNCTIONS_ALREADY_DEFINED
=
"Custom function %s already defined. Ignoring this definition and using previous one."
...
...
This diff is collapsed.
Click to expand it.
rules_shipping_framework_joomla.php
+
44
−
0
View file @
92d8fcad
...
@@ -38,6 +38,8 @@ class RulesShippingFrameworkJoomla extends RulesShippingFramework {
...
@@ -38,6 +38,8 @@ class RulesShippingFrameworkJoomla extends RulesShippingFramework {
JPluginHelper
::
importPlugin
(
'vmshipmentrules'
);
JPluginHelper
::
importPlugin
(
'vmshipmentrules'
);
$dispatcher
=
JDispatcher
::
getInstance
();
$dispatcher
=
JDispatcher
::
getInstance
();
$custfuncdefs
=
$dispatcher
->
trigger
(
'onVmShippingRulesRegisterCustomFunctions'
,
array
());
$custfuncdefs
=
$dispatcher
->
trigger
(
'onVmShippingRulesRegisterCustomFunctions'
,
array
());
$custfuncdefs
[
'convertfromcurrency'
]
=
array
(
$this
,
'convert_from_currency'
);
$custfuncdefs
[
'converttocurrency'
]
=
array
(
$this
,
'convert_to_currency'
);
return
$custfuncdefs
;
return
$custfuncdefs
;
}
}
...
@@ -391,4 +393,46 @@ class RulesShippingFrameworkJoomla extends RulesShippingFramework {
...
@@ -391,4 +393,46 @@ class RulesShippingFrameworkJoomla extends RulesShippingFramework {
return
$result
;
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
;
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment