public static function refreshCurrencies() { $currencies_to_update = ''; $currencies = Currency::getCurrencies(true, false, true); foreach($currencies as $key => $currency) { $currencies_to_update .= ($key > 0 ? ',' : '').$currency->iso_code; } $default_currency = Currency::getDefaultCurrency(); $data = Tools::file_get_contents('https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies/'.strtolower($default_currency->iso_code).'.min.json'); if(!$parser = Tools::jsonDecode($data, true)) { $data = Tools::file_get_contents('https://latest.currency-api.pages.dev/v1/currencies/'.strtolower($default_currency->iso_code).'.json'); $parser = Tools::jsonDecode($data, true); } if(is_array($parser) && isset($parser[strtolower($default_currency->iso_code)])) { foreach($currencies as $currency) { if($currency->id != $default_currency->id) { foreach($parser['eur'] as $iso_code => $rate) { if(strtoupper($iso_code) == $currency->iso_code) { $currency->conversion_rate = round($rate, 6); $currency->update(); } } } } return false; } else { $error = Tools::displayError('Error: unable to update currencies exchange rate from').' cdn.jsdelivr.net ('.$parser.')'; PrestaShopLogger::addLog($error, 1, '0000001', 'Currency', 0); return $error; } }