mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 09:35:49 +02:00
Assume that a mouser part is active, if mouser has parts instock even if it is marked as "new part"
Related to #540
This commit is contained in:
parent
91e8711fdf
commit
0e68f0783f
1 changed files with 18 additions and 3 deletions
|
@ -207,6 +207,7 @@ class MouserProvider implements InfoProviderInterface
|
||||||
} else {
|
} else {
|
||||||
throw new \RuntimeException('Unknown response format');
|
throw new \RuntimeException('Unknown response format');
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = [];
|
$result = [];
|
||||||
foreach ($products as $product) {
|
foreach ($products as $product) {
|
||||||
$result[] = new PartDetailDTO(
|
$result[] = new PartDetailDTO(
|
||||||
|
@ -218,7 +219,10 @@ class MouserProvider implements InfoProviderInterface
|
||||||
manufacturer: $product['Manufacturer'],
|
manufacturer: $product['Manufacturer'],
|
||||||
mpn: $product['ManufacturerPartNumber'],
|
mpn: $product['ManufacturerPartNumber'],
|
||||||
preview_image_url: $product['ImagePath'],
|
preview_image_url: $product['ImagePath'],
|
||||||
manufacturing_status: $this->releaseStatusCodeToManufacturingStatus($product['LifecycleStatus'] ?? null),
|
manufacturing_status: $this->releaseStatusCodeToManufacturingStatus(
|
||||||
|
$product['LifecycleStatus'] ?? null,
|
||||||
|
(int) ($product['AvailabilityInStock'] ?? 0)
|
||||||
|
),
|
||||||
provider_url: $product['ProductDetailUrl'],
|
provider_url: $product['ProductDetailUrl'],
|
||||||
datasheets: $this->parseDataSheets($product['DataSheetUrl'] ?? null,
|
datasheets: $this->parseDataSheets($product['DataSheetUrl'] ?? null,
|
||||||
$product['MouserPartNumber'] ?? null),
|
$product['MouserPartNumber'] ?? null),
|
||||||
|
@ -287,9 +291,15 @@ class MouserProvider implements InfoProviderInterface
|
||||||
|
|
||||||
TODO: Probably need to review the values of field Lifecyclestatus
|
TODO: Probably need to review the values of field Lifecyclestatus
|
||||||
*/
|
*/
|
||||||
private function releaseStatusCodeToManufacturingStatus(?string $productStatus): ?ManufacturingStatus
|
/**
|
||||||
|
* Converts the lifecycle status from the Mouser API to a ManufacturingStatus
|
||||||
|
* @param string|null $productStatus The lifecycle status from the Mouser API
|
||||||
|
* @param int $availableInStock The number of parts available in stock
|
||||||
|
* @return ManufacturingStatus|null
|
||||||
|
*/
|
||||||
|
private function releaseStatusCodeToManufacturingStatus(?string $productStatus, int $availableInStock = 0): ?ManufacturingStatus
|
||||||
{
|
{
|
||||||
return match ($productStatus) {
|
$tmp = match ($productStatus) {
|
||||||
null => null,
|
null => null,
|
||||||
"New Product" => ManufacturingStatus::ANNOUNCED,
|
"New Product" => ManufacturingStatus::ANNOUNCED,
|
||||||
"Not Recommended for New Designs" => ManufacturingStatus::NRFND,
|
"Not Recommended for New Designs" => ManufacturingStatus::NRFND,
|
||||||
|
@ -297,5 +307,10 @@ class MouserProvider implements InfoProviderInterface
|
||||||
"End of Life" => ManufacturingStatus::EOL,
|
"End of Life" => ManufacturingStatus::EOL,
|
||||||
default => ManufacturingStatus::ACTIVE,
|
default => ManufacturingStatus::ACTIVE,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//If the part would be assumed to be announced, check if it is in stock, then it is active
|
||||||
|
if ($tmp === ManufacturingStatus::ANNOUNCED && $availableInStock > 0) {
|
||||||
|
return ManufacturingStatus::ACTIVE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue