Skip to content

Using System Value for Base Currency Results in Config Error #8003

Closed
@tsmith1985

Description

@tsmith1985

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

  1. Log into Admin
  2. Navigate to Stores > Settings > Configuration > General > Currency Setup
  3. Select Use system value for Base Currency
  4. Select Yes for Enabled in the Scheduled Import Settings section
  5. Click Save Config if necessary and flush the cache
  6. Navigate to Stores > Currency > Currency Rates
  7. Try Importing Currency Rates via any of the three services

Expected result

  1. Currency rates are imported for Allowed Currencies

Actual result

  1. You must first configure currency options before being able to see currency rates. is displayed on Currency Rates page and user is unable to import rates via any of the services.

currency_options

currency_rates

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

Component: ConfigFixed in 2.2.xThe issue has been fixed in 2.2 release lineFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releaseReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 releasebug report

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions