Use preview image and other additional images provided by the info provider

This commit is contained in:
Jan Böhmer 2023-07-15 21:41:35 +02:00
parent 701212239d
commit db97114fb4
2 changed files with 38 additions and 3 deletions

View file

@ -162,6 +162,30 @@ final class DTOtoEntityConverter
$entity->addParameter($this->convertParameter($parameter)); $entity->addParameter($this->convertParameter($parameter));
} }
//Add preview image
$image_type = $this->getImageType();
if ($dto->preview_image_url) {
$preview_image = new PartAttachment();
$preview_image->setURL($dto->preview_image_url);
$preview_image->setName('Main image');
$preview_image->setAttachmentType($image_type);
$entity->addAttachment($preview_image);
$entity->setMasterPictureAttachment($preview_image);
}
//Add other images
foreach ($dto->images ?? [] as $image) {
//Ensure that the image is not the same as the preview image
if ($image->url === $dto->preview_image_url) {
continue;
}
$entity->addAttachment($this->convertFile($image, $image_type));
}
//Add datasheets //Add datasheets
$datasheet_type = $this->getDatasheetType(); $datasheet_type = $this->getDatasheetType();
foreach ($dto->datasheets ?? [] as $datasheet) { foreach ($dto->datasheets ?? [] as $datasheet) {

View file

@ -86,7 +86,7 @@ class TMEProvider implements InfoProviderInterface
$result[] = new SearchResultDTO( $result[] = new SearchResultDTO(
provider_key: $this->getProviderKey(), provider_key: $this->getProviderKey(),
provider_id: $product['Symbol'], provider_id: $product['Symbol'],
name: $product['OriginalSymbol'] ?? $product['Symbol'], name: !empty($product['OriginalSymbol']) ? $product['OriginalSymbol'] : $product['Symbol'],
description: $product['Description'], description: $product['Description'],
category: $product['Category'], category: $product['Category'],
manufacturer: $product['Producer'], manufacturer: $product['Producer'],
@ -122,7 +122,7 @@ class TMEProvider implements InfoProviderInterface
return new PartDetailDTO( return new PartDetailDTO(
provider_key: $this->getProviderKey(), provider_key: $this->getProviderKey(),
provider_id: $product['Symbol'], provider_id: $product['Symbol'],
name: $product['OriginalSymbol'] ?? $product['Symbol'], name: !empty($product['OriginalSymbol']) ? $product['OriginalSymbol'] : $product['Symbol'],
description: $product['Description'], description: $product['Description'],
category: $product['Category'], category: $product['Category'],
manufacturer: $product['Producer'], manufacturer: $product['Producer'],
@ -132,6 +132,7 @@ class TMEProvider implements InfoProviderInterface
provider_url: $productInfoPage, provider_url: $productInfoPage,
footprint: $footprint, footprint: $footprint,
datasheets: $files['datasheets'], datasheets: $files['datasheets'],
images: $files['images'],
parameters: $parameters, parameters: $parameters,
vendor_infos: [$this->getVendorInfo($id, $productInfoPage)], vendor_infos: [$this->getVendorInfo($id, $productInfoPage)],
mass: $product['WeightUnit'] === 'g' ? $product['Weight'] : null, mass: $product['WeightUnit'] === 'g' ? $product['Weight'] : null,
@ -142,7 +143,7 @@ class TMEProvider implements InfoProviderInterface
* Fetches all files for a given product id * Fetches all files for a given product id
* @param string $id * @param string $id
* @return array<string, list<FileDTO>> An array with the keys 'datasheet' * @return array<string, list<FileDTO>> An array with the keys 'datasheet'
* @phpstan-return array{datasheets: list<FileDTO>} * @phpstan-return array{datasheets: list<FileDTO>, images: list<FileDTO>}
*/ */
public function getFiles(string $id): array public function getFiles(string $id): array
{ {
@ -164,9 +165,19 @@ class TMEProvider implements InfoProviderInterface
); );
} }
//Extract images
$imageList = $files['AdditionalPhotoList'];
$images = [];
foreach($imageList as $image) {
$images[] = new FileDTO(
url: $this->normalizeURL($image['HighResolutionPhoto']),
);
}
return [ return [
'datasheets' => $datasheets, 'datasheets' => $datasheets,
'images' => $images,
]; ];
} }