mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-09 09:54:33 +02:00
Get datasheets and category from digikey
This commit is contained in:
parent
01d9109c45
commit
412fa3f0bf
1 changed files with 48 additions and 1 deletions
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||||
namespace App\Services\InfoProviderSystem\Providers;
|
namespace App\Services\InfoProviderSystem\Providers;
|
||||||
|
|
||||||
use App\Entity\Parts\ManufacturingStatus;
|
use App\Entity\Parts\ManufacturingStatus;
|
||||||
|
use App\Services\InfoProviderSystem\DTOs\FileDTO;
|
||||||
use App\Services\InfoProviderSystem\DTOs\ParameterDTO;
|
use App\Services\InfoProviderSystem\DTOs\ParameterDTO;
|
||||||
use App\Services\InfoProviderSystem\DTOs\PartDetailDTO;
|
use App\Services\InfoProviderSystem\DTOs\PartDetailDTO;
|
||||||
use App\Services\InfoProviderSystem\DTOs\PriceDTO;
|
use App\Services\InfoProviderSystem\DTOs\PriceDTO;
|
||||||
|
@ -116,7 +117,8 @@ class DigikeyProvider implements InfoProviderInterface
|
||||||
provider_key: $this->getProviderKey(),
|
provider_key: $this->getProviderKey(),
|
||||||
provider_id: $product['DigiKeyPartNumber'],
|
provider_id: $product['DigiKeyPartNumber'],
|
||||||
name: $product['ManufacturerPartNumber'],
|
name: $product['ManufacturerPartNumber'],
|
||||||
description: $product['ProductDescription'],
|
description: $product['DetailedDescription'] ?? $product['ProductDescription'],
|
||||||
|
category: $this->getCategoryString($product),
|
||||||
manufacturer: $product['Manufacturer']['Value'] ?? null,
|
manufacturer: $product['Manufacturer']['Value'] ?? null,
|
||||||
mpn: $product['ManufacturerPartNumber'],
|
mpn: $product['ManufacturerPartNumber'],
|
||||||
preview_image_url: $product['PrimaryPhoto'] ?? null,
|
preview_image_url: $product['PrimaryPhoto'] ?? null,
|
||||||
|
@ -138,18 +140,22 @@ class DigikeyProvider implements InfoProviderInterface
|
||||||
|
|
||||||
$footprint = null;
|
$footprint = null;
|
||||||
$parameters = $this->parametersToDTOs($product['Parameters'] ?? [], $footprint);
|
$parameters = $this->parametersToDTOs($product['Parameters'] ?? [], $footprint);
|
||||||
|
$media = $this->mediaToDTOs($product['MediaLinks']);
|
||||||
|
|
||||||
return new PartDetailDTO(
|
return new PartDetailDTO(
|
||||||
provider_key: $this->getProviderKey(),
|
provider_key: $this->getProviderKey(),
|
||||||
provider_id: $product['DigiKeyPartNumber'],
|
provider_id: $product['DigiKeyPartNumber'],
|
||||||
name: $product['ManufacturerPartNumber'],
|
name: $product['ManufacturerPartNumber'],
|
||||||
description: $product['DetailedDescription'] ?? $product['ProductDescription'],
|
description: $product['DetailedDescription'] ?? $product['ProductDescription'],
|
||||||
|
category: $this->getCategoryString($product),
|
||||||
manufacturer: $product['Manufacturer']['Value'] ?? null,
|
manufacturer: $product['Manufacturer']['Value'] ?? null,
|
||||||
mpn: $product['ManufacturerPartNumber'],
|
mpn: $product['ManufacturerPartNumber'],
|
||||||
preview_image_url: $product['PrimaryPhoto'] ?? null,
|
preview_image_url: $product['PrimaryPhoto'] ?? null,
|
||||||
manufacturing_status: $this->productStatusToManufacturingStatus($product['ProductStatus']),
|
manufacturing_status: $this->productStatusToManufacturingStatus($product['ProductStatus']),
|
||||||
provider_url: $product['ProductUrl'],
|
provider_url: $product['ProductUrl'],
|
||||||
footprint: $footprint,
|
footprint: $footprint,
|
||||||
|
datasheets: $media['datasheets'],
|
||||||
|
images: $media['images'],
|
||||||
parameters: $parameters,
|
parameters: $parameters,
|
||||||
vendor_infos: $this->pricingToDTOs($product['StandardPricing'] ?? [], $product['DigiKeyPartNumber'], $product['ProductUrl']),
|
vendor_infos: $this->pricingToDTOs($product['StandardPricing'] ?? [], $product['DigiKeyPartNumber'], $product['ProductUrl']),
|
||||||
);
|
);
|
||||||
|
@ -174,6 +180,17 @@ class DigikeyProvider implements InfoProviderInterface
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getCategoryString(array $product): string
|
||||||
|
{
|
||||||
|
$category = $product['Category']['Value'];
|
||||||
|
$sub_category = $product['Family']['Value'];
|
||||||
|
|
||||||
|
//Replace the ' - ' category separator with ' -> '
|
||||||
|
$sub_category = str_replace(' - ', ' -> ', $sub_category);
|
||||||
|
|
||||||
|
return $category . ' -> ' . $sub_category;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function converts the "Parameters" part of the Digikey API response to an array of ParameterDTOs
|
* This function converts the "Parameters" part of the Digikey API response to an array of ParameterDTOs
|
||||||
* @param array $parameters
|
* @param array $parameters
|
||||||
|
@ -216,4 +233,34 @@ class DigikeyProvider implements InfoProviderInterface
|
||||||
new PurchaseInfoDTO(distributor_name: self::VENDOR_NAME, order_number: $order_number, prices: $prices, product_url: $product_url)
|
new PurchaseInfoDTO(distributor_name: self::VENDOR_NAME, order_number: $order_number, prices: $prices, product_url: $product_url)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $media_links
|
||||||
|
* @return FileDTO[][]
|
||||||
|
* @phpstan-return array<string, FileDTO[]>
|
||||||
|
*/
|
||||||
|
private function mediaToDTOs(array $media_links): array
|
||||||
|
{
|
||||||
|
$datasheets = [];
|
||||||
|
$images = [];
|
||||||
|
|
||||||
|
foreach ($media_links as $media_link) {
|
||||||
|
$file = new FileDTO(url: $media_link['Url'], name: $media_link['Title']);
|
||||||
|
|
||||||
|
switch ($media_link['MediaType']) {
|
||||||
|
case 'Datasheets':
|
||||||
|
$datasheets[] = $file;
|
||||||
|
break;
|
||||||
|
case 'Product Photos':
|
||||||
|
$images[] = $file;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'datasheets' => $datasheets,
|
||||||
|
'images' => $images,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue