From 7e315c88998d2ade4e2d22b99327847c6f231903 Mon Sep 17 00:00:00 2001
From: Jakob Perry <japerry@45640.no-reply.drupal.org>
Date: Wed, 13 Jan 2016 15:40:57 -0800
Subject: [PATCH] 2415237

---
 commerce.api.php |  4 +++-
 commerce.module  | 16 +++++++++++++---
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/commerce.api.php b/commerce.api.php
index 2c44df6..9fbdff7 100644
--- a/commerce.api.php
+++ b/commerce.api.php
@@ -183,10 +183,12 @@ function hook_commerce_entity_create_alter($entity_type, $entity) {
  *
  * @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) {
+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 1bf6226..c4ed2e9 100755
--- a/commerce.module
+++ b/commerce.module
@@ -468,10 +468,20 @@ 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() {
-  $currency_code = variable_get('commerce_default_currency', 'USD');
-  drupal_alter('commerce_default_currency', $currency_code);
+function commerce_default_currency($context = NULL) {
+  // Once the currency is set, don't change it.
+  $currency_code = &drupal_static(__FUNCTION__);
+
+  if (!isset($currency)) {
+    $currency_code = variable_get('commerce_default_currency', 'USD');
+    // Allow modules to alter the default currency.
+    drupal_alter('commerce_default_currency', $currency_code, $context);
+  }
+
   return $currency_code;
 }
 
-- 
2.6.4 (Apple Git-63)

