Skip to content

Commit 919bf49

Browse files
committed
Fix the wrong currency code mouser returns for chinese yuan
This fixes issue #1045
1 parent 001f2e9 commit 919bf49

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/Services/InfoProviderSystem/Providers/MouserProvider.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,17 @@ private function priceStrToFloat($val): float
305305
return (float)$val;
306306
}
307307

308+
private function mapCurrencyCode(string $currency): string
309+
{
310+
//Mouser uses "RMB" for Chinese Yuan, but the correct ISO code is "CNY"
311+
if ($currency === "RMB") {
312+
return "CNY";
313+
}
314+
315+
//For all other currencies, we assume that the ISO code is correct
316+
return $currency;
317+
}
318+
308319
/**
309320
* Converts the pricing (StandardPricing field) from the Mouser API to an array of PurchaseInfoDTOs
310321
* @param array $price_breaks
@@ -321,7 +332,7 @@ private function pricingToDTOs(array $price_breaks, string $order_number, string
321332
$prices[] = new PriceDTO(
322333
minimum_discount_amount: $price_break['Quantity'],
323334
price: (string)$number,
324-
currency_iso_code: $price_break['Currency']
335+
currency_iso_code: $this->mapCurrencyCode($price_break['Currency'])
325336
);
326337
}
327338

0 commit comments

Comments
 (0)