Hello Magento Folks,

In this tutorial blog, I will help you to get the currency data like code, rate, and symbol in Magento 2. Also, check out my last published blog where I have illustrated How to Add Discount Component to Checkout Order Summary in Magento 2. Let’s get started with today’s article.

Basically when anyone utilizes the Magento 2 platform to develop an e-commerce/online store then there is a functionality where you can accept any currencies which depend on your customers and buyers. With the help of this illustration, I will assist you to fetch default, current currency code available currency code as well as allowed currency codes.

Steps to get Currency data: Code, Rate, Symbol in Magento 2:

Step 1: Declare in Vendor_Extension

You will use a block class of the module Vendor_Extension, then possibly inject the object of StoreManagerInterface & Currency class in the constructor of the module’s block class.

Path: app/code/Vendor/Extension/Block/Currency/Getdata.php

 

You can see more functions in vendor/magento/module-store/Model/Store.php and vendor/magento/module-directory/Model/Currency.php.

Step 2: Now, we will fetch the output in the currency data in the phtml file.

Run the below code for fetching and printing the currency symbol, currency code, and currency rate in the template phtml file. 

currencyData.phtml

 

 

That’s It

Wrap Up:

Hopefully, all are able to get Currency data: Code, Rate, Symbol in Magento 2 by following the above illustration. In case of any errors you face in the implementation of the above code then let me know in the comment section below. You can also utilize our Hire Magento Developer Service for implementing the above tutorial precisely in your Magento 2 store.

Share the article with your Magento Developer Friends

Happy Reading!

[Total: 2   Average: 5/5]