You are here

function commerce_multicurrency_get_user_currency_code in Commerce Multicurrency 7

Returns the currency code to use for the current user.

Return value

string The currency code.

10 calls to commerce_multicurrency_get_user_currency_code()
CommerceMulticurrencyTestCase::testGetCurrency in tests/commerce_multicurrency.test
Test that the currency retrieving works.
CommerceMulticurrencyTestCase::testNotOverwrittingCurrency in tests/commerce_multicurrency.test
Test that the currency switching works as expected.
CommerceMulticurrencyTestCase::testSetCurrency in tests/commerce_multicurrency.test
Test that the currency switching works as expected.
commerce_multicurrency_block_view in ./commerce_multicurrency.module
Implements hook_block_view().
commerce_multicurrency_commerce_cart_line_item_refresh in ./commerce_multicurrency.module
Implements hook_commerce_cart_line_item_refresh().

... See full list

4 string references to 'commerce_multicurrency_get_user_currency_code'
CommerceMulticurrencyTestCase::testGetCurrency in tests/commerce_multicurrency.test
Test that the currency retrieving works.
CommerceMulticurrencyTestCase::testNotOverwrittingCurrency in tests/commerce_multicurrency.test
Test that the currency switching works as expected.
CommerceMulticurrencyTestCase::testSetCurrency in tests/commerce_multicurrency.test
Test that the currency switching works as expected.
commerce_multicurrency_set_user_currency_code in ./commerce_multicurrency.module
Store the currency_code to use for the user.

File

./commerce_multicurrency.module, line 478
Enhancements for the commerce currency support.

Code

function commerce_multicurrency_get_user_currency_code() {
  $currency_code =& drupal_static(__FUNCTION__, FALSE);
  if ($currency_code) {
    return $currency_code;
  }

  // If there's a cookie with a selected currency ensure it's a available one.
  if (isset($_COOKIE['Drupal_visitor_commerce_currency'])) {
    $enabled_currencies = commerce_currencies(TRUE);
    if (!empty($enabled_currencies[$_COOKIE['Drupal_visitor_commerce_currency']])) {
      return $currency_code = $_COOKIE['Drupal_visitor_commerce_currency'];
    }
  }
  return $currency_code = commerce_default_currency();
}