Magento2: Price format based on locale instead of currency/country

Created on 27 Aug 2017  路  6Comments  路  Source: magento/magento2


Preconditions


  1. Magento 2.1.7 (probably latest also)
  2. Language: en_US
  3. Default Country: Sweden
  4. Default Display Currency: Swedish Krona

Steps to reproduce

  1. View any product on category page, product page, account pages, checkout etc

Expected result

  • Price format in a Swedish format like for example: "2.000,00 SEK", "2 000,00 SEK" or "2000.00 SEK"
  • decimal is comma "," in Sweden
  • Format not dependent on locale but instead on Default Display Currency or Default Country.
  • Bonus: Also it would be nice if it could be configured what format to use in Admin per store view.

Actual result

  1. Price looks like "SEK 2,000.00" which would essentially mean that it looks like it costs 2 SEK instead of 2000 SEK.


Developer comment: Also the logic for this is too spread out, in order to change this you need to plugin/mixin all of these files:

  • Magento\Directory\Model\Currency
  • Magento\Framework\Locale\Format
  • Magento\Tax\Block\Item\Price\Renderer
  • Magento_Catalog/js/price-utils
  • Magento_Msrp/js/view/checkout/minicart/subtotal/totals

IMO there should be 1 class in BE that formats the prices + a controller for that. FE should simply call that controller with Ajax to get the price formatting (instead of hardcoded formats in js files)

Clear Description Confirmed Format is valid Ready for Work Reproduced on 2.1.x Reproduced on 2.2.x bug report non-issue

All 6 comments

@OZZlE, thank you for your report.
We've created internal ticket(s) MAGETWO-75577 to track progress on the issue.

@magento-engcom-team wow thank you :)

I'm not sure if we should bump into a technical solution for this right away. As part of a hackathon at MeetMagento Belgium, we checked a few international shops (non-Magento based) to see how they approached this. And they all used the chosen language (so the locale) to represent the currency. So, I'm not sure this is actually a technical issue, or actually, a strategical change (a feature) that makes sense to a lot of people. This will need to be discussed in the community with multiple merchants first, or internally by Magento, before it should be picked up here.

Suggestion: Like @OZZlE suggested, it could maybe be a good idea to add an option in the Store Configuration, see you can select the way that money should be formatted - maybe in the form of an input string for money_format() (native PHP function).

Some further development notes: The class Magento\Framework\Locale\Currency triggers an event currency_display_options_forming. This event has a few parameters, one of them being $options. If this is changed through an observer into the locale nl_NL for example, it changes the formatting. This is used on a Block-level. On the JS level, a different class is used: Magento\Framework\Locale\Format which can be manipulated through a Plugin-method that modifies the return value of getPriceFormat(). In short, an extension could be created to do this, instead of requesting a modification in the core.

Hi @OZZlE thank you for report
@jissereitsma thank you for deep investigation. I would support your idea, so closing the issue as non-issue.
Sorry @OZZlE , but you can customize this behavior for your store. if there are not enough extension points for that, just submit a PR. Thank you

Why this issue is close ?
Magento return very strange price formatting.
For example in every place when use price, magento set a different format: look in product grid, cart, checkout administration and admin. Every price (product, shipping, tax, etc) have own price format. This is very very strange.

You can't close issue.

@okorshenko How is this a non issue when you need to modify over 5+ core files to get correct currency formatting across your entire store?

It needs to be fixed.

Was this page helpful?
0 / 5 - 0 ratings