Skip to content

Commit b2946ae

Browse files
committed
Moved pollin and reichelt info provider settings to new settings system
1 parent beb079b commit b2946ae

File tree

8 files changed

+182
-86
lines changed

8 files changed

+182
-86
lines changed

.env

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,6 @@ ERROR_PAGE_ADMIN_EMAIL=''
6767
# 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...
6868
ERROR_PAGE_SHOW_HELP=1
6969

70-
##################################################################################
71-
# Part table settings
72-
##################################################################################
73-
74-
# The default page size for the part table (set to -1 to show all parts on one page)
75-
#TABLE_DEFAULT_PAGE_SIZE=50
76-
# Configure which columns will be visible by default in the parts table (and in which order).
77-
# This is a comma separated list of column names. See documentation for available values.
78-
#TABLE_PARTS_DEFAULT_COLUMNS=name,description,category,footprint,manufacturer,storage_location,amount
79-
8070
##################################################################################
8171
# Info provider settings
8272
##################################################################################
@@ -106,27 +96,6 @@ PROVIDER_OCTOPART_SEARCH_LIMIT=10
10696
# Set to false to include non authorized offers in the results
10797
PROVIDER_OCTOPART_ONLY_AUTHORIZED_SELLERS=1
10898

109-
110-
# Reichelt provider:
111-
# Reichelt.com offers no official API, so this info provider webscrapes the website to extract info
112-
# It could break at any time, use it at your own risk
113-
# We dont require an API key for Reichelt, just set this to 1 to enable Reichelt support
114-
PROVIDER_REICHELT_ENABLED=0
115-
# The country to get prices for
116-
PROVIDER_REICHELT_COUNTRY=DE
117-
# The language to get results in (en, de, fr, nl, pl, it, es)
118-
PROVIDER_REICHELT_LANGUAGE=en
119-
# Include VAT in prices (set to 1 to include VAT, 0 to exclude VAT)
120-
PROVIDER_REICHELT_INCLUDE_VAT=1
121-
# The currency to get prices in (only for countries with countries other than EUR)
122-
PROVIDER_REICHELT_CURRENCY=EUR
123-
124-
# Pollin provider:
125-
# Pollin.de offers no official API, so this info provider webscrapes the website to extract info
126-
# It could break at any time, use it at your own risk
127-
# We dont require an API key for Pollin, just set this to 1 to enable Pollin support
128-
PROVIDER_POLLIN_ENABLED=0
129-
13099
##################################################################################
131100
# EDA integration related settings
132101
##################################################################################

