mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-02-03 16:09:36 +00:00
Use parameter parsing logic from PR #1211 to handle multi parameters fine
This commit is contained in:
parent
22cf04585b
commit
6f4dad98d9
1 changed files with 47 additions and 9 deletions
|
|
@ -89,16 +89,54 @@ readonly class ConradProvider implements InfoProviderInterface
|
||||||
|
|
||||||
private function technicalAttributesToParameters(array $technicalAttributes): array
|
private function technicalAttributesToParameters(array $technicalAttributes): array
|
||||||
{
|
{
|
||||||
$parameters = [];
|
return array_map(static function (array $p) {
|
||||||
foreach ($technicalAttributes as $attribute) {
|
if (count($p['values']) === 1) { //Single value attribute
|
||||||
if ($attribute['multiValue'] ?? false === true) {
|
if (array_key_exists('unit', $p['values'][0])) {
|
||||||
throw new \LogicException('Multi value attributes are not supported yet');
|
return ParameterDTO::parseValueField( //With unit
|
||||||
}
|
name: $p['attributeName'],
|
||||||
$parameters[] = ParameterDTO::parseValueField($attribute['attributeName'],
|
value: $p['values'][0]['value'],
|
||||||
$attribute['values'][0]['value'], $attribute['values'][0]['unit']['name'] ?? null);
|
unit: $p['values'][0]['unit']['name'],
|
||||||
}
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return $parameters;
|
return ParameterDTO::parseValueIncludingUnit(
|
||||||
|
name: $p['attributeName'],
|
||||||
|
value: $p['values'][0]['value'],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($p['values']) === 2) { //Multi value attribute (e.g. min/max)
|
||||||
|
$value = $p['values'][0]['value'] ?? null;
|
||||||
|
$value2 = $p['values'][1]['value'] ?? null;
|
||||||
|
$unit = $p['values'][0]['unit']['name'] ?? '';
|
||||||
|
$unit2 = $p['values'][1]['unit']['name'] ?? '';
|
||||||
|
if ($unit === $unit2 && is_numeric($value) && is_numeric($value2)) {
|
||||||
|
if (array_key_exists('unit', $p['values'][0])) { //With unit
|
||||||
|
return new ParameterDTO(
|
||||||
|
name: $p['attributeName'],
|
||||||
|
value_min: (float)$value,
|
||||||
|
value_max: (float)$value2,
|
||||||
|
unit: $unit,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ParameterDTO(
|
||||||
|
name: $p['attributeName'],
|
||||||
|
value_min: (float)$value,
|
||||||
|
value_max: (float)$value2,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// fallback implementation
|
||||||
|
$values = implode(", ", array_map(fn($q) =>
|
||||||
|
array_key_exists('unit', $q) ? $q['value']." ". $q['unit'] : $q['value']
|
||||||
|
, $p['values']));
|
||||||
|
return ParameterDTO::parseValueIncludingUnit(
|
||||||
|
name: $p['attributeName'],
|
||||||
|
value: $values,
|
||||||
|
);
|
||||||
|
}, $technicalAttributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function productMediaToDatasheets(array $productMedia): array
|
public function productMediaToDatasheets(array $productMedia): array
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue