From 7feba634b8f8195e583b851c669b19a35aa011e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sun, 1 Feb 2026 17:20:13 +0100 Subject: [PATCH] Hadle if offers are nested and images are ImageObjects in JSON+LD --- .../Providers/GenericWebProvider.php | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/Services/InfoProviderSystem/Providers/GenericWebProvider.php b/src/Services/InfoProviderSystem/Providers/GenericWebProvider.php index 3c657989..a098c685 100644 --- a/src/Services/InfoProviderSystem/Providers/GenericWebProvider.php +++ b/src/Services/InfoProviderSystem/Providers/GenericWebProvider.php @@ -112,10 +112,30 @@ class GenericWebProvider implements InfoProviderInterface $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( distributor_name: $this->extractShopName($url), 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, )]; } @@ -123,11 +143,17 @@ class GenericWebProvider implements InfoProviderInterface $image = null; if (isset($jsonLd['image'])) { if (is_array($jsonLd['image'])) { - $image = $jsonLd['image'][0] ?? null; + if (array_is_list($jsonLd['image'])) { + $image = $jsonLd['image'][0] ?? null; + } } elseif (is_string($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( provider_key: $this->getProviderKey(),