mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-20 17:15:51 +02:00
Allow to parse batch prices
This commit is contained in:
parent
39bc400376
commit
f1c28b9f46
1 changed files with 30 additions and 1 deletions
|
@ -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
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue