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

Implement convert_from_currency and convet_to_currency functions

parent c7a0983f
No related branches found
No related tags found
No related merge requests found
...@@ -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."
......
...@@ -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;
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment