mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 01:25:55 +02:00
Allow to change language and country
This commit is contained in:
parent
32b4e6812d
commit
90e1b809fe
1 changed files with 14 additions and 9 deletions
|
@ -39,7 +39,7 @@ class ReicheltProvider implements InfoProviderInterface
|
||||||
|
|
||||||
private const SEARCH_ENDPOINT = "https://www.reichelt.com/index.html?ACTION=446&LA=0&nbc=1&q=%s";
|
private const SEARCH_ENDPOINT = "https://www.reichelt.com/index.html?ACTION=446&LA=0&nbc=1&q=%s";
|
||||||
|
|
||||||
public function __construct(private readonly HttpClientInterface $client)
|
public function __construct(private readonly HttpClientInterface $client, private readonly bool $enabled = true, private readonly string $language = "en", private readonly string $country = "DE")
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,8 +47,8 @@ class ReicheltProvider implements InfoProviderInterface
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'name' => 'Reichelt',
|
'name' => 'Reichelt',
|
||||||
'description' => 'TODO',
|
'description' => 'Webscrapping from reichelt.com to get part information',
|
||||||
'url' => 'https://www.reichelt.de/',
|
'url' => 'https://www.reichelt.com/',
|
||||||
'disabled_help' => 'TODO'
|
'disabled_help' => 'TODO'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -60,14 +60,12 @@ class ReicheltProvider implements InfoProviderInterface
|
||||||
|
|
||||||
public function isActive(): bool
|
public function isActive(): bool
|
||||||
{
|
{
|
||||||
return true;
|
return $this->enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function searchByKeyword(string $keyword): array
|
public function searchByKeyword(string $keyword): array
|
||||||
{
|
{
|
||||||
//Lowercase the keyword and urlencode it
|
$response = $this->client->request('GET', sprintf($this->getBaseURL() . '/shop/search/%s', $keyword));
|
||||||
$keyword = urlencode($keyword);
|
|
||||||
$response = $this->client->request('GET', sprintf(self::SEARCH_ENDPOINT, $keyword));
|
|
||||||
$html = $response->getContent();
|
$html = $response->getContent();
|
||||||
|
|
||||||
//Parse the HTML and return the results
|
//Parse the HTML and return the results
|
||||||
|
@ -109,7 +107,14 @@ class ReicheltProvider implements InfoProviderInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
//Use this endpoint to resolve the artID to a product page
|
//Use this endpoint to resolve the artID to a product page
|
||||||
$response = $this->client->request('GET', sprintf('https://www.reichelt.com/?ACTION=514&id=74&article=%s&LANGUAGE=EN&CCOUNTRY=DE', $id));
|
$response = $this->client->request('GET',
|
||||||
|
sprintf(
|
||||||
|
'https://www.reichelt.com/?ACTION=514&id=74&article=%s&LANGUAGE=%s&CCOUNTRY=%s',
|
||||||
|
$id,
|
||||||
|
strtoupper($this->language),
|
||||||
|
strtoupper($this->country)
|
||||||
|
)
|
||||||
|
);
|
||||||
$json = $response->toArray();
|
$json = $response->toArray();
|
||||||
|
|
||||||
//Retrieve the product page from the response
|
//Retrieve the product page from the response
|
||||||
|
@ -246,7 +251,7 @@ class ReicheltProvider implements InfoProviderInterface
|
||||||
private function getBaseURL(): string
|
private function getBaseURL(): string
|
||||||
{
|
{
|
||||||
//Without the trailing slash
|
//Without the trailing slash
|
||||||
return 'https://www.reichelt.com/de/en';
|
return 'https://www.reichelt.com/' . strtolower($this->country) . '/' . strtolower($this->language);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCapabilities(): array
|
public function getCapabilities(): array
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue