Allow to extract MPN from reichelt provider

This commit is contained in:
Jan Böhmer 2025-02-20 15:39:35 +01:00
parent f1c28b9f46
commit a798aa9c24

View file

@ -147,6 +147,7 @@ class ReicheltProvider implements InfoProviderInterface
description: $json[0]['article_besch'], description: $json[0]['article_besch'],
category: $this->parseCategory($dom), category: $this->parseCategory($dom),
manufacturer: $json[0]['manufacturer_name'], manufacturer: $json[0]['manufacturer_name'],
mpn: $this->parseMPN($dom),
preview_image_url: $json[0]['article_picture'], preview_image_url: $json[0]['article_picture'],
provider_url: $productPage, provider_url: $productPage,
notes: $notes, notes: $notes,
@ -157,6 +158,19 @@ class ReicheltProvider implements InfoProviderInterface
} }
private function parseMPN(Crawler $dom): ?string
{
//Find the small element directly after meta[itemprop="url"] element
$element = $dom->filter('meta[itemprop="url"] + small');
//If the text contains GTIN text, take the small element afterwards
if (str_contains($element->text(), 'GTIN')) {
$element = $dom->filter('meta[itemprop="url"] + small + small');
}
//The MPN is contained in the span inside the element
return $element->filter('span')->text();
}
private function parseBatchPrices(Crawler $dom): array private function parseBatchPrices(Crawler $dom): array
{ {
//Iterate over each a.inline-block element in div.discountValue //Iterate over each a.inline-block element in div.discountValue