Open ducquywp92 opened 1 year ago
Hi @ducquywp92. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:
@magento give me 2.4-develop instance
- upcoming 2.4.x release@magento I am working on this
Join Magento Community Engineering Slack and ask your questions in #github channel. :warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting. :clock10: You can find the schedule on the Magento Community Calendar page. :telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.
Hi @engcom-Hotel. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:
Area: XXXXX
label to the ticket, indicating the functional areas it may be related to.2.4-develop
branch@magento give me 2.4-develop instance
to deploy test instance on Magento infrastructure. 2.4-develop
branch, please, add the label Reproduced on 2.4.x
.Issue: Confirmed
once verification is complete. Hello @ducquywp92,
Thanks for the report and collaboration!
We have gone through with the description and it seems to us a valid good-to-have feature.
Hence marking this issue as a feature request.
Thanks
@ducquywp92 how did you solve it?
@akosglue @ducquywp92
Correct scenario: Even after creating an observer and set the position symbol in \Magento\Framework\Currency::LEFT or RIGHT with setData the symbol is not moved.
This is only a temporary fix.
Just make on override of the method formatCurrency in (vendor/magento/module-directory/Model/Currency.php) at line 436 with:
if ((array_key_exists(LocaleCurrency::CURRENCY_OPTION_DISPLAY, $options)
&& $options[LocaleCurrency::CURRENCY_OPTION_DISPLAY] === \Magento\Framework\Currency::NO_SYMBOL)) {
$formattedCurrency = str_replace(' ', '', $formattedCurrency);
}else if (array_key_exists('position', $options)
&& $options['position'] === \Magento\Framework\Currency::LEFT){
$exp = explode(" ", $formattedCurrency);
$formattedCurrency = $exp[1].' '.$exp[0];
}else if (array_key_exists('position', $options)
&& $options['position'] === \Magento\Framework\Currency::RIGHT){
$exp = explode(" ", $formattedCurrency);
$formattedCurrency = $exp[0].' '.$exp[1];
}
@akosglue @ducquywp92
Correct scenario: Even after creating an observer and set the position symbol in \Magento\Framework\Currency::LEFT or RIGHT with setData the symbol is not moved.
This is only a temporary fix.
Just make on override of the method formatCurrency in (vendor/magento/module-directory/Model/Currency.php) at line 436 with:
if ((array_key_exists(LocaleCurrency::CURRENCY_OPTION_DISPLAY, $options) && $options[LocaleCurrency::CURRENCY_OPTION_DISPLAY] === \Magento\Framework\Currency::NO_SYMBOL)) { $formattedCurrency = str_replace(' ', '', $formattedCurrency); }else if (array_key_exists('position', $options) && $options['position'] === \Magento\Framework\Currency::LEFT){ $exp = explode(" ", $formattedCurrency); $formattedCurrency = $exp[1].' '.$exp[0]; }else if (array_key_exists('position', $options) && $options['position'] === \Magento\Framework\Currency::RIGHT){ $exp = explode(" ", $formattedCurrency); $formattedCurrency = $exp[0].' '.$exp[1]; }
its not working for me!
@akosglue @ducquywp92 Correct scenario: Even after creating an observer and set the position symbol in \Magento\Framework\Currency::LEFT or RIGHT with setData the symbol is not moved. This is only a temporary fix. Just make on override of the method formatCurrency in (vendor/magento/module-directory/Model/Currency.php) at line 436 with:
if ((array_key_exists(LocaleCurrency::CURRENCY_OPTION_DISPLAY, $options) && $options[LocaleCurrency::CURRENCY_OPTION_DISPLAY] === \Magento\Framework\Currency::NO_SYMBOL)) { $formattedCurrency = str_replace(' ', '', $formattedCurrency); }else if (array_key_exists('position', $options) && $options['position'] === \Magento\Framework\Currency::LEFT){ $exp = explode(" ", $formattedCurrency); $formattedCurrency = $exp[1].' '.$exp[0]; }else if (array_key_exists('position', $options) && $options['position'] === \Magento\Framework\Currency::RIGHT){ $exp = explode(" ", $formattedCurrency); $formattedCurrency = $exp[0].' '.$exp[1]; }
its not working for me!
have you added the observer?
@akosglue @ducquywp92 Correct scenario: Even after creating an observer and set the position symbol in \Magento\Framework\Currency::LEFT or RIGHT with setData the symbol is not moved. This is only a temporary fix. Just make on override of the method formatCurrency in (vendor/magento/module-directory/Model/Currency.php) at line 436 with:
if ((array_key_exists(LocaleCurrency::CURRENCY_OPTION_DISPLAY, $options) && $options[LocaleCurrency::CURRENCY_OPTION_DISPLAY] === \Magento\Framework\Currency::NO_SYMBOL)) { $formattedCurrency = str_replace(' ', '', $formattedCurrency); }else if (array_key_exists('position', $options) && $options['position'] === \Magento\Framework\Currency::LEFT){ $exp = explode(" ", $formattedCurrency); $formattedCurrency = $exp[1].' '.$exp[0]; }else if (array_key_exists('position', $options) && $options['position'] === \Magento\Framework\Currency::RIGHT){ $exp = explode(" ", $formattedCurrency); $formattedCurrency = $exp[0].' '.$exp[1]; }
its not working for me!
have you added the observer?
yes, i have added observer!
I came across this issue while working on a feature, and as stated previously here (https://github.com/magento/magento2/issues/37280#issuecomment-1694432544), even if you create an observer to set the currency symbol 'position' data, the symbol is not affected because the 'position' data is never taken into account in the core currency format methods. Also, the method formatCurrency in "vendor/magento/module-directory/Model/Currency.php" mentioned here too (https://github.com/magento/magento2/issues/37280#issuecomment-1694432544), is a private method, which makes the option of creating a plugin for such a method impossible.
There is however a viable option that I used to solve this issue for the feature I was working on, which involves an after-plugin for the public method formatTxt in "vendor/magento/module-directory/Model/Currency.php". In fact, I created a very lightweight module publicly available that serves as a solution, so for anyone who has come across this same issue, you are very welcome to use that module or explore it to implement a similar solution https://github.com/esteban-w/m2-currency-symbol-position (at least until we get a permanent solution implemented by Magento in a future update). The solution implemented in the module basically consists of:
I hope this helps anyone looking for a solution, and if you need the details of my implementation you can find it at https://github.com/esteban-w/m2-currency-symbol-position
Peace.
Summary
Since Magento 2.4.6, Zendframework1 has been removed. We use below class to format price Magento\Framework\Currency\Data\Currency.php
On line 28
public const RIGHT = 16;
On line 139
$numberFormatter = new NumberFormatter($options['locale'], NumberFormatter::CURRENCY);
Position right value has been define, but never used. So if we using Japan locale, the output of this function alway be 円100. There is no option to move currency symbol (we expect 100円)
Examples
Proposed solution
Can we have the option to change the currency symbol position?
Release note
No response
Triage and priority