Skip to content

Commit 5d3f861

Browse files
committed
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
1 parent 319b69f commit 5d3f861

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/Services/InfoProviderSystem/Providers/Element14Provider.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Element14Provider implements InfoProviderInterface
3535
{
3636

3737
private const ENDPOINT_URL = 'https://api.element14.com/catalog/products';
38-
private const API_VERSION_NUMBER = '1.2';
38+
private const API_VERSION_NUMBER = '1.4';
3939
private const NUMBER_OF_RESULTS = 20;
4040

4141
public const DISTRIBUTOR_NAME = 'Farnell';
@@ -83,7 +83,7 @@ private function queryByTerm(string $term): array
8383
'resultsSettings.responseGroup' => 'large',
8484
'callInfo.apiKey' => $this->api_key,
8585
'callInfo.responseDataFormat' => 'json',
86-
'callInfo.version' => self::API_VERSION_NUMBER,
86+
'versionNumber' => self::API_VERSION_NUMBER,
8787
],
8888
]);
8989

@@ -107,21 +107,18 @@ private function queryByTerm(string $term): array
107107
mpn: $product['translatedManufacturerPartNumber'],
108108
preview_image_url: $this->toImageUrl($product['image'] ?? null),
109109
manufacturing_status: $this->releaseStatusCodeToManufacturingStatus($product['releaseStatusCode'] ?? null),
110-
provider_url: $this->generateProductURL($product['sku']),
110+
provider_url: $product['productURL'],
111+
notes: $product['productOverview']['description'] ?? null,
111112
datasheets: $this->parseDataSheets($product['datasheets'] ?? null),
112113
parameters: $this->attributesToParameters($product['attributes'] ?? null),
113-
vendor_infos: $this->pricesToVendorInfo($product['sku'], $product['prices'] ?? [])
114+
vendor_infos: $this->pricesToVendorInfo($product['sku'], $product['prices'] ?? [], $product['productURL']),
115+
114116
);
115117
}
116118

117119
return $result;
118120
}
119121

120-
private function generateProductURL($sku): string
121-
{
122-
return 'https://' . $this->store_id . '/' . $sku;
123-
}
124-
125122
/**
126123
* @param array|null $datasheets
127124
* @return FileDTO[]|null Array of FileDTOs
@@ -161,7 +158,7 @@ private function toImageUrl(?array $image): ?string
161158
* @param array $prices
162159
* @return array
163160
*/
164-
private function pricesToVendorInfo(string $sku, array $prices): array
161+
private function pricesToVendorInfo(string $sku, array $prices, string $product_url): array
165162
{
166163
$price_dtos = [];
167164

@@ -179,7 +176,7 @@ private function pricesToVendorInfo(string $sku, array $prices): array
179176
distributor_name: self::DISTRIBUTOR_NAME,
180177
order_number: $sku,
181178
prices: $price_dtos,
182-
product_url: $this->generateProductURL($sku)
179+
product_url: $product_url
183180
)
184181
];
185182
}

0 commit comments

Comments
 (0)