1

I want to get the list of allowed currency names for a store. Please note that, I know how to get the allowed currency codes, but all I want is , it's name. For example, Indian Rupee, US Dollar etc.

Please suggest some code without using the Object Manager concept.

2 Answers 2

2
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\Locale\CurrencyInterface;



protected $storeManager;

protected $localeCurrency;


public function __construct(
    ...
    StoreManagerInterface $storeManager,
    CurrencyInterface $localeCurrency
    ....
) {
    ....
    $this->storeManager = $storeManager;    
    $this->localeCurrency = $localeCurrency;
    ....
}


$currencyCodes=$this->storeManager->getStore(1)->getAvailableCurrencyCodes(); // replace with your store Id
if($currencyCodes){
    foreach ($currencyCodes as $code){
        $currencyData[$code]=$this->localeCurrency->getCurrency($code)->getName();
    }
    print_r($currencyData);exit;
}

I know foreach loop is bad to prepare array but I think there is no direct method available to get the currency name, even Magento team does the forech loop to print the currency name. You can also confirm this in

app\code\Magento\Sales\view\adminhtml\templates\order\create\data.phtml

0
0

Get currency codes and names

protected $storeManager;
protected $currencyInterface;


public function __construct(
    \Magento\Store\Model\StoreManagerInterface $storeManager
    \Magento\Framework\Locale\CurrencyInterface $currencyInterface
) {
    $this->storeManager = $storeManager;
    $this->currencyInterface = $currencyInterface;
}


$availableCurrencies = $this->storeManager->getStore()->getAvailableCurrencyCodes();
$currencyNames = array();

foreach ($availableCurrencies as $currencyCode) {
    $currencyNames[] = $this->currencyInterface->getCurrency($currencyCode)->getName();
}

print_r($currencyNames);
1
  • getOptionCurrencies will display all currency name not only allowed currency @Dinesh
    – Keyur Shah
    Oct 13, 2017 at 10:22

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.