Magento2: Priduct page price is using the hardcoded digits in js

Created on 22 Mar 2018  路  5Comments  路  Source: magento/magento2

When using more then 2 digits ex(9.4880 will be displayed as 9.49) for the price the js will override this value and it will format using the round for 2 digits.

Preconditions


  1. magento 2.2.0
  2. php 7.0
  3. mysql 5.7.21

Steps to reproduce

  1. Create a plugin to use more then 2 digits for the price
  2. The price should be saved in database as 9.4880
  3. category page will display the price based on database value, but when accessing the prodcut page the price will be overrided with value 9.49

Expected result

  1. Price = 9.488

Actual result

  1. Price = 9.49

Going deeer found the issue in price-utils.js on this line

        // replace(/-/, 0) is only for fixing Safari bug which appears
        // when Math.abs(0).toFixed() executed on '0' number.
        // Result is '0.-0' :(

        am = Number(Math.round(Math.abs(amount - i) + 'e+' + precision) + ('e-' + precision));
        r = (j ? i.substr(0, j) + groupSymbol : '') +
            i.substr(j).replace(re, '$1' + groupSymbol) +
            (precision ? decimalSymbol + am.toFixed(2).replace(/-/, 0).slice(2) : '');

am.toFixed(2) <--- is using the hardcoded precision and the price will be overrided with 2 digits value !!!

done a quick check and changing this to

am.toFixed(precision)

seems to do the job.

Thanks,
Calin.

Fixed in 2.1.x Fixed in 2.2.x Fixed in 2.3.x Format is valid

All 5 comments

@cdiacon your suggestion looks perfectly valid to me, could you please prepare a pull request?

Generally, when you see something in code you would like to change, it can be proposed directly as pull request, there is no need in reporting issue first.

Thanks @orlangur makes sense
Created a PR here https://github.com/magento/magento2/pull/14350

Hi @cdiacon. Thank you for your report.
The issue has been fixed in magento/magento2#14350 by @cdiacon in 2.2-develop branch
Related commit(s):

The fix will be available with the upcoming 2.2.5 release.

Hi @cdiacon. Thank you for your report.
The issue has been fixed in magento/magento2#14461 by @mastiuhin-olexandr in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.0 release.

Hi @cdiacon. Thank you for your report.
The issue has been fixed in magento/magento2#15926 by @dmytro-ch in 2.1-develop branch
Related commit(s):

The fix will be available with the upcoming 2.1.15 release.

Was this page helpful?
0 / 5 - 0 ratings