Use newer version of farnell/element14 api to get the correct links to product pages. Also we can now retrieve a more detailed description, which will be put into the notes field

This commit is contained in:
Jan Böhmer 2025-02-22 23:29:57 +01:00
parent 319b69f6c7
commit 5d3f861728

View file

@ -35,7 +35,7 @@ class Element14Provider implements InfoProviderInterface
{
private const ENDPOINT_URL = 'https://api.element14.com/catalog/products';
private const API_VERSION_NUMBER = '1.2';
private const API_VERSION_NUMBER = '1.4';
private const NUMBER_OF_RESULTS = 20;
public const DISTRIBUTOR_NAME = 'Farnell';
@ -83,7 +83,7 @@ class Element14Provider implements InfoProviderInterface
'resultsSettings.responseGroup' => 'large',
'callInfo.apiKey' => $this->api_key,
'callInfo.responseDataFormat' => 'json',
'callInfo.version' => self::API_VERSION_NUMBER,
'versionNumber' => self::API_VERSION_NUMBER,
],
]);
@ -107,21 +107,18 @@ class Element14Provider implements InfoProviderInterface
mpn: $product['translatedManufacturerPartNumber'],
preview_image_url: $this->toImageUrl($product['image'] ?? null),
manufacturing_status: $this->releaseStatusCodeToManufacturingStatus($product['releaseStatusCode'] ?? null),
provider_url: $this->generateProductURL($product['sku']),
provider_url: $product['productURL'],
notes: $product['productOverview']['description'] ?? null,
datasheets: $this->parseDataSheets($product['datasheets'] ?? null),
parameters: $this->attributesToParameters($product['attributes'] ?? null),
vendor_infos: $this->pricesToVendorInfo($product['sku'], $product['prices'] ?? [])
vendor_infos: $this->pricesToVendorInfo($product['sku'], $product['prices'] ?? [], $product['productURL']),
);
}
return $result;
}
private function generateProductURL($sku): string
{
return 'https://' . $this->store_id . '/' . $sku;
}
/**
* @param array|null $datasheets
* @return FileDTO[]|null Array of FileDTOs
@ -161,7 +158,7 @@ class Element14Provider implements InfoProviderInterface
* @param array $prices
* @return array
*/
private function pricesToVendorInfo(string $sku, array $prices): array
private function pricesToVendorInfo(string $sku, array $prices, string $product_url): array
{
$price_dtos = [];
@ -179,7 +176,7 @@ class Element14Provider implements InfoProviderInterface
distributor_name: self::DISTRIBUTOR_NAME,
order_number: $sku,
prices: $price_dtos,
product_url: $this->generateProductURL($sku)
product_url: $product_url
)
];
}