Skip to content

Priduct page price is using the hardcoded digits in js #14249

@cdiacon

Description

@cdiacon

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fixed in 2.1.xThe issue has been fixed in 2.1 release lineFixed in 2.2.xThe issue has been fixed in 2.2 release lineFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Format is validGate 1 Passed. Automatic verification of issue format passed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions