In this Article I am going to explain, how to change the current currency of the store.
Need : If you are developing Api’s or creating the custom module, the situation may come, when you need to change the current currency of store.
To get the right behaviour for the target.
Here we go :
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $storeManager = $objectManager->get(\Magento\Store\Model\StoreManagerInterface::class); $currency = "USD"; if ($currency) { $storeManager->getStore()->setCurrentCurrencyCode($currency); }
$currency is a currency code in which you want to set the current currency to your store.
6 comments
I placed this code in a handler for the event ‘controller_action_predispatch’ to force the full request to this currency. Worked like charm!
Webkul guys are always awesome.save my lots of times.
Thank you for sharing your knowledge.
#Webkul