Closed
Description
Checking Use system value
for the base currency in the currency options results in a configuration error when importing currency rates.
Preconditions
- Magento CE v2.1.3
- PHP v7.0.14
- MySQL v14.14 Distrib 5.7.16, for osx 10.12
Steps to reproduce
- Log into Admin
- Navigate to
Stores > Settings > Configuration > General > Currency Setup
- Select
Use system value
forBase Currency
- Select
Yes
forEnabled
in theScheduled Import Settings
section - Click
Save Config
if necessary and flush the cache - Navigate to
Stores > Currency > Currency Rates
- Try Importing Currency Rates via any of the three services
Expected result
- Currency rates are imported for
Allowed Currencies
Actual result
You must first configure currency options before being able to see currency rates.
is displayed onCurrency Rates
page and user is unable to import rates via any of the services.
Additional Notes
I was able to work around this issue by unselecting Use system value
and explicitly selecting a Base Currency.
This issue seems to be a result of the base currency not being written to the database when Use system value
is selected
mysql> mysql> select * from core_config_data where path='currency/options/base';
Empty set (0.00 sec)
This results in this method failing to fetch the rates as $defaultCurrencies
(actually base currencies) is empty:
<magento install dir>/vendor/magento/module-directory/Model/Currency/Import/AbstractImport.php#L92-L117
/**
* @return array
*/
public function fetchRates()
{
$data = [];
$currencies = $this->_getCurrencyCodes();
$defaultCurrencies = $this->_getDefaultCurrencyCodes();
set_time_limit(0);
foreach ($defaultCurrencies as $currencyFrom) {
if (!isset($data[$currencyFrom])) {
$data[$currencyFrom] = [];
}
foreach ($currencies as $currencyTo) {
if ($currencyFrom == $currencyTo) {
$data[$currencyFrom][$currencyTo] = $this->_numberFormat(1);
} else {
$data[$currencyFrom][$currencyTo] = $this->_numberFormat(
$this->_convert($currencyFrom, $currencyTo)
);
}
}
ksort($data[$currencyFrom]);
}
ini_restore('max_execution_time');
return $data;
}
Also, the _getDefaultCurrencyCodes()
method is getting the base currencies rather than the default currencies, which may be a bug or just a poor naming choice:
<magento install dir>/vendor/magento/module-directory/Model/Currency/Import/AbstractImport.php#L49-L52
protected function _getDefaultCurrencyCodes()
{
return $this->_currencyFactory->create()->getConfigBaseCurrencies();
}
Metadata
Metadata
Assignees
Labels
The issue has been fixed in 2.2 release lineThe issue has been fixed in 2.3 release lineGate 3 Passed. Manual verification of the issue completed. Issue is confirmedGate 1 Passed. Automatic verification of issue format passedGate 4. Acknowledged. Issue is added to backlog and ready for developmentThe issue has been reproduced on latest 2.1 releaseThe issue has been reproduced on latest 2.2 releaseThe issue has been reproduced on latest 2.3 release