mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 01:25:55 +02:00
Allow to configure various options of the octopart provider
This commit is contained in:
parent
827dd01e28
commit
f7cea1100c
4 changed files with 49 additions and 15 deletions
|
@ -39,6 +39,7 @@
|
||||||
PassEnv PROVIDER_DIGIKEY_CLIENT_ID PROVIDER_DIGIKEY_SECRET PROVIDER_DIGIKEY_CURRENCY PROVIDER_DIGIKEY_LANGUAGE PROVIDER_DIGIKEY_COUNTRY
|
PassEnv PROVIDER_DIGIKEY_CLIENT_ID PROVIDER_DIGIKEY_SECRET PROVIDER_DIGIKEY_CURRENCY PROVIDER_DIGIKEY_LANGUAGE PROVIDER_DIGIKEY_COUNTRY
|
||||||
PassEnv PROVIDER_ELEMENT14_KEY PROVIDER_ELEMENT14_STORE_ID
|
PassEnv PROVIDER_ELEMENT14_KEY PROVIDER_ELEMENT14_STORE_ID
|
||||||
PassEnv PROVIDER_TME_KEY PROVIDER_TME_SECRET PROVIDER_TME_CURRENCY PROVIDER_TME_LANGUAGE PROVIDER_TME_COUNTRY PROVIDER_TME_GET_GROSS_PRICES
|
PassEnv PROVIDER_TME_KEY PROVIDER_TME_SECRET PROVIDER_TME_CURRENCY PROVIDER_TME_LANGUAGE PROVIDER_TME_COUNTRY PROVIDER_TME_GET_GROSS_PRICES
|
||||||
|
PassEnv PROVIDER_OCTOPART_CLIENT_ID PROVIDER_OCTOPART_SECRET PROVIDER_OCTOPART_CURRENCY PROVIDER_OCTOPART_COUNTRY PROVIDER_OCTOPART_SEARCH_LIMIT PROVIDER_OCTOPART_ONLY_AUTHORIZED_SELLERS
|
||||||
|
|
||||||
# For most configuration files from conf-available/, which are
|
# For most configuration files from conf-available/, which are
|
||||||
# enabled or disabled at a global level, it is possible to
|
# enabled or disabled at a global level, it is possible to
|
||||||
|
|
14
.env
14
.env
|
@ -125,6 +125,20 @@ PROVIDER_TME_COUNTRY=DE
|
||||||
# Set this to 1 to get gross prices (including VAT) instead of net prices
|
# Set this to 1 to get gross prices (including VAT) instead of net prices
|
||||||
PROVIDER_TME_GET_GROSS_PRICES=1
|
PROVIDER_TME_GET_GROSS_PRICES=1
|
||||||
|
|
||||||
|
# Octopart / Nexar Provider:
|
||||||
|
# You can get your API key from https://nexar.com/api
|
||||||
|
PROVIDER_OCTOPART_CLIENT_ID=
|
||||||
|
PROVIDER_OCTOPART_SECRET=
|
||||||
|
# The currency and country to get prices for (you have to set both to get meaningful results)
|
||||||
|
# 3 letter ISO currency code (e.g. EUR, USD, GBP)
|
||||||
|
PROVIDER_OCTOPART_CURRENCY=EUR
|
||||||
|
# 2 letter ISO country code (e.g. DE, US, GB)
|
||||||
|
PROVIDER_OCTOPART_COUNTRY=DE
|
||||||
|
# The number of results to get from Octopart while searching (please note that this counts towards your API limits)
|
||||||
|
PROVIDER_OCTOPART_SEARCH_LIMIT=10
|
||||||
|
# Set to false to include non authorized offers in the results
|
||||||
|
PROVIDER_OCTOPART_ONLY_AUTHORIZED_SELLERS=1
|
||||||
|
|
||||||
|
|
||||||
###################################################################################
|
###################################################################################
|
||||||
# SAML Single sign on-settings
|
# SAML Single sign on-settings
|
||||||
|
|
|
@ -268,6 +268,15 @@ services:
|
||||||
$language: '%env(string:PROVIDER_TME_LANGUAGE)%'
|
$language: '%env(string:PROVIDER_TME_LANGUAGE)%'
|
||||||
$get_gross_prices: '%env(bool:PROVIDER_TME_GET_GROSS_PRICES)%'
|
$get_gross_prices: '%env(bool:PROVIDER_TME_GET_GROSS_PRICES)%'
|
||||||
|
|
||||||
|
App\Services\InfoProviderSystem\Providers\OctopartProvider:
|
||||||
|
arguments:
|
||||||
|
$clientId: '&env(string:PROVIDER_OCTOPART_CLIENT_ID)%'
|
||||||
|
$secret: '%env(string:PROVIDER_OCTOPART_SECRET)%'
|
||||||
|
$country: '%env(string:PROVIDER_OCTOPART_COUNTRY)%'
|
||||||
|
$currency: '%env(string:PROVIDER_OCTOPART_CURRENCY)%'
|
||||||
|
$search_limit: '%env(int:PROVIDER_OCTOPART_SEARCH_LIMIT)%'
|
||||||
|
$onlyAuthorizedSellers: '%env(bool:PROVIDER_OCTOPART_ONLY_AUTHORIZED_SELLERS)%'
|
||||||
|
|
||||||
####################################################################################################################
|
####################################################################################################################
|
||||||
# Symfony overrides
|
# Symfony overrides
|
||||||
####################################################################################################################
|
####################################################################################################################
|
||||||
|
|
|
@ -31,7 +31,6 @@ use App\Services\InfoProviderSystem\DTOs\PriceDTO;
|
||||||
use App\Services\InfoProviderSystem\DTOs\PurchaseInfoDTO;
|
use App\Services\InfoProviderSystem\DTOs\PurchaseInfoDTO;
|
||||||
use App\Services\OAuth\OAuthTokenManager;
|
use App\Services\OAuth\OAuthTokenManager;
|
||||||
use Symfony\Component\HttpClient\HttpOptions;
|
use Symfony\Component\HttpClient\HttpOptions;
|
||||||
use Symfony\Component\HttpClient\NativeHttpClient;
|
|
||||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
|
|
||||||
class OctopartProvider implements InfoProviderInterface
|
class OctopartProvider implements InfoProviderInterface
|
||||||
|
@ -67,7 +66,7 @@ class OctopartProvider implements InfoProviderInterface
|
||||||
currency
|
currency
|
||||||
quantity
|
quantity
|
||||||
}
|
}
|
||||||
sellers(authorizedOnly: true) {
|
sellers(authorizedOnly: $authorizedOnly) {
|
||||||
company {
|
company {
|
||||||
name
|
name
|
||||||
}
|
}
|
||||||
|
@ -105,7 +104,10 @@ class OctopartProvider implements InfoProviderInterface
|
||||||
|
|
||||||
|
|
||||||
public function __construct(private readonly HttpClientInterface $httpClient,
|
public function __construct(private readonly HttpClientInterface $httpClient,
|
||||||
private readonly OAuthTokenManager $authTokenManager)
|
private readonly OAuthTokenManager $authTokenManager,
|
||||||
|
private readonly string $clientId, private readonly string $secret,
|
||||||
|
private readonly string $currency, private readonly string $country,
|
||||||
|
private readonly int $search_limit, private readonly bool $onlyAuthorizedSellers)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -172,7 +174,7 @@ class OctopartProvider implements InfoProviderInterface
|
||||||
{
|
{
|
||||||
//The client ID has to be set and a token has to be available (user clicked connect)
|
//The client ID has to be set and a token has to be available (user clicked connect)
|
||||||
//return /*!empty($this->clientId) && */ $this->authTokenManager->hasToken(self::OAUTH_APP_NAME);
|
//return /*!empty($this->clientId) && */ $this->authTokenManager->hasToken(self::OAUTH_APP_NAME);
|
||||||
return true;
|
return !empty($this->clientId) && !empty($this->secret);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function mapLifeCycleStatus(?string $value): ?ManufacturingStatus
|
private function mapLifeCycleStatus(?string $value): ?ManufacturingStatus
|
||||||
|
@ -251,30 +253,32 @@ class OctopartProvider implements InfoProviderInterface
|
||||||
provider_key: $this->getProviderKey(),
|
provider_key: $this->getProviderKey(),
|
||||||
provider_id: $part['id'],
|
provider_id: $part['id'],
|
||||||
name: $part['mpn'],
|
name: $part['mpn'],
|
||||||
description: $part['shortDescription'],
|
description: $part['shortDescription'] ?? null,
|
||||||
category: $part['category']['name'],
|
category: $part['category']['name'] ?? null,
|
||||||
manufacturer: $part['manufacturer']['name'],
|
manufacturer: $part['manufacturer']['name'] ?? null,
|
||||||
mpn: $part['mpn'],
|
mpn: $part['mpn'],
|
||||||
preview_image_url: $part['bestImage']['url'],
|
preview_image_url: $part['bestImage']['url'] ?? null,
|
||||||
manufacturing_status: $mStatus,
|
manufacturing_status: $mStatus,
|
||||||
provider_url: $part['octopartUrl'],
|
provider_url: $part['octopartUrl'] ?? null,
|
||||||
footprint: $footprint,
|
footprint: $footprint,
|
||||||
datasheets: [new FileDTO($part['bestDatasheet']['url'], $part['bestDatasheet']['name'])],
|
datasheets: $part['bestDatasheet'] !== null ? [new FileDTO($part['bestDatasheet']['url'], $part['bestDatasheet']['name'])]: null,
|
||||||
parameters: $parameters,
|
parameters: $parameters,
|
||||||
vendor_infos: $orderinfos,
|
vendor_infos: $orderinfos,
|
||||||
mass: $mass,
|
mass: $mass,
|
||||||
manufacturer_product_url: $part['manufacturerUrl'],
|
manufacturer_product_url: $part['manufacturerUrl'] ?? null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function searchByKeyword(string $keyword): array
|
public function searchByKeyword(string $keyword): array
|
||||||
{
|
{
|
||||||
$graphQL = sprintf(<<<'GRAPHQL'
|
$graphQL = sprintf(<<<'GRAPHQL'
|
||||||
query partSearch($keyword: String, $limit: Int) {
|
query partSearch($keyword: String, $limit: Int, $currency: String!, $country: String!, $authorizedOnly: Boolean!) {
|
||||||
supSearch(
|
supSearch(
|
||||||
q: $keyword
|
q: $keyword
|
||||||
inStockOnly: false
|
inStockOnly: false
|
||||||
limit: $limit
|
limit: $limit
|
||||||
|
currency: $currency
|
||||||
|
country: $country
|
||||||
) {
|
) {
|
||||||
hits
|
hits
|
||||||
results {
|
results {
|
||||||
|
@ -288,7 +292,10 @@ class OctopartProvider implements InfoProviderInterface
|
||||||
|
|
||||||
$result = $this->makeGraphQLCall($graphQL, [
|
$result = $this->makeGraphQLCall($graphQL, [
|
||||||
'keyword' => $keyword,
|
'keyword' => $keyword,
|
||||||
'limit' => 4,
|
'limit' => $this->search_limit,
|
||||||
|
'currency' => $this->currency,
|
||||||
|
'country' => $this->country,
|
||||||
|
'authorizedOnly' => $this->onlyAuthorizedSellers,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$tmp = [];
|
$tmp = [];
|
||||||
|
@ -305,14 +312,17 @@ class OctopartProvider implements InfoProviderInterface
|
||||||
public function getDetails(string $id): PartDetailDTO
|
public function getDetails(string $id): PartDetailDTO
|
||||||
{
|
{
|
||||||
$graphql = sprintf(<<<'GRAPHQL'
|
$graphql = sprintf(<<<'GRAPHQL'
|
||||||
query partSearch($ids: [String!]!) {
|
query partSearch($ids: [String!]!, $currency: String!, $country: String!, $authorizedOnly: Boolean!) {
|
||||||
supParts(ids: $ids)
|
supParts(ids: $ids, currency: $currency, country: $country)
|
||||||
%s
|
%s
|
||||||
}
|
}
|
||||||
GRAPHQL, self::GRAPHQL_PART_SECTION);
|
GRAPHQL, self::GRAPHQL_PART_SECTION);
|
||||||
|
|
||||||
$result = $this->makeGraphQLCall($graphql, [
|
$result = $this->makeGraphQLCall($graphql, [
|
||||||
'ids' => [$id],
|
'ids' => [$id],
|
||||||
|
'currency' => $this->currency,
|
||||||
|
'country' => $this->country,
|
||||||
|
'authorizedOnly' => $this->onlyAuthorizedSellers,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $this->partResultToDTO($result['data']['supParts'][0]);
|
return $this->partResultToDTO($result['data']['supParts'][0]);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue