Prestashop: Rounding to full numbers and not 2 decimals

Created on 20 Dec 2020  路  12Comments  路  Source: PrestaShop/PrestaShop

Bug: Product cards have prices rounded to full numbers and not 2 decimals.

Issue is for all products in webshop.
First occurrence: after update from 1.7.6.9 using 1-click update

  1. Product price with TAX in database: 616.55
  2. Product price visible at product card: 617.00
  3. International>Localization>Curencies> "Decimals" = 2
  4. Products added to cart have a correct price 616.55
  5. /src/Core/Localization/CLDR/ComputingPrecision.php is:
    `namespace PrestaShop\PrestaShop\Core\Localization\CLDR;

/**

  • {@inheritdoc}
    */
    final class ComputingPrecision implements ComputingPrecisionInterface
    {
    const MULTIPLIER = 1;
    const MINIMAL_VALUE = 0;
/**
 * {@inheritdoc}
 */
public function getPrecision(int $displayPrecision)
{
    // the MULTIPLIER attribute is set to 1 for now, so that it matches display precision
    $computingPrecision = $displayPrecision * self::MULTIPLIER;

    return ($computingPrecision < self::MINIMAL_VALUE) ? self::MINIMAL_VALUE : $computingPrecision;
}

}`

Q1: Shouldn't the 'const MINIMAL_VALUE = 0;' be set to 2?

Prestashop: 1.7.7
PHP: 7.3
Zrzut ekranu 2020-12-20 142500
InkedZrzut ekranu 2020-12-20 142947_LI

1.7.7.0 Bug Currencies FO International Localization No change required

Most helpful comment

Hello everyone.
I found the problem. It was one of the modules which was working fine with previous version of PS and now it does not. The module was showing related products at product pages,categories & cart.
Anyway thanks @Hlavtox @hibatallahAouadni @SimonGrn for the guide and support!
Without you I would be looking in the wrong place!
I wish you all the best, happy, great and excellent Christmas and a happy new year! :):):)

All 12 comments

@michael2278 Hi Michael, the MINIMAL_VALUE value is correct. It works fine in clean 1.7.7 install. I think that something went wrong in the upgrade process, or there is something influencing the way the price on your product page displays.

See here:
1
2

Thanks for a quick reply.
Any hints what to look for?
For me this is a major issue because Google Merchant Center is rejecting my products. The reason is that one of my modules creates a feed for GMC and uses real prices while in webshop Google sees a different price (rounded). My ads are not showing...
I would really appreciate any hints/directions/ideas what could be done to fix this :)

@michael2278

Go to your PS install, controllers/front, open any controller, for example Product Controller, put this right to beginning of initContent:

echo Context::getContext()->getComputingPrecision();
echo Context::getContext()->currency->precision;

Then go to product page and there should be two numbers on the top of the page, are they 22?

Hi - yes, 22 is there at the top left corner.

Hello @michael2278

I didn't manage to reproduce your issue with my shop PS1.7.6.9 upgraded to PS1.7.7.0, see the attached screen record below:

https://drive.google.com/file/d/1vtat2tP0iIcfWII2rVNwg3I5WmBTPaCN/view

Please check and feedback.
Thanks!

Hi @hibatallahAouadni
OK. But we did not do anything else with the shop...

  1. We made an 1-click upgrade
  2. We switched from PHP 7.2 to 7.3 (I tried switching back and it does not change anything)
    No new modules were installed and no other upgrades were made.
    I jut have no idea where to look for a solution.....

You can try to disable all your non-PrestaShop modules and reactivate them one by one to check if you can reproduce the problem.
Also, are you using the Classic Theme in FO ? It could be from the theme if it's a third-party. Try with Classic to check if the issue is still there.

Thank you

Checked with classic theme and problem is still there. I will continue with the modules this evening because of traffic.
Thanks everyone. All replies and ideas are really appreciated 馃憤

Hello @michael2278

By the way, have you changed any Core code? or override it?
If so, please redo what you changed and check if the problem persists.

Thanks!

Hello everyone.
I found the problem. It was one of the modules which was working fine with previous version of PS and now it does not. The module was showing related products at product pages,categories & cart.
Anyway thanks @Hlavtox @hibatallahAouadni @SimonGrn for the guide and support!
Without you I would be looking in the wrong place!
I wish you all the best, happy, great and excellent Christmas and a happy new year! :):):)

@michael2278 Glad that you found the problem :tada:
Merry Christmas and happy new year :slightly_smiling_face:

@michael2278 Awesome! :-) Merry christmas for you too!

Maybe the module is not hard to fix, search the code for some rounding and investigate why there is 0 for decimal places, or just hardcode 2 there... 馃馃槃

Was this page helpful?
0 / 5 - 0 ratings