Use full path for categories returned by Octopart

This commit is contained in:
Jan Böhmer 2023-07-31 22:17:24 +02:00
parent 5b1ad541a8
commit ffe76f9d2e

View file

@ -58,8 +58,10 @@ class OctopartProvider implements InfoProviderInterface
} }
shortDescription shortDescription
category { category {
ancestors {
name
}
name name
path
} }
bestImage { bestImage {
url url
@ -290,12 +292,22 @@ class OctopartProvider implements InfoProviderInterface
} }
} }
//Built the category full path
$category = null;
if ($part['category']['name'] !== null) {
$category = implode(' -> ', array_map(fn($c) => $c['name'], $part['category']['ancestors'] ?? []));
if (!empty($category)) {
$category .= ' -> ';
}
$category .= $part['category']['name'];
}
return new PartDetailDTO( return new PartDetailDTO(
provider_key: $this->getProviderKey(), provider_key: $this->getProviderKey(),
provider_id: $part['id'], provider_id: $part['id'],
name: $part['mpn'], name: $part['mpn'],
description: $part['shortDescription'] ?? null, description: $part['shortDescription'] ?? null,
category: $part['category']['name'] ?? null, category: $category ,
manufacturer: $part['manufacturer']['name'] ?? null, manufacturer: $part['manufacturer']['name'] ?? null,
mpn: $part['mpn'], mpn: $part['mpn'],
preview_image_url: $part['bestImage']['url'] ?? null, preview_image_url: $part['bestImage']['url'] ?? null,