How we can set Currency by default Billing Address Country. I was trying to implement the same using the solution mentioned in

How to set Currency by default Billing Address Country in Magento 1.9?.

But now I got stuck in the following error.

Fatal error: Uncaught Error: Class 'Mage' not found. Becuase " Mage::app()->getStore()->setCurrentCurrencyCode($mapping[$countryCode]);" not supported in magento 2.

I was trying to do change the currency on cutomer login based on billing addrsss country with the help of observer.

Can anybody help on how we Can set the store currency in Magento 2?


You can use setCurrencycode($code) method to set your store currency programmatically.

Just Inject following class: Magento/Store/Model/Store

in there a function is defined as:

public function setCurrentCurrencyCode($code)
     $code = strtoupper($code);
     if (in_array($code, $this->getAvailableCurrencyCodes())) {

            $defaultCode = $this->_storeManager->getWebsite()->getDefaultStore()->getDefaultCurrency()->getCode();
            $this->_httpContext->setValue(Context::CONTEXT_CURRENCY, $code, $defaultCode);
        return $this;

Just Call this function anywhere you want and pass the currency code in the parameter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.