src/Services/InfoProviderSystem/Providers/PollinProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use App\Services\InfoProviderSystem\DTOs\PriceDTO;
3232
use App\Services\InfoProviderSystem\DTOs\PurchaseInfoDTO;
3333
use App\Services\InfoProviderSystem\DTOs\SearchResultDTO;
34+
use App\Settings\InfoProviderSystem\PollinSettings;
3435
use Symfony\Component\DependencyInjection\Attribute\Autowire;
3536
use Symfony\Component\DomCrawler\Crawler;
3637
use Symfony\Contracts\HttpClient\HttpClientInterface;
@@ -39,8 +40,7 @@ class PollinProvider implements InfoProviderInterface
3940
{
4041

4142
public function __construct(private readonly HttpClientInterface $client,
42-
#[Autowire(env: 'bool:PROVIDER_POLLIN_ENABLED')]
43-
private readonly bool $enabled = true,
43+
private readonly PollinSettings $settings,
4444
)
4545
{
4646
}
@@ -62,7 +62,7 @@ public function getProviderKey(): string
6262

6363
public function isActive(): bool
6464
{
65-
return $this->enabled;
65+
return $this->settings->enabled;
6666
}
6767

6868
public function searchByKeyword(string $keyword): array

src/Services/InfoProviderSystem/Providers/ReicheltProvider.php

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use App\Services\InfoProviderSystem\DTOs\PriceDTO;
3030
use App\Services\InfoProviderSystem\DTOs\PurchaseInfoDTO;
3131
use App\Services\InfoProviderSystem\DTOs\SearchResultDTO;
32+
use App\Settings\InfoProviderSystem\ReicheltSettings;
3233
use Symfony\Component\DependencyInjection\Attribute\Autowire;
3334
use Symfony\Component\DomCrawler\Crawler;
3435
use Symfony\Contracts\HttpClient\HttpClientInterface;
@@ -39,16 +40,7 @@ class ReicheltProvider implements InfoProviderInterface
3940
public const DISTRIBUTOR_NAME = "Reichelt";
4041

4142
public function __construct(private readonly HttpClientInterface $client,
42-
#[Autowire(env: "bool:PROVIDER_REICHELT_ENABLED")]
43-
private readonly bool $enabled = true,
44-
#[Autowire(env: "PROVIDER_REICHELT_LANGUAGE")]
45-
private readonly string $language = "en",
46-
#[Autowire(env: "PROVIDER_REICHELT_COUNTRY")]
47-
private readonly string $country = "DE",
48-
#[Autowire(env: "PROVIDER_REICHELT_INCLUDE_VAT")]
49-
private readonly bool $includeVAT = false,
50-
#[Autowire(env: "PROVIDER_REICHELT_CURRENCY")]
51-
private readonly string $currency = "EUR",
43+
private readonly ReicheltSettings $settings,
5244
)
5345
{
5446
}
@@ -70,7 +62,7 @@ public function getProviderKey(): string
7062

7163
public function isActive(): bool
7264
{
73-
return $this->enabled;
65+
return $this->settings->enabled;
7466
}
7567

7668
public function searchByKeyword(string $keyword): array
@@ -121,8 +113,8 @@ public function getDetails(string $id): PartDetailDTO
121113
sprintf(
122114
'https://www.reichelt.com/?ACTION=514&id=74&article=%s&LANGUAGE=%s&CCOUNTRY=%s',
123115
$id,
124-
strtoupper($this->language),
125-
strtoupper($this->country)
116+
strtoupper($this->settings->language),
117+
strtoupper($this->settings->country)
126118
)
127119
);
128120
$json = $response->toArray();
@@ -133,8 +125,8 @@ public function getDetails(string $id): PartDetailDTO
133125

134126
$response = $this->client->request('GET', $productPage, [
135127
'query' => [
136-
'CCTYPE' => $this->includeVAT ? 'private' : 'business',
137-
'currency' => $this->currency,
128+
'CCTYPE' => $this->settings->includeVAT ? 'private' : 'business',
129+
'currency' => $this->settings->currency,
138130
],
139131
]);
140132
$html = $response->getContent();
@@ -158,7 +150,7 @@ public function getDetails(string $id): PartDetailDTO
158150
distributor_name: self::DISTRIBUTOR_NAME,
159151
order_number: $json[0]['article_artnr'],
160152
prices: array_merge(
161-
[new PriceDTO(1.0, $priceString, $currency, $this->includeVAT)]
153+
[new PriceDTO(1.0, $priceString, $currency, $this->settings->includeVAT)]
162154
, $this->parseBatchPrices($dom, $currency)),
163155
product_url: $productPage
164156
);
@@ -218,7 +210,7 @@ private function parseBatchPrices(Crawler $dom, string $currency): array
218210
//Strip any non-numeric characters
219211
$priceString = preg_replace('/[^0-9.]/', '', $priceString);
220212

221-
$prices[] = new PriceDTO($minAmount, $priceString, $currency, $this->includeVAT);
213+
$prices[] = new PriceDTO($minAmount, $priceString, $currency, $this->settings->includeVAT);
222214
});
223215

224216
return $prices;
@@ -270,7 +262,7 @@ private function parseParameters(Crawler $dom): array
270262
private function getBaseURL(): string
271263
{
272264
//Without the trailing slash
273-
return 'https://www.reichelt.com/' . strtolower($this->country) . '/' . strtolower($this->language);
265+
return 'https://www.reichelt.com/' . strtolower($this->settings->country) . '/' . strtolower($this->settings->language);
274266
}
275267

276268
public function getCapabilities(): array

src/Settings/InfoProviderSystem/InfoProviderSettings.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,10 @@ class InfoProviderSettings
4646

4747
#[EmbeddedSettings]
4848
public ?OEMSecretsSettings $oemsecrets = null;
49+
50+
#[EmbeddedSettings]
51+
public ?ReicheltSettings $reichelt = null;
52+
53+
#[EmbeddedSettings]
54+
public ?PollinSettings $pollin = null;
4955
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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\SettingsParameter;
29+
use Symfony\Component\Translation\TranslatableMessage as TM;
30+
31+
#[Settings(label: new TM("settings.ips.pollin"), description: new TM("settings.ips.pollin.help"))]
32+
#[SettingsIcon("fa-plug")]
33+
class PollinSettings
34+
{
35+
#[SettingsParameter(label: new TM("settings.ips.lcsc.enabled"), envVar: "bool:PROVIDER_POLLIN_ENABLED")]
36+
public bool $enabled = false;
37+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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\SettingsParameter;
29+
use Jbtronics\SettingsBundle\Settings\SettingsTrait;
30+
use Symfony\Component\Form\Extension\Core\Type\CountryType;
31+
use Symfony\Component\Form\Extension\Core\Type\CurrencyType;
32+
use Symfony\Component\Form\Extension\Core\Type\LanguageType;
33+
use Symfony\Component\Translation\TranslatableMessage as TM;
34+
use Symfony\Component\Validator\Constraints as Assert;
35+
36+
#[Settings(label: new TM("settings.ips.reichelt"), description: new TM("settings.ips.reichelt.help"))]
37+
#[SettingsIcon("fa-plug")]
38+
class ReicheltSettings
39+
{
40+
use SettingsTrait;
41+
42+
public const SUPPORTED_LANGUAGE = ["en", "de", "fr", "nl", "pl", "it", "es"];
43+
44+
#[SettingsParameter(label: new TM("settings.ips.lcsc.enabled"), envVar: "bool:PROVIDER_REICHELT_ENABLED")]
45+
public bool $enabled = false;
46+
47+
#[SettingsParameter(label: new TM("settings.ips.tme.currency"), formType: CurrencyType::class, formOptions: ["preferred_choices" => ["EUR"]], envVar: "PROVIDER_REICHELT_CURRENCY")]
48+
public string $currency = "EUR";
49+
50+
#[SettingsParameter(label: new TM("settings.ips.tme.language"), formType: LanguageType::class, formOptions: ["preferred_choices" => self::SUPPORTED_LANGUAGE], envVar: "PROVIDER_REICHELT_LANGUAGE")]
51+
#[Assert\Language()]
52+
#[Assert\Choice(choices: self::SUPPORTED_LANGUAGE)]
53+
public string $language = "en";
54+
55+
#[SettingsParameter(label: new TM("settings.ips.tme.country"), envVar: "PROVIDER_REICHELT_COUNTRY", formType: CountryType::class, formOptions: ["preferred_choices" => ["DE", "PL", "GB", "FR"]])]
56+
#[Assert\Country]
57+
public string $country = "DE";
58+
59+
#[SettingsParameter(label: new TM("settings.ips.reichelt.include_vat"), envVar: "bool:PROVIDER_REICHELT_INCLUDE_VAT")]
60+
public bool $includeVAT = true;
61+
62+
}

src/Settings/InfoProviderSystem/TMESettings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class TMESettings
5656
#[Assert\Language]
5757
public string $language = "en";
5858

59-
#[SettingsParameter(label: new TM("settings.ips.tme.country"), envVar: "PROVIDER_TME_COUNTRY", formType: CountryType::class, formOptions: ["preferred_choices" => ["DE", "PL", "GB", "FR"]])]
59+
#[SettingsParameter(label: new TM("settings.ips.tme.country"), formType: CountryType::class, formOptions: ["preferred_choices" => ["DE", "PL", "GB", "FR"]], envVar: "PROVIDER_TME_COUNTRY")]
6060
#[Assert\Country]
6161
public string $country = "DE";
6262

0 commit comments

Comments
 (0)