mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 01:25:55 +02:00
Allow reichelt provider to parse parameters
This commit is contained in:
parent
376c7e7a6f
commit
e0bf8e5fbc
1 changed files with 23 additions and 1 deletions
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||||
namespace App\Services\InfoProviderSystem\Providers;
|
namespace App\Services\InfoProviderSystem\Providers;
|
||||||
|
|
||||||
use App\Services\InfoProviderSystem\DTOs\FileDTO;
|
use App\Services\InfoProviderSystem\DTOs\FileDTO;
|
||||||
|
use App\Services\InfoProviderSystem\DTOs\ParameterDTO;
|
||||||
use App\Services\InfoProviderSystem\DTOs\PartDetailDTO;
|
use App\Services\InfoProviderSystem\DTOs\PartDetailDTO;
|
||||||
use App\Services\InfoProviderSystem\DTOs\SearchResultDTO;
|
use App\Services\InfoProviderSystem\DTOs\SearchResultDTO;
|
||||||
use Symfony\Component\DomCrawler\Crawler;
|
use Symfony\Component\DomCrawler\Crawler;
|
||||||
|
@ -134,11 +135,32 @@ class ReicheltProvider implements InfoProviderInterface
|
||||||
preview_image_url: $json[0]['article_picture'],
|
preview_image_url: $json[0]['article_picture'],
|
||||||
provider_url: $productPage,
|
provider_url: $productPage,
|
||||||
notes: $notes,
|
notes: $notes,
|
||||||
datasheets: $datasheets
|
datasheets: $datasheets,
|
||||||
|
parameters: $this->parseParameters($dom)
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function parseParameters(Crawler $dom): array
|
||||||
|
{
|
||||||
|
$parameters = [];
|
||||||
|
//Iterate over each ul.articleTechnicalData which contains the specifications of each group
|
||||||
|
$dom->filter('ul.articleTechnicalData')->each(function (Crawler $groupElement) use (&$parameters) {
|
||||||
|
$groupName = $groupElement->filter('li.articleTechnicalHeadline')->text();
|
||||||
|
|
||||||
|
//Iterate over each second li in ul.articleAttribute, which contains the specifications
|
||||||
|
$groupElement->filter('ul.articleAttribute li:nth-child(2n)')->each(function (Crawler $specElement) use (&$parameters, $groupName) {
|
||||||
|
$parameters[] = ParameterDTO::parseValueField(
|
||||||
|
name: $specElement->previousAll()->text(),
|
||||||
|
value: $specElement->text(),
|
||||||
|
group: $groupName
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return $parameters;
|
||||||
|
}
|
||||||
|
|
||||||
private function getBaseURL(): string
|
private function getBaseURL(): string
|
||||||
{
|
{
|
||||||
//Without the trailing slash
|
//Without the trailing slash
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue