Skip to content

Commit 705e71f

Browse files
committed
Started working on a conrad provider
1 parent ae4c078 commit 705e71f

File tree

3 files changed

+176
-1
lines changed

3 files changed

+176
-1
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
/*
3+
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
4+
*
5+
* Copyright (C) 2019 - 2026 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\Services\InfoProviderSystem\Providers;
25+
26+
use App\Services\InfoProviderSystem\DTOs\PartDetailDTO;
27+
use App\Services\InfoProviderSystem\DTOs\SearchResultDTO;
28+
use App\Settings\InfoProviderSystem\ConradSettings;
29+
use Symfony\Contracts\HttpClient\HttpClientInterface;
30+
31+
readonly class ConradProvider implements InfoProviderInterface
32+
{
33+
34+
private const SEARCH_ENDPOINT = 'https://api.conrad.de/search/1/v3/facetSearch';
35+
36+
public function __construct(private HttpClientInterface $httpClient, private ConradSettings $settings)
37+
{
38+
}
39+
40+
public function getProviderInfo(): array
41+
{
42+
return [
43+
'name' => 'Pollin',
44+
'description' => 'Retrieves part information from conrad.de',
45+
'url' => 'https://www.conrad.de/',
46+
'disabled_help' => 'Set API key in settings',
47+
'settings_class' => ConradSettings::class,
48+
];
49+
}
50+
51+
public function getProviderKey(): string
52+
{
53+
return 'conrad';
54+
}
55+
56+
public function isActive(): bool
57+
{
58+
return !empty($this->settings->apiKey);
59+
}
60+
61+
public function searchByKeyword(string $keyword): array
62+
{
63+
$url = self::SEARCH_ENDPOINT . '/' . $this->settings->country . '/' . $this->settings->language . '/' . $this->settings->customerType;
64+
65+
$response = $this->httpClient->request('POST', $url, [
66+
'query' => [
67+
'apikey' => $this->settings->apiKey,
68+
],
69+
'json' => [
70+
'query' => $keyword,
71+
],
72+
]);
73+
74+
$out = [];
75+
$results = $response->toArray();
76+
77+
foreach($results as $result) {
78+
$out[] = new SearchResultDTO(
79+
provider_key: $this->getProviderKey(),
80+
provider_id: $result['productId'],
81+
name: $result['title'],
82+
description: '',
83+
manufacturer: $result['brand']['name'] ?? null,
84+
mpn: $result['manufacturerId'] ?? null,
85+
preview_image_url: $result['image'] ?? null,
86+
);
87+
}
88+
89+
return $out;
90+
}
91+
92+
public function getDetails(string $id): PartDetailDTO
93+
{
94+
// TODO: Implement getDetails() method.
95+
}
96+
97+
public function getCapabilities(): array
98+
{
99+
return [ProviderCapabilities::BASIC,
100+
ProviderCapabilities::PICTURE,
101+
ProviderCapabilities::PRICE,];
102+
}
103+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/*
3+
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
4+
*
5+
* Copyright (C) 2019 - 2026 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\Form\Type\APIKeyType;
27+
use App\Settings\SettingsIcon;
28+
use Jbtronics\SettingsBundle\Metadata\EnvVarMode;
29+
use Jbtronics\SettingsBundle\Settings\Settings;
30+
use Jbtronics\SettingsBundle\Settings\SettingsParameter;
31+
use Jbtronics\SettingsBundle\Settings\SettingsTrait;
32+
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
33+
use Symfony\Component\Form\Extension\Core\Type\CountryType;
34+
use Symfony\Component\Form\Extension\Core\Type\LanguageType;
35+
use Symfony\Component\Translation\TranslatableMessage as TM;
36+
use Symfony\Component\Validator\Constraints as Assert;
37+
38+
#[Settings(label: new TM("settings.ips.conrad"))]
39+
#[SettingsIcon("fa-plug")]
40+
class ConradSettings
41+
{
42+
use SettingsTrait;
43+
44+
#[SettingsParameter(label: new TM("settings.ips.element14.apiKey"),
45+
formType: APIKeyType::class,
46+
formOptions: ["help_html" => true], envVar: "PROVIDER_CONRAD_API_KEY", envVarMode: EnvVarMode::OVERWRITE)]
47+
public ?string $apiKey = null;
48+
49+
#[SettingsParameter(label: new TM("settings.ips.tme.country"), formType: CountryType::class,
50+
envVar: "PROVIDER_CONRAD_COUNTRY", envVarMode: EnvVarMode::OVERWRITE)]
51+
#[Assert\Country]
52+
public string $country = "DE";
53+
54+
#[SettingsParameter(label: new TM("settings.ips.tme.language"), formType: LanguageType::class,
55+
envVar: "PROVIDER_CONRAD_LANGUAGE", envVarMode: EnvVarMode::OVERWRITE)]
56+
#[Assert\Language]
57+
public string $language = "en";
58+
59+
#[SettingsParameter(label: new TM("settings.ips.conrad.customerType"), formType: ChoiceType::class,
60+
formOptions: [
61+
"choices" => [
62+
"settings.ips.conrad.customerType.b2c" => "b2c",
63+
"settings.ips.conrad.customerType.b2b" => "b2b",
64+
],
65+
],
66+
envVar: "PROVIDER_CONRAD_LANGUAGE", envVarMode: EnvVarMode::OVERWRITE, )]
67+
#[Assert\Choice(choices: ["b2c", "b2b"])]
68+
public string $customerType = "b2c";
69+
}

src/Settings/InfoProviderSystem/InfoProviderSettings.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ class InfoProviderSettings
6363

6464
#[EmbeddedSettings]
6565
public ?PollinSettings $pollin = null;
66-
66+
6767
#[EmbeddedSettings]
6868
public ?BuerklinSettings $buerklin = null;
69+
70+
#[EmbeddedSettings]
71+
public ?ConradSettings $conrad = null;
6972
}

0 commit comments

Comments
 (0)