mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-02-12 04:29:36 +00:00
Allow to extract parameters form additionalProperty JSONLD data
This commit is contained in:
parent
909cab0044
commit
47c7ee9f07
1 changed files with 27 additions and 5 deletions
|
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||||
namespace App\Services\InfoProviderSystem\Providers;
|
namespace App\Services\InfoProviderSystem\Providers;
|
||||||
|
|
||||||
use App\Exceptions\ProviderIDNotSupportedException;
|
use App\Exceptions\ProviderIDNotSupportedException;
|
||||||
|
use App\Services\InfoProviderSystem\DTOs\ParameterDTO;
|
||||||
use App\Services\InfoProviderSystem\DTOs\PartDetailDTO;
|
use App\Services\InfoProviderSystem\DTOs\PartDetailDTO;
|
||||||
use App\Services\InfoProviderSystem\DTOs\PriceDTO;
|
use App\Services\InfoProviderSystem\DTOs\PriceDTO;
|
||||||
use App\Services\InfoProviderSystem\DTOs\PurchaseInfoDTO;
|
use App\Services\InfoProviderSystem\DTOs\PurchaseInfoDTO;
|
||||||
|
|
@ -161,6 +162,26 @@ class GenericWebProvider implements InfoProviderInterface
|
||||||
$image = $image['contentUrl'] ?? $image['url'] ?? null;
|
$image = $image['contentUrl'] ?? $image['url'] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Try to extract parameters from additionalProperty
|
||||||
|
$parameters = [];
|
||||||
|
if (isset($jsonLd['additionalProperty']) && array_is_list($jsonLd['additionalProperty'])) {
|
||||||
|
foreach ($jsonLd['additionalProperty'] as $property) { //TODO: Handle minValue and maxValue
|
||||||
|
if (isset ($property['unitText'])) {
|
||||||
|
$parameters[] = ParameterDTO::parseValueField(
|
||||||
|
name: $property['name'] ?? 'Unknown',
|
||||||
|
value: $property['value'] ?? '',
|
||||||
|
unit: $property['unitText']
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$parameters[] = ParameterDTO::parseValueIncludingUnit(
|
||||||
|
name: $property['name'] ?? 'Unknown',
|
||||||
|
value: $property['value'] ?? ''
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return new PartDetailDTO(
|
return new PartDetailDTO(
|
||||||
provider_key: $this->getProviderKey(),
|
provider_key: $this->getProviderKey(),
|
||||||
provider_id: $url,
|
provider_id: $url,
|
||||||
|
|
@ -172,6 +193,7 @@ class GenericWebProvider implements InfoProviderInterface
|
||||||
preview_image_url: $image,
|
preview_image_url: $image,
|
||||||
provider_url: $url,
|
provider_url: $url,
|
||||||
notes: $notes,
|
notes: $notes,
|
||||||
|
parameters: $parameters,
|
||||||
vendor_infos: $vendor_infos,
|
vendor_infos: $vendor_infos,
|
||||||
mass: isset($jsonLd['weight']['value']) ? (float)$jsonLd['weight']['value'] : null,
|
mass: isset($jsonLd['weight']['value']) ? (float)$jsonLd['weight']['value'] : null,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue