Magento 2 – Fix Different Currencies Not Working in Custom Store Views

magento-2.1magento2

In the Default Store View that is created in fresh Magento 2 installation, the currency switcher works, but only for EUR and USD. If I add British Pound or other currency to allowed currencies then it doesn't show up in currency switcher.
If I switch to other store view in store switcher (I mad English and German store views), there are no currency switchers and both use the same currency.
I have set Default Display Currency and Allowed Currencies to British Pound on English store view. EUR on German store view.

I tried to do this in backend and via setup script.

public function setDefaultCurrencies()
{
    $this->_config->saveConfig('currency/options/base', 'EUR', 'default', 0);
    $this->_config->saveConfig('currency/options/default', 'EUR', 'default', 0);
    $this->_config->saveConfig('currency/options/allow', 'EUR,GBP', 'default', 0);
}

public function setStoreViewCurrencies()
{
    $stores = $this->_storeManager->getStores(true, false);

    foreach ($stores as $store) {
        $storeId = $store->getId();

        if ($store->getCode() == 'en') {
            $this->_config->saveConfig('currency/options/allow', 'GBP', 'stores', $storeId);
            $this->_config->saveConfig('currency/options/default', 'GBP', 'stores', $storeId);
        }

        if ($store->getCode() == 'de') {
            $this->_config->saveConfig('currency/options/allow', 'EUR', 'stores', $storeId);
            $this->_config->saveConfig('currency/options/default', 'EUR', 'stores', $storeId);
        }
    }
}

EDIT:

enter image description here
enter image description here
enter image description here
enter image description here

Best Answer

After doing all these change you have to set the currency conversion rate.

Go to Admin -> Store -> Currency Rates

And set the currency conversion rates and save it.

After that Flush all your cache, and it will work properly.

Related Topic