From 552ba683c3d85f72551e7f912d4cf01ee71c2da6 Mon Sep 17 00:00:00 2001 From: Jakob Perry Date: Wed, 13 Jan 2016 15:40:57 -0800 Subject: [PATCH] 2415237 --- commerce.api.php | 17 +++++++++++++++++ commerce.module | 16 ++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/commerce.api.php b/commerce.api.php index d13ad3d..9fbdff7 100644 --- a/commerce.api.php +++ b/commerce.api.php @@ -177,3 +177,20 @@ function hook_commerce_entity_access_condition_alter() { function hook_commerce_entity_create_alter($entity_type, $entity) { // No example. } + +/** + * Allows modules to alter the default currency. + * + * @param $currency_code + * The default currency code. + * @param $context + * Optional context for determining the default currency. + * + * @see commerce_default_currency() + */ +function hook_commerce_default_currency_alter(&$currency_code, $context = NULL) { + global $language; + if (isset($language->language) && $language->language == 'en-US') { + $currency_code = 'USD'; + } +} diff --git a/commerce.module b/commerce.module index c23edc2..22eb18d 100755 --- a/commerce.module +++ b/commerce.module @@ -468,9 +468,21 @@ function commerce_i18n_string($name, $default, $options = array()) { /** * Returns the currency code of the site's default currency. + * + * @param $context + * Provide an optional context to help determine the default currency. */ -function commerce_default_currency() { - return variable_get('commerce_default_currency', 'USD'); +function commerce_default_currency($context = NULL) { + // Once the currency is set, don't change it. + $currency = &drupal_static(__FUNCTION__); + + if (!isset($currency)) { + $currency = variable_get('commerce_default_currency', 'USD'); + // Allow modules to alter the default currency. + drupal_alter('default_currency', $currency, $context); + } + + return $currency; } /** -- 2.5.4 (Apple Git-61)