Fix the wrong currency code mouser returns for chinese yuan
Some checks are pending
Build assets artifact / Build assets artifact (push) Waiting to run
Docker Image Build / docker (push) Waiting to run
Docker Image Build (FrankenPHP) / docker (push) Waiting to run
Static analysis / Static analysis (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.2, mysql) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.3, mysql) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.4, mysql) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.5, mysql) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.2, postgres) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.3, postgres) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.4, postgres) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.5, postgres) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.2, sqlite) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.3, sqlite) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.4, sqlite) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.5, sqlite) (push) Waiting to run

This fixes issue #1045
This commit is contained in:
Jan Böhmer 2025-09-22 00:20:52 +02:00
parent 001f2e97ea
commit 919bf49ec1

View file

@ -305,6 +305,17 @@ class MouserProvider implements InfoProviderInterface
return (float)$val; return (float)$val;
} }
private function mapCurrencyCode(string $currency): string
{
//Mouser uses "RMB" for Chinese Yuan, but the correct ISO code is "CNY"
if ($currency === "RMB") {
return "CNY";
}
//For all other currencies, we assume that the ISO code is correct
return $currency;
}
/** /**
* Converts the pricing (StandardPricing field) from the Mouser API to an array of PurchaseInfoDTOs * Converts the pricing (StandardPricing field) from the Mouser API to an array of PurchaseInfoDTOs
* @param array $price_breaks * @param array $price_breaks
@ -321,7 +332,7 @@ class MouserProvider implements InfoProviderInterface
$prices[] = new PriceDTO( $prices[] = new PriceDTO(
minimum_discount_amount: $price_break['Quantity'], minimum_discount_amount: $price_break['Quantity'],
price: (string)$number, price: (string)$number,
currency_iso_code: $price_break['Currency'] currency_iso_code: $this->mapCurrencyCode($price_break['Currency'])
); );
} }