mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 01:25:55 +02:00
Made mouser price info parsing more flexible
Austrian mouser returned some other formatted string, which caused problems on the old method. This fixes issue #540
This commit is contained in:
parent
0e68f0783f
commit
2bcbe1d0be
1 changed files with 9 additions and 0 deletions
|
@ -247,10 +247,19 @@ class MouserProvider implements InfoProviderInterface
|
||||||
/*
|
/*
|
||||||
* Mouser API price is a string in the form "n[.,]nnn[.,] currency"
|
* Mouser API price is a string in the form "n[.,]nnn[.,] currency"
|
||||||
* then this convert it to a number
|
* then this convert it to a number
|
||||||
|
* Austria has a format like "€ 2,10"
|
||||||
*/
|
*/
|
||||||
private function priceStrToFloat($val): float
|
private function priceStrToFloat($val): float
|
||||||
{
|
{
|
||||||
|
//Remove any character that is not a number, dot or comma (like currency symbols)
|
||||||
|
$val = preg_replace('/[^0-9.,]/', '', $val);
|
||||||
|
|
||||||
|
//Trim the string
|
||||||
|
$val = trim($val);
|
||||||
|
|
||||||
|
//Convert commas to dots
|
||||||
$val = str_replace(",", ".", $val);
|
$val = str_replace(",", ".", $val);
|
||||||
|
//Remove any dot that is not the last one (to avoid problems with thousands separators)
|
||||||
$val = preg_replace('/\.(?=.*\.)/', '', $val);
|
$val = preg_replace('/\.(?=.*\.)/', '', $val);
|
||||||
return (float)$val;
|
return (float)$val;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue