Allow to retrieve parameters from conrad

This commit is contained in:
Jan Böhmer 2026-01-26 23:18:32 +01:00
parent 7ab33c859b
commit 3ed62f5cee

View file

@ -23,6 +23,7 @@ declare(strict_types=1);
namespace App\Services\InfoProviderSystem\Providers;
use App\Services\InfoProviderSystem\DTOs\ParameterDTO;
use App\Services\InfoProviderSystem\DTOs\PartDetailDTO;
use App\Services\InfoProviderSystem\DTOs\SearchResultDTO;
use App\Settings\InfoProviderSystem\ConradSettings;
@ -85,6 +86,20 @@ readonly class ConradProvider implements InfoProviderInterface
return null;
}
private function technicalAttributesToParameters(array $technicalAttributes): array
{
$parameters = [];
foreach ($technicalAttributes as $attribute) {
if ($attribute['multiValue'] ?? false === true) {
throw new \LogicException('Multi value attributes are not supported yet');
}
$parameters[] = ParameterDTO::parseValueField($attribute['attributeName'],
$attribute['values'][0]['value'], $attribute['values'][0]['unit']['name'] ?? null);
}
return $parameters;
}
public function searchByKeyword(string $keyword): array
{
$url = $this->settings->shopID->getAPIRoot() . self::SEARCH_ENDPOINT . '/'
@ -146,6 +161,7 @@ readonly class ConradProvider implements InfoProviderInterface
provider_url: $this->getProductUrl($data['shortProductNumber']),
footprint: $this->getFootprintFromTechnicalAttributes($data['productFullInformation']['technicalAttributes'] ?? []),
notes: $data['productFullInformation']['description'] ?? null,
parameters: $this->technicalAttributesToParameters($data['productFullInformation']['technicalAttributes'] ?? []),
);
}