mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-02-12 04:29:36 +00:00
Hadle if offers are nested and images are ImageObjects in JSON+LD
This commit is contained in:
parent
1213f82cdf
commit
7feba634b8
1 changed files with 28 additions and 2 deletions
|
|
@ -112,10 +112,30 @@ class GenericWebProvider implements InfoProviderInterface
|
||||||
$jsonLd['url'] = $scheme.'://'.$host.$jsonLd['url'];
|
$jsonLd['url'] = $scheme.'://'.$host.$jsonLd['url'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$prices = [];
|
||||||
|
if (isset($offer['price'])) {
|
||||||
|
$prices[] = new PriceDTO(
|
||||||
|
minimum_discount_amount: 1,
|
||||||
|
price: (string) $offer['price'],
|
||||||
|
currency_iso_code: $offer['priceCurrency'] ?? null
|
||||||
|
);
|
||||||
|
} else if (isset($offer['offers']) && array_is_list($offer['offers'])) {
|
||||||
|
//Some sites nest offers
|
||||||
|
foreach ($offer['offers'] as $subOffer) {
|
||||||
|
if (isset($subOffer['price'])) {
|
||||||
|
$prices[] = new PriceDTO(
|
||||||
|
minimum_discount_amount: 1,
|
||||||
|
price: (string) $subOffer['price'],
|
||||||
|
currency_iso_code: $subOffer['priceCurrency'] ?? null
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$vendor_infos = [new PurchaseInfoDTO(
|
$vendor_infos = [new PurchaseInfoDTO(
|
||||||
distributor_name: $this->extractShopName($url),
|
distributor_name: $this->extractShopName($url),
|
||||||
order_number: (string) ($jsonLd['sku'] ?? $jsonLd['@id'] ?? $jsonLd['gtin'] ?? 'Unknown'),
|
order_number: (string) ($jsonLd['sku'] ?? $jsonLd['@id'] ?? $jsonLd['gtin'] ?? 'Unknown'),
|
||||||
prices: [new PriceDTO(minimum_discount_amount: 1, price: (string) $offer['price'], currency_iso_code: $offer['priceCurrency'] ?? null)],
|
prices: $prices,
|
||||||
product_url: $jsonLd['url'] ?? $url,
|
product_url: $jsonLd['url'] ?? $url,
|
||||||
)];
|
)];
|
||||||
}
|
}
|
||||||
|
|
@ -123,11 +143,17 @@ class GenericWebProvider implements InfoProviderInterface
|
||||||
$image = null;
|
$image = null;
|
||||||
if (isset($jsonLd['image'])) {
|
if (isset($jsonLd['image'])) {
|
||||||
if (is_array($jsonLd['image'])) {
|
if (is_array($jsonLd['image'])) {
|
||||||
|
if (array_is_list($jsonLd['image'])) {
|
||||||
$image = $jsonLd['image'][0] ?? null;
|
$image = $jsonLd['image'][0] ?? null;
|
||||||
|
}
|
||||||
} elseif (is_string($jsonLd['image'])) {
|
} elseif (is_string($jsonLd['image'])) {
|
||||||
$image = $jsonLd['image'];
|
$image = $jsonLd['image'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//If image is an object with @type ImageObject, extract the url
|
||||||
|
if (is_array($image) && isset($image['@type']) && $image['@type'] === 'ImageObject') {
|
||||||
|
$image = $image['contentUrl'] ?? $image['url'] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
return new PartDetailDTO(
|
return new PartDetailDTO(
|
||||||
provider_key: $this->getProviderKey(),
|
provider_key: $this->getProviderKey(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue