Skip to content

Commit 1dbcff6

Browse files
committed
Moved digikey IPS configuration to new settings system
1 parent 6e28f2a commit 1dbcff6

File tree

7 files changed

+96
-28
lines changed

7 files changed

+96
-28
lines changed

.env

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,6 @@ ERROR_PAGE_SHOW_HELP=1
7171
# Info provider settings
7272
##################################################################################
7373

74-
# Digikey Provider:
75-
# You can get your client id and secret from https://developer.digikey.com/
76-
PROVIDER_DIGIKEY_CLIENT_ID=
77-
PROVIDER_DIGIKEY_SECRET=
78-
# The currency to get prices in
79-
PROVIDER_DIGIKEY_CURRENCY=EUR
80-
# The language to get results in (en, de, fr, it, es, zh, ja, ko)
81-
PROVIDER_DIGIKEY_LANGUAGE=en
82-
# The country to get results for
83-
PROVIDER_DIGIKEY_COUNTRY=DE
84-
8574
# Octopart / Nexar Provider:
8675
# You can get your API key from https://nexar.com/api
8776
PROVIDER_OCTOPART_CLIENT_ID=

config/packages/knpu_oauth2_client.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ knpu_oauth2_client:
66
type: generic
77
provider_class: '\League\OAuth2\Client\Provider\GenericProvider'
88

9-
client_id: '%env(PROVIDER_DIGIKEY_CLIENT_ID)%'
10-
client_secret: '%env(PROVIDER_DIGIKEY_SECRET)%'
9+
client_id: '%env(settings:digikey:clientId)%'
10+
client_secret: '%env(settings:digikey:secret)%'
1111

1212
redirect_route: 'oauth_client_check'
1313
redirect_params: {name: 'ip_digikey_oauth'}

config/services.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,6 @@ services:
199199
arguments:
200200
$providers: !tagged_iterator 'app.info_provider'
201201

202-
App\Services\InfoProviderSystem\Providers\DigikeyProvider:
203-
arguments:
204-
$clientId: '%env(string:PROVIDER_DIGIKEY_CLIENT_ID)%'
205-
$currency: '%env(string:PROVIDER_DIGIKEY_CURRENCY)%'
206-
$language: '%env(string:PROVIDER_DIGIKEY_LANGUAGE)%'
207-
$country: '%env(string:PROVIDER_DIGIKEY_COUNTRY)%'
208-
209202
App\Services\InfoProviderSystem\Providers\OctopartProvider:
210203
arguments:
211204
$clientId: '&env(string:PROVIDER_OCTOPART_CLIENT_ID)%'

src/Services/InfoProviderSystem/Providers/DigikeyProvider.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use App\Services\InfoProviderSystem\DTOs\PurchaseInfoDTO;
3232
use App\Services\InfoProviderSystem\DTOs\SearchResultDTO;
3333
use App\Services\OAuth\OAuthTokenManager;
34+
use App\Settings\InfoProviderSystem\DigikeySettings;
3435
use Symfony\Contracts\HttpClient\HttpClientInterface;
3536

3637
class DigikeyProvider implements InfoProviderInterface
@@ -55,17 +56,16 @@ class DigikeyProvider implements InfoProviderInterface
5556
];
5657

