Retrieve the part mass from mouser API if available

This commit is contained in:
Jan Böhmer 2024-03-09 21:34:05 +01:00
parent 1e6065f732
commit c989be2719

View file

@ -210,6 +210,16 @@ class MouserProvider implements InfoProviderInterface
$result = [];
foreach ($products as $product) {
//Check if we have a mass field available
$mass = null;
if (isset($product['UnitWeightKg']['UnitWeight'])) {
$mass = (float) $product['UnitWeightKg']['UnitWeight'];
//The mass is given in kg, we want it in g
$mass *= 1000;
}
$result[] = new PartDetailDTO(
provider_key: $this->getProviderKey(),
provider_id: $product['MouserPartNumber'],
@ -228,6 +238,7 @@ class MouserProvider implements InfoProviderInterface
$product['MouserPartNumber'] ?? null),
vendor_infos: $this->pricingToDTOs($product['PriceBreaks'] ?? [], $product['MouserPartNumber'],
$product['ProductDetailUrl']),
mass: $mass,
);
}
return $result;