Back to Top

How to get all the allowed currencies having currency rates.

Updated 11 January 2018

Hello everyone, sometimes we need all those currencies that are allowed by admin and also have conversion rates set by the admin.

Following code will help you to achieve this.

First of all, In the Helper construct, add the following code,

public function __construct(
   \Magento\Directory\Block\Currency $currency,
   \Magento\Framework\App\Helper\Context $context
) {
   $this->_currency = $currency;
   parent::__construct($context);
}

after that, you can write this function to get the currencies codes with their corresponding names as below-

public function getCurrencies() //this will fetch the allowed currencies for which rates are set
{
    $currencies = $this->_currency->getCurrencies();
    $currencyData = [];
    foreach ($currencies as $code => $currencyName) {
        $currencyData[$code]['code'] = $code;
        $currencyData[$code]['name'] = $currencyName;
    }
    return $currencyData;
}

if you print $currencyData, it will display the result as you can see in the image-

Searching for an experienced
Magento 2 Company ?
Find out More


This is all for now. Hope this will help.

For any queries, comment below.

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home