5758
public function __construct(HttpClientInterface $httpClient, private readonly OAuthTokenManager $authTokenManager,
58-
private readonly string $currency, private readonly string $clientId,
59-
private readonly string $language, private readonly string $country)
59+
private readonly DigikeySettings $settings,)
6060
{
6161
//Create the HTTP client with some default options
6262
$this->digikeyClient = $httpClient->withOptions([
6363
"base_uri" => self::BASE_URI,
6464
"headers" => [
65-
"X-DIGIKEY-Client-Id" => $clientId,
66-
"X-DIGIKEY-Locale-Site" => $this->country,
67-
"X-DIGIKEY-Locale-Language" => $this->language,
68-
"X-DIGIKEY-Locale-Currency" => $this->currency,
65+
"X-DIGIKEY-Client-Id" => $this->settings->clientId,
66+
"X-DIGIKEY-Locale-Site" => $this->settings->country,
67+
"X-DIGIKEY-Locale-Language" => $this->settings->language,
68+
"X-DIGIKEY-Locale-Currency" => $this->settings->currency,
6969
"X-DIGIKEY-Customer-Id" => 0,
7070
]
7171
]);
@@ -101,7 +101,7 @@ public function getProviderKey(): string
101101
public function isActive(): bool
102102
{
103103
//The client ID has to be set and a token has to be available (user clicked connect)
104-
return $this->clientId !== '' && $this->authTokenManager->hasToken(self::OAUTH_APP_NAME);
104+
return $this->settings->clientId !== '' && $this->authTokenManager->hasToken(self::OAUTH_APP_NAME);
105105
}
106106

107107
public function searchByKeyword(string $keyword): array
@@ -268,7 +268,7 @@ private function pricingToDTOs(array $price_breaks, string $order_number, string
268268
$prices = [];
269269

270270
foreach ($price_breaks as $price_break) {
271-
$prices[] = new PriceDTO(minimum_discount_amount: $price_break['BreakQuantity'], price: (string) $price_break['UnitPrice'], currency_iso_code: $this->currency);
271+
$prices[] = new PriceDTO(minimum_discount_amount: $price_break['BreakQuantity'], price: (string) $price_break['UnitPrice'], currency_iso_code: $this->settings->currency);
272272
}
273273

274274
return [
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
/*
3+
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
4+
*
5+
* Copyright (C) 2019 - 2025 Jan Böhmer (https://github.com/jbtronics)
6+
*
7+
* This program is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU Affero General Public License as published
9+
* by the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Affero General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public License
18+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
declare(strict_types=1);
22+
23+
24+
namespace App\Settings\InfoProviderSystem;
25+
26+
use App\Settings\SettingsIcon;
27+
use Jbtronics\SettingsBundle\Settings\Settings;
28+
use Jbtronics\SettingsBundle\Settings\SettingsTrait;
29+
use Symfony\Component\Form\Extension\Core\Type\CountryType;
30+
use Symfony\Component\Form\Extension\Core\Type\CurrencyType;
31+
use Symfony\Component\Form\Extension\Core\Type\LanguageType;
32+
use Symfony\Component\Translation\TranslatableMessage as TM;
33+
use Jbtronics\SettingsBundle\Settings\SettingsParameter;
34+
use Symfony\Component\Validator\Constraints as Assert;
35+
36+
#[Settings(label: new TM("settings.ips.digikey"))]
37+
#[SettingsIcon("fa-plug")]
38+
class DigikeySettings
39+
{
40+
use SettingsTrait;
41+
42+
#[SettingsParameter(
43+
label: new TM("settings.ips.digikey.client_id"),
44+
envVar: "PROVIDER_DIGIKEY_CLIENT_ID"
45+
)]
46+
public ?string $clientId = null;
47+
48+
#[SettingsParameter(
49+
label: new TM("settings.ips.digikey.secret"),
50+
envVar: "PROVIDER_DIGIKEY_SECRET"
51+
)]
52+
public ?string $secret = null;
53+
54+
#[SettingsParameter(label: new TM("settings.ips.tme.currency"), formType: CurrencyType::class, formOptions: ["preferred_choices" => ["EUR", "USD", "CHF", "GBP"]], envVar: "PROVIDER_DIGIKEY_CURRENCY")]
55+
#[Assert\Currency()]
56+
public string $currency = "EUR";
57+
58+
#[SettingsParameter(label: new TM("settings.ips.tme.country"), formType: CountryType::class, envVar: "PROVIDER_DIGIKEY_COUNTRY")]
59+
#[Assert\Country]
60+
public string $country = "DE";
61+
62+
#[SettingsParameter(label: new TM("settings.ips.tme.language"), formType: LanguageType::class, envVar: "PROVIDER_DIGIKEY_LANGUAGE")]
63+
#[Assert\Language]
64+
public string $language = "en";
65+
}

src/Settings/InfoProviderSystem/InfoProviderSettings.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ class InfoProviderSettings
3232
{
3333
use SettingsTrait;
3434

35+
#[EmbeddedSettings]
36+
public ?DigikeySettings $digikey = null;
37+
3538
#[EmbeddedSettings]
3639
public ?MouserSettings $mouser = null;
3740

translations/messages.en.xlf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12928,5 +12928,23 @@ Please note, that you can not impersonate a disabled user. If you try you will g
1292812928
<target>Root nodes redirect to new entity pages</target>
1292912929
</segment>
1293012930
</unit>
12931+
<unit id="j7HiQ80" name="settings.ips.digikey">
12932+
<segment>
12933+
<source>settings.ips.digikey</source>
12934+
<target>Digikey</target>
12935+
</segment>
12936+
</unit>
12937+
<unit id="_ViyVdh" name="settings.ips.digikey.client_id">
12938+
<segment>
12939+
<source>settings.ips.digikey.client_id</source>
12940+
<target>Client ID</target>
12941+
</segment>
12942+
</unit>
12943+
<unit id="eB9dDyp" name="settings.ips.digikey.secret">
12944+
<segment>
12945+
<source>settings.ips.digikey.secret</source>
12946+
<target>Secret</target>
12947+
</segment>
12948+
</unit>
1293112949
</file>
1293212950
</xliff>

0 commit comments

Comments
 (0)