function commerce_currencies in Commerce Core 7
Returns an array of all available currencies.
Parameters
$enabled: Boolean indicating whether or not to return only enabled currencies.
$reset: Boolean indicating whether or not the cache should be reset before currency data is loaded and returned.
Return value
An array of altered currency arrays keyed by the currency code.
9 calls to commerce_currencies()
- commerce_currency_get_code in ./
commerce.module - Returns an associative array of the specified currency codes.
- commerce_currency_get_symbol in ./
commerce.module - Returns the symbol of any or all currencies.
- commerce_currency_load in ./
commerce.module - Returns a single currency array.
- commerce_currency_settings_form in includes/
commerce_ui.admin.inc - Builds the currency settings form.
- commerce_payment_handler_filter_currency_code::get_value_options in modules/
payment/ includes/ views/ handlers/ commerce_payment_handler_filter_currency_code.inc - Child classes should be used to override this function and set the 'value options', unless 'options callback' is defined as a valid function or static public method to generate these values.
File
- ./
commerce.module, line 510 - Defines features and functions common to the Commerce modules.
Code
function commerce_currencies($enabled = FALSE, $reset = FALSE) {
global $language;
$currencies =& drupal_static(__FUNCTION__);
// If there is no static cache for currencies yet or a reset was specified...
if (!isset($currencies) || $reset) {
// First attempt to load currency data from the cache if we simply didn't
// have it statically cached and a reset hasn't been specified.
if (!$reset && ($currencies_cached = cache_get('commerce_currencies:' . $language->language))) {
$currencies['all'] = $currencies_cached->data;
}
else {
// Otherwise we'll load currency definitions afresh from enabled modules.
// Begin by establishing some default values for currencies.
$defaults = array(
'symbol' => '',
'minor_unit' => '',
'decimals' => 2,
'rounding_step' => 0,
'thousands_separator' => ',',
'decimal_separator' => '.',
'symbol_placement' => 'hidden',
'symbol_spacer' => " ",
'code_placement' => 'after',
'code_spacer' => " ",
'format_callback' => '',
'conversion_callback' => '',
'conversion_rate' => 1,
);
// Include the currency file and invoke the currency info hook.
module_load_include('inc', 'commerce', 'includes/commerce.currency');
$currencies['all'] = module_invoke_all('commerce_currency_info');
drupal_alter('commerce_currency_info', $currencies['all'], $language->language);
// Add default values if they don't exist.
foreach ($currencies['all'] as $currency_code => $currency) {
$currencies['all'][$currency_code] = array_merge($defaults, $currency);
}
// Sort the currencies
ksort($currencies['all']);
cache_set('commerce_currencies:' . $language->language, $currencies['all']);
}
// Form an array of enabled currencies based on the variable set by the
// checkboxes element on the currency settings form.
$enabled_currencies = array_diff(array_values(variable_get('commerce_enabled_currencies', array(
'USD' => 'USD',
))), array(
0,
));
$currencies['enabled'] = array_intersect_key($currencies['all'], drupal_map_assoc($enabled_currencies));
}
return $enabled ? $currencies['enabled'] : $currencies['all'];
}