PrestaShop Exception Validation Error

Posted by on 3 August 2016

A recent install of PrestaShop v1.6 was throwing an Exception Error when trying to convert a cart to an order. This happened when the customer paid or in the back office converting a cart to an order manually. It was only happening in some instances and only on the live server not my local copy. Hence, it was tricky to track down the culprit.

Error message example:

[PrestaShopException]

Property Order->total_shipping_tax_excl is not valid
at line 909 in file classes/ObjectModel.php

The problem related to the precision of PHP's rounding when using the (float) function. The live server's precision was set to 16 and my local server was set to 14.

Quick Solution

If you experience this problem, add this line to the file : config/config.inc.php

ini_set('precision',9);

Explanation

The validation function that PrestaShop uses to determine if a variable is a price relies on a regular expression. Before this validation takes place though the number is converted to a float and the precision of this number is based on the server setting. In my case the precision was too large and causing the regex to not find a match.

public static function isPrice($price) {
   return preg_match('/^[0-9]{1,10}(\.[0-9]{1,9})?$/', $price);
}

 

Like to make an inquiry? Contact Us