Thursday, August 30, 2018

How to get Currency symbol in Magento2




How to get currency symbol in Magento2?

It is very simple to retrieve currency symbol from Magento2

In your Helper add a constructor like below
    protected $storeManager;
    protected $_localeCurrency;

public function __construct(
        \Magento\Store\Model\StoreManagerInterface $storemanager,
        \Magento\Framework\Locale\CurrencyInterface $localeCurrency
       ) {
        $this->_storeManager       = $storemanager;
        $this->_localeCurrency     = $localeCurrency;
         }


/**
     * [getCurrencySymbol get currency symbol]
     * @return string currency symbol
     */
    public function getCurrencySymbol()
    {
        $code     = $this->_storeManager->getStore()->getCurrentCurrencyCode();
        $currency = $this->_localeCurrency->getCurrency($code)->getSymbol();
        return $currency;
    }

No comments:

Post a Comment