You are here:  » tapestry_decimalise problem with setlocale


tapestry_decimalise problem with setlocale

Submitted by sirmanu on Mon, 2016-11-21 16:33 in

I recently add es_ES locale at server and I am experiencing some problems when importing price. All the prices are ending with 0 decimals. Example: 55.00; 22.00; 288.00...

With an example is easy so let's see it:

<?php
setlocale
(LC_ALL,"es_ES");
require(
"includes/common.php");
echo 
tapestry_decimalise("399.95");
?>

Returns 399,95

I have 2 possible solutions that I want to know if are valid:

1) Set setlocale to the first line of function tapestry_decimalise

setlocale(LC_ALL, array('en_GB.UTF8','en_GB@euro','en_GB','english'));

2) Modify admin.php

$importRecord["price"] = tapestry_decimalise($importRecord["price"]);
into
$importRecord["price"] = tapestry_decimalise(str_replace(",",".",$importRecord["price"]));

Did you have other clients with this problem?
Thank you...

Submitted by support on Mon, 2016-11-21 16:54

Hi,

I would suggest changing the tapestry_decimalise() function to use number_format instead of sprintf as it is not locale aware and simply uses the decimal separator supplied in the call. To do this, edit includes/tapestry.php and look for the following code at line 53:

    $price = sprintf("%.2f",$price);

...and REPLACE with:

    $price = number_format($price,2,".","");

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by sirmanu on Tue, 2016-11-22 11:53

Excellent. It worked! Thanks

Submitted by sirmanu on Sat, 2016-12-03 18:39

Hi David. Do you know why I am getting this error:
"PHP Notice: A non well formed numeric value encountered in"
in that line?

($price = number_format($price,2,".","");)

Submitted by support on Mon, 2016-12-05 11:33

Hi,

That would indicate that a nun-numeric value has been presented, which would result in 0.00 - what I would suggest is wrapping the code in a call to is_numeric()...

  if (is_numeric($price))
  {
    $price = number_format($price,2,".","");
  }

It would then be down to the database what to make of the price value - what I would suggest is after making the above mod re-import and then search for all products using the query;

bw:

...and then order by Price / Low-to-High. If you have ended up with lots of 0.00 prices let me know and I'll check it out further with you...

Cheers,
David.
--
PriceTapestry.com