function commerce_multicurrency_cron in Commerce Multicurrency 7
Implements hook_cron().
Queues currencies for updates.
1 call to commerce_multicurrency_cron()
- commerce_multicurrency_sync_exchange_rates_now in ./
commerce_multicurrency.module - Function to trigger the currency exchange rate synchronization.
File
- ./
commerce_multicurrency.module, line 222 - Enhancements for the commerce currency support.
Code
function commerce_multicurrency_cron() {
$currencies = commerce_currencies(TRUE);
if (!($conversion_settings = variable_get('commerce_multicurrency_conversion_settings', FALSE))) {
return;
}
$queue = DrupalQueue::get('commerce_multicurrency_sync_exchange_rates');
foreach ($currencies as $currency_code => $currency) {
$currencies_to_sync = $currencies;
unset($currencies_to_sync[$currency_code]);
$currency_sync_item = array(
'currency_code' => $currency_code,
'target_currencies' => empty($currencies_to_sync) ? array() : array_combine(array_keys($currencies_to_sync), array_keys($currencies_to_sync)),
);
// Check if there are individual settings per currency to currency rate.
if (!empty($conversion_settings[$currency_code]) && empty($conversion_settings[$currency_code]['sync'])) {
foreach ($conversion_settings[$currency_code]['rates'] as $target_currency_code => $settings) {
// If this combination is excluded from autosync remove it.
if (empty($settings['sync'])) {
unset($currency_sync_item['target_currencies'][$target_currency_code]);
}
}
}
$queue
->createItem($currency_sync_item);
}
$queue
->createItem('finish');
}