From f1c28b9f46b98342a9be5f6744bf2ce455a04f7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Thu, 20 Feb 2025 15:14:59 +0100 Subject: [PATCH] Allow to parse batch prices --- .../Providers/ReicheltProvider.php | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/Services/InfoProviderSystem/Providers/ReicheltProvider.php b/src/Services/InfoProviderSystem/Providers/ReicheltProvider.php index a91d256f..bffb9279 100644 --- a/src/Services/InfoProviderSystem/Providers/ReicheltProvider.php +++ b/src/Services/InfoProviderSystem/Providers/ReicheltProvider.php @@ -135,7 +135,7 @@ class ReicheltProvider implements InfoProviderInterface order_number: $json[0]['article_artnr'], prices: [ new PriceDTO(1.0, (string) $json[0]['article_price'], 'EUR') - ], + ] + $this->parseBatchPrices($dom), product_url: $productPage ); @@ -157,6 +157,35 @@ class ReicheltProvider implements InfoProviderInterface } + private function parseBatchPrices(Crawler $dom): array + { + //Iterate over each a.inline-block element in div.discountValue + $prices = []; + $dom->filter('div.discountValue a.inline-block')->each(function (Crawler $element) use (&$prices) { + //The minimum amount is the number in the span.block element + $minAmountText = $element->filter('span.block')->text(); + + //Extract a integer from the text + $matches = []; + if (!preg_match('/\d+/', $minAmountText, $matches)) { + return; + } + + $minAmount = (int) $matches[0]; + + //The price is the text of the p.productPrice element + $priceString = $element->filter('p.productPrice')->text(); + //Replace comma with dot + $priceString = str_replace(',', '.', $priceString); + //Strip any non-numeric characters + $priceString = preg_replace('/[^0-9.]/', '', $priceString); + + $prices[] = new PriceDTO($minAmount, $priceString, 'EUR'); + }); + + return $prices; + } + private function parseCategory(Crawler $dom): string {