Magento 2 Module
How to change currency symbol position in Magento 2 (Left to Right)
Hide/Show description
Hello, My name is Cuong, I'm a Magento Developer, Welcome back to my Magento 2 tutorial video series. #magento2tutorial #magento2training #magento2
Today, I am going to show everybody the best practice, How to change the currency symbol position in Magento 2.
When you work for a project, you are required to move the currency symbol from left to right or from right to left, you don't know how to complete this task, you are searching for a solution. Today I show you the best codes to complete your task.
We have the scenario: We will create a new feature that allows the administrator to set the currency symbol position in the Stores → Currency → Currency Symbol Position
So what will we do in this practice?
1. We will create a new module called PHPCuong_CurrencySymbolPosition
2. We will hook to the event named currency_display_options_forming changing currency symbol position set in the configuration
Okie, let's go.
Let's complete this practice you need to follow steps by step:
Step 1: Declaring the new module called PHPCuong_CurrencySymbolPosition
- Create the namespace PHPCuong in the path app\code
- Create the module named CurrencySymbolPosition in the path app\code\PHPCuong
- Create the file named registration.php in the path app\code\PHPCuong\CurrencySymbolPosition
- Create the file named module.xml in the path app\code\PHPCuong\CurrencySymbolPosition\etc
End of step #1, I have been completed the codes to create the new module called PHPCuong_CurrencySymbolPosition.
Step 2: Hook to event currency_display_options_forming
- Create the new file named events.xml in the path app\code\PHPCuong\ProductReviewForm\etc\frontend
- Create the new file named DisplayOptions.php in the path app\code\PHPCuong\CurrencySymbolPosition\Observer
class DisplayOptions implements
Step 3: Add the new page in the backend allows the administrator to set the value
- Create the new file named acl.xml in the path app\code\PHPCuong\CurrencySymbolPosition\etc
This file helps to define the role resource
- Create the new file named menu.xml in the path app\code\PHPCuong\CurrencySymbolPosition\etc\adminhtml
This file helps to define the link named "Currency Symbols Position" under the currency section
- Create the new file named routes.xml in the path app\code\PHPCuong\CurrencySymbolPosition\etc\adminhtml
This file helps to define the route path used for the module named PHPCuong_CurrencySymbolPosition in the backend
- Create the new file named Index.php in the path app\code\PHPCuong\CurrencySymbolPosition\Controller\Adminhtml\System\Currencysymbolposition
This file helps to define the new action named Index in the controller named System_Currencysymbolpostion.
- Create the new file named adminhtml_system_currencysymbolposition_index.xml in the path app\code\PHPCuong\CurrencySymbolPosition\view\adminhtml\layout
- Create the new block named CurrencySymbolPosition.php in the path app\code\PHPCuong\CurrencySymbolPosition\Block\Adminhtml\System
- Create the new template named grid.phtml in the path app\code\PHPCuong\CurrencySymbolPosition\view\adminhtml\templates
- Create the model named CurrencySymbolPosition.php in the path app\code\PHPCuong\CurrencySymbolPosition\Model\System
This file helps to save the value of currency symbol position in the table named core_config_data
- Create the new file named Save.php in the path app\code\PHPCuong\CurrencySymbolPosition\Controller\Adminhtml\System\Currencysymbolposition
Step 4: Test and See the results
1. Run the following command lines:
php bin/magento setup:upgrade --keep-generated
php bin/magento setup:di:compile
This process will take much time, please wait for 5 minutes.
This is the codes in the new module, I just created.
I am using the docker on windows 10 pro 64bit for developing Magento 2.
it is better than XAMPP, Vargant.
You can see the tutorial how to use install magento 2 with docker on windows 10 here
php bin/magento cache:flush
2. Go to the Backend.
Stores → Currency → Currency Symbol Position
Change the symbol position for the currencies
You can add more the currency here.
The base currency is USD, so we need to exchange from USD to another.
3. Go to the storefront.
Yeah, It works perfectly.
Thanks for watching the guide. If you have any questions about this practice, please feel free to leave a comment below.
Don't forget to like, comment, share my videos with your friends and subscribe to my channel for getting other lessons.
Please do not hesitate to contact me, if you need me to join your Magento project. My rate is $25/hour in Magento 1 and $30/hour in Magento 2.
Get the source codes of this practice in the Github https://github.com/php-cuong/magento2-currency-symbol-position
-
How to create a new module in Magento 2
How to add new tables for a custom module in Magento 2
How to create a grid using UI component in Magento 2
How to create a form using UI component in Magento 2
How to upload an image using fileUploader in Magento 2
How to validate the data before saving in Magento 2
How to display an image in the admin grid in magento 2
How to use the Inline Edit Component in Magento 2
How to add the JS and CSS files into a custom module in Magento 2
How to add a new Widget into a custom module in Magento 2
How to use plugin in Magento 2
How to use events and observers in magento 2
How to add a new customer attribute in magento 2
How to override a template phtml in Magento 2
How to create the buttons increase and decrease quantity on the product detail page in Magento 2
How to send an email from a custom module in Magento 2
How to create a new shipping method in Magento 2
How to display a static block in a popup in Magento 2
How to add a new checkout step in Magento 2
How to override a knockout HTML template file in Magento 2
How to create a custom console command in Magento 2 - Rebuild URL Rewrite
Increase and decrease quantity in Magento 2 mini cart
How to create a customization cart price rule condition in Magento 2
How to display best seller products on the homepage in Magento 2
How to restrict products by customer group in Magento 2
How to include coupon code in newsletter subscription success email in Magento 2
How to show the registration and login form in a popup in Magento 2
How to remove the decimal from the price in Magento 2
How to use Ajax for the newsletter subscription in Magento 2
How to redirect the customer to a custom page after logging in
How to add the CMS page links to the top menu in Magento 2
How to create lazy loading product images in Magento 2
How to move the Javascript files to the footer in Magento 2
How to remove out of stock items from the shopping cart in Magento 2
How to show review form only for the customer who has purchased the item in Magento 2
How to minify HTML in Magento 2
How to change currency symbol position in Magento 2 (Left to Right)
How to package and publish a magento 2 extension
How to display all products on sale in Magento 2
Magento 2 Admin Security [Send a notification email after logging in successfully]
How to create a custom log file in Magento 2
How to create a custom cron job in Magento 2