diff --git a/.env b/.env
index 0469f0eb..4b292298 100644
--- a/.env
+++ b/.env
@@ -67,23 +67,6 @@ ERROR_PAGE_ADMIN_EMAIL=''
# If this is set to true, solutions to common problems are shown on error pages. Disable this, if you do not want your users to see them...
ERROR_PAGE_SHOW_HELP=1
-##################################################################################
-# Info provider settings
-##################################################################################
-
-# 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
##################################################################################
# EDA integration related settings
diff --git a/config/packages/knpu_oauth2_client.yaml b/config/packages/knpu_oauth2_client.yaml
index d84b094d..5e56d5c5 100644
--- a/config/packages/knpu_oauth2_client.yaml
+++ b/config/packages/knpu_oauth2_client.yaml
@@ -26,8 +26,8 @@ knpu_oauth2_client:
type: generic
provider_class: '\League\OAuth2\Client\Provider\GenericProvider'
- client_id: '%env(PROVIDER_OCTOPART_CLIENT_ID)%'
- client_secret: '%env(PROVIDER_OCTOPART_SECRET)%'
+ client_id: '%env(settings:octopart:clientId)%'
+ client_secret: '%env(settings:octopart:secret)%'
redirect_route: 'oauth_client_check'
redirect_params: { name: 'ip_octopart_oauth' }
diff --git a/config/services.yaml b/config/services.yaml
index b65a4e78..6133dce7 100644
--- a/config/services.yaml
+++ b/config/services.yaml
@@ -199,16 +199,6 @@ services:
arguments:
$providers: !tagged_iterator 'app.info_provider'
- 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)%'
-
-
####################################################################################################################
# API system
####################################################################################################################
diff --git a/src/Services/InfoProviderSystem/Providers/OctopartProvider.php b/src/Services/InfoProviderSystem/Providers/OctopartProvider.php
index e28162ba..ce1ec4a4 100644
--- a/src/Services/InfoProviderSystem/Providers/OctopartProvider.php
+++ b/src/Services/InfoProviderSystem/Providers/OctopartProvider.php
@@ -30,6 +30,7 @@ use App\Services\InfoProviderSystem\DTOs\PartDetailDTO;
use App\Services\InfoProviderSystem\DTOs\PriceDTO;
use App\Services\InfoProviderSystem\DTOs\PurchaseInfoDTO;
use App\Services\OAuth\OAuthTokenManager;
+use App\Settings\InfoProviderSystem\OctopartSettings;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\HttpClient\HttpOptions;
use Symfony\Contracts\HttpClient\HttpClientInterface;
@@ -114,9 +115,8 @@ class OctopartProvider implements InfoProviderInterface
public function __construct(private readonly HttpClientInterface $httpClient,
private readonly OAuthTokenManager $authTokenManager, private readonly CacheItemPoolInterface $partInfoCache,
- 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)
+ private readonly OctopartSettings $settings,
+ )
{
}
@@ -183,7 +183,7 @@ class OctopartProvider implements InfoProviderInterface
{
//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 $this->clientId !== '' && $this->secret !== '';
+ return $this->settings->clientId !== '' && $this->settings->secret !== '';
}
private function mapLifeCycleStatus(?string $value): ?ManufacturingStatus
@@ -347,10 +347,10 @@ class OctopartProvider implements InfoProviderInterface
$result = $this->makeGraphQLCall($graphQL, [
'keyword' => $keyword,
- 'limit' => $this->search_limit,
- 'currency' => $this->currency,
- 'country' => $this->country,
- 'authorizedOnly' => $this->onlyAuthorizedSellers,
+ 'limit' => $this->settings->searchLimit,
+ 'currency' => $this->settings->currency,
+ 'country' => $this->settings->country,
+ 'authorizedOnly' => $this->settings->onlyAuthorizedSellers,
]);
$tmp = [];
@@ -383,9 +383,9 @@ class OctopartProvider implements InfoProviderInterface
$result = $this->makeGraphQLCall($graphql, [
'ids' => [$id],
- 'currency' => $this->currency,
- 'country' => $this->country,
- 'authorizedOnly' => $this->onlyAuthorizedSellers,
+ 'currency' => $this->settings->currency,
+ 'country' => $this->settings->country,
+ 'authorizedOnly' => $this->settings->onlyAuthorizedSellers,
]);
$tmp = $this->partResultToDTO($result['data']['supParts'][0]);
diff --git a/src/Settings/InfoProviderSystem/InfoProviderSettings.php b/src/Settings/InfoProviderSystem/InfoProviderSettings.php
index 7ad3c0ea..3c7159cb 100644
--- a/src/Settings/InfoProviderSystem/InfoProviderSettings.php
+++ b/src/Settings/InfoProviderSystem/InfoProviderSettings.php
@@ -44,6 +44,9 @@ class InfoProviderSettings
#[EmbeddedSettings]
public ?Element14Settings $element14 = null;
+ #[EmbeddedSettings]
+ public ?OctopartSettings $octopartSettings = null;
+
#[EmbeddedSettings]
public ?LCSCSettings $lcsc = null;
diff --git a/src/Settings/InfoProviderSystem/OctopartSettings.php b/src/Settings/InfoProviderSystem/OctopartSettings.php
new file mode 100644
index 00000000..905f337f
--- /dev/null
+++ b/src/Settings/InfoProviderSystem/OctopartSettings.php
@@ -0,0 +1,70 @@
+.
+ */
+
+declare(strict_types=1);
+
+
+namespace App\Settings\InfoProviderSystem;
+
+use App\Settings\SettingsIcon;
+use Jbtronics\SettingsBundle\Settings\Settings;
+use Jbtronics\SettingsBundle\Settings\SettingsParameter;
+use Jbtronics\SettingsBundle\Settings\SettingsTrait;
+use Symfony\Component\Form\Extension\Core\Type\CountryType;
+use Symfony\Component\Form\Extension\Core\Type\CurrencyType;
+use Symfony\Component\Form\Extension\Core\Type\NumberType;
+use Symfony\Component\Translation\TranslatableMessage as TM;
+use Symfony\Component\Validator\Constraints as Assert;
+
+#[Settings(label: new TM("settings.ips.octopart"))]
+#[SettingsIcon("fa-plug")]
+class OctopartSettings
+{
+ use SettingsTrait;
+
+ #[SettingsParameter(
+ label: new TM("settings.ips.digikey.client_id"),
+ envVar: "PROVIDER_OCTOPART_CLIENT_ID"
+ )]
+ public ?string $clientId = null;
+
+ #[SettingsParameter(
+ label: new TM("settings.ips.digikey.secret"),
+ envVar: "PROVIDER_OCTOPART_SECRET"
+ )]
+ public ?string $secret = null;
+
+ #[SettingsParameter(label: new TM("settings.ips.tme.currency"), formType: CurrencyType::class, formOptions: ["preferred_choices" => ["EUR", "USD", "CHF", "GBP"]], envVar: "PROVIDER_OCTOPART_CURRENCY")]
+ #[Assert\Currency()]
+ public string $currency = "EUR";
+
+ #[SettingsParameter(label: new TM("settings.ips.tme.country"), formType: CountryType::class, envVar: "PROVIDER_OCTOPART_COUNTRY")]
+ #[Assert\Country]
+ public string $country = "DE";
+
+ #[SettingsParameter(label: new TM("settings.ips.octopart.searchLimit"), description: new TM("settings.ips.octopart.searchLimit.help"),
+ formType: NumberType::class, formOptions: ["attr" => ["min" => 1, "max" => 100]], envVar: "PROVIDER_OCTOPART_SEARCH_LIMIT")]
+ #[Assert\Range(min: 1, max: 100)]
+ public int $searchLimit = 10;
+
+ #[SettingsParameter(label: new TM("settings.ips.octopart.onlyAuthorizedSellers"), description: new TM("settings.ips.octopart.onlyAuthorizedSellers.help"))]
+ public bool $onlyAuthorizedSellers = true;
+
+}
\ No newline at end of file
diff --git a/translations/messages.en.xlf b/translations/messages.en.xlf
index 9efccd04..56f5cb27 100644
--- a/translations/messages.en.xlf
+++ b/translations/messages.en.xlf
@@ -12946,5 +12946,35 @@ Please note, that you can not impersonate a disabled user. If you try you will g
Secret
+
+
+ settings.ips.octopart
+ Octopart / Nexar
+
+
+
+
+ settings.ips.octopart.searchLimit
+ Number of results
+
+
+
+
+ settings.ips.octopart.searchLimit.help
+ The number of results to get from Octopart while searching (please note that this counts towards your API limits)
+
+
+
+
+ settings.ips.octopart.onlyAuthorizedSellers
+ Only authorized sellers
+
+
+
+
+ settings.ips.octopart.onlyAuthorizedSellers.help
+ Set to false to include non-authorized offers in the results
+
+