mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-07-27 03:31:35 +00:00
parent
a47e56bd93
commit
c6983c6516
1 changed files with 22 additions and 13 deletions
|
|
@ -136,7 +136,9 @@ class LCSCProvider implements BatchInfoProviderInterface, URLHandlerInfoProvider
|
|||
}
|
||||
}
|
||||
|
||||
$response = $this->lcscClient->request('POST', self::ENDPOINT_URL . "/search/v2/global", [
|
||||
//First we try the search v3 endpoint, which seems to give better results including pictures, but it only works
|
||||
//on quite exact mpn matches
|
||||
$response = $this->lcscClient->request('POST', self::ENDPOINT_URL . "/search/v3/global", [
|
||||
'headers' => [
|
||||
'Cookie' => new Cookie('currencyCode', $this->settings->currency)
|
||||
],
|
||||
|
|
@ -147,18 +149,25 @@ class LCSCProvider implements BatchInfoProviderInterface, URLHandlerInfoProvider
|
|||
|
||||
$arr = $response->toArray();
|
||||
|
||||
// Get products list
|
||||
$products = $arr['result']['productSearchResultVO']['productList'] ?? [];
|
||||
// Get product tip
|
||||
$tipProductCode = $arr['result']['tipProductDetailUrlVO']['productCode'] ?? null;
|
||||
//If we get exact matches, use them
|
||||
if (!empty($arr['result']['exactMatchResult'])) {
|
||||
$products = $arr['result']['a'];
|
||||
} else { //Otherwise fallback onto the third search endpoint, which has a worse data quality but is more likely to return results for vague search terms
|
||||
$response = $this->lcscClient->request('POST', self::ENDPOINT_URL."/search/third", [
|
||||
'headers' => [
|
||||
'Cookie' => new Cookie('currencyCode', $this->settings->currency)
|
||||
],
|
||||
'json' => [
|
||||
'keyword' => $term,
|
||||
'currentPage' => 1,
|
||||
'pageSize' => 10,
|
||||
],
|
||||
]);
|
||||
|
||||
$result = [];
|
||||
$arr = $response->toArray();
|
||||
|
||||
// LCSC does not display LCSC codes in the search, instead taking you directly to the
|
||||
// detailed product listing. It does so utilizing a product tip field.
|
||||
// If product tip exists and there are no products in the product list try a detail query
|
||||
if (count($products) === 0 && $tipProductCode !== null) {
|
||||
$result[] = $this->queryDetail($tipProductCode, $lightweight);
|
||||
// Get products list
|
||||
$products = $arr['result']['productList'] ?? [];
|
||||
}
|
||||
|
||||
foreach ($products as $product) {
|
||||
|
|
@ -219,7 +228,7 @@ class LCSCProvider implements BatchInfoProviderInterface, URLHandlerInfoProvider
|
|||
provider_key: $this->getProviderKey(),
|
||||
provider_id: $product['productCode'],
|
||||
name: $product['productModel'],
|
||||
description: $this->sanitizeField($product['productIntroEn']),
|
||||
description: $this->sanitizeField($product['productIntroEn']) ?? '',
|
||||
category: $this->sanitizeField($category ?? null),
|
||||
manufacturer: $this->sanitizeField($product['brandNameEn'] ?? null),
|
||||
mpn: $this->sanitizeField($product['productModel'] ?? null),
|
||||
|
|
@ -383,7 +392,7 @@ class LCSCProvider implements BatchInfoProviderInterface, URLHandlerInfoProvider
|
|||
]);
|
||||
} else {
|
||||
// Search API call for other terms
|
||||
$responses[$keyword] = $this->lcscClient->request('POST', self::ENDPOINT_URL . "/search/v2/global", [
|
||||
$responses[$keyword] = $this->lcscClient->request('POST', self::ENDPOINT_URL . "/search/v3/global", [
|
||||
'headers' => [
|
||||
'Cookie' => new Cookie('currencyCode', $this->settings->currency)
|
||||
],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue