mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 01:25:55 +02:00
Allow to select if VAT should be included or not
This commit is contained in:
parent
d13752114c
commit
5e40519bc5
2 changed files with 20 additions and 7 deletions
2
.env
2
.env
|
@ -227,6 +227,8 @@ PROVIDER_REICHELT_ENABLED=0
|
||||||
PROVIDER_REICHELT_COUNTRY=DE
|
PROVIDER_REICHELT_COUNTRY=DE
|
||||||
# The language to get results in (en, de, fr, nl, pl, it, es)
|
# The language to get results in (en, de, fr, nl, pl, it, es)
|
||||||
PROVIDER_REICHELT_LANGUAGE=en
|
PROVIDER_REICHELT_LANGUAGE=en
|
||||||
|
# Include VAT in prices (set to 1 to include VAT, 0 to exclude VAT)
|
||||||
|
PROVIDER_REICHELT_INCLUDE_VAT=1
|
||||||
|
|
||||||
##################################################################################
|
##################################################################################
|
||||||
# EDA integration related settings
|
# EDA integration related settings
|
||||||
|
|
|
@ -46,7 +46,10 @@ class ReicheltProvider implements InfoProviderInterface
|
||||||
#[Autowire(env: "PROVIDER_REICHELT_LANGUAGE")]
|
#[Autowire(env: "PROVIDER_REICHELT_LANGUAGE")]
|
||||||
private readonly string $language = "en",
|
private readonly string $language = "en",
|
||||||
#[Autowire(env: "PROVIDER_REICHELT_COUNTRY")]
|
#[Autowire(env: "PROVIDER_REICHELT_COUNTRY")]
|
||||||
private readonly string $country = "DE")
|
private readonly string $country = "DE",
|
||||||
|
#[Autowire(env: "PROVIDER_REICHELT_INCLUDE_VAT")]
|
||||||
|
private bool $includeVAT = false
|
||||||
|
)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +131,11 @@ class ReicheltProvider implements InfoProviderInterface
|
||||||
$productPage = $this->getBaseURL() . '/shop/product' . $json[0]['article_path'];
|
$productPage = $this->getBaseURL() . '/shop/product' . $json[0]['article_path'];
|
||||||
|
|
||||||
|
|
||||||
$response = $this->client->request('GET', $productPage);
|
$response = $this->client->request('GET', $productPage, [
|
||||||
|
'query' => [
|
||||||
|
'CCTYPE' => $this->includeVAT ? 'private' : 'business',
|
||||||
|
],
|
||||||
|
]);
|
||||||
$html = $response->getContent();
|
$html = $response->getContent();
|
||||||
$dom = new Crawler($html);
|
$dom = new Crawler($html);
|
||||||
|
|
||||||
|
@ -141,13 +148,17 @@ class ReicheltProvider implements InfoProviderInterface
|
||||||
$datasheets[] = new FileDTO($element->attr('href'), $element->filter('span')->text());
|
$datasheets[] = new FileDTO($element->attr('href'), $element->filter('span')->text());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//Determine price for one unit
|
||||||
|
$priceString = $dom->filter('meta[itemprop="price"]')->attr('content');
|
||||||
|
$currency = $dom->filter('meta[itemprop="priceCurrency"]')->attr('content', 'EUR');
|
||||||
|
|
||||||
//Create purchase info
|
//Create purchase info
|
||||||
$purchaseInfo = new PurchaseInfoDTO(
|
$purchaseInfo = new PurchaseInfoDTO(
|
||||||
distributor_name: self::DISTRIBUTOR_NAME,
|
distributor_name: self::DISTRIBUTOR_NAME,
|
||||||
order_number: $json[0]['article_artnr'],
|
order_number: $json[0]['article_artnr'],
|
||||||
prices: [
|
prices: [
|
||||||
new PriceDTO(1.0, (string) $json[0]['article_price'], 'EUR')
|
new PriceDTO(1.0, $priceString, $currency, $this->includeVAT)
|
||||||
] + $this->parseBatchPrices($dom),
|
] + $this->parseBatchPrices($dom, $currency),
|
||||||
product_url: $productPage
|
product_url: $productPage
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -183,11 +194,11 @@ class ReicheltProvider implements InfoProviderInterface
|
||||||
return $element->filter('span')->text();
|
return $element->filter('span')->text();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function parseBatchPrices(Crawler $dom): array
|
private function parseBatchPrices(Crawler $dom, string $currency): array
|
||||||
{
|
{
|
||||||
//Iterate over each a.inline-block element in div.discountValue
|
//Iterate over each a.inline-block element in div.discountValue
|
||||||
$prices = [];
|
$prices = [];
|
||||||
$dom->filter('div.discountValue a.inline-block')->each(function (Crawler $element) use (&$prices) {
|
$dom->filter('div.discountValue a.inline-block')->each(function (Crawler $element) use (&$prices, $currency) {
|
||||||
//The minimum amount is the number in the span.block element
|
//The minimum amount is the number in the span.block element
|
||||||
$minAmountText = $element->filter('span.block')->text();
|
$minAmountText = $element->filter('span.block')->text();
|
||||||
|
|
||||||
|
@ -206,7 +217,7 @@ class ReicheltProvider implements InfoProviderInterface
|
||||||
//Strip any non-numeric characters
|
//Strip any non-numeric characters
|
||||||
$priceString = preg_replace('/[^0-9.]/', '', $priceString);
|
$priceString = preg_replace('/[^0-9.]/', '', $priceString);
|
||||||
|
|
||||||
$prices[] = new PriceDTO($minAmount, $priceString, 'EUR');
|
$prices[] = new PriceDTO($minAmount, $priceString, $currency, $this->includeVAT);
|
||||||
});
|
});
|
||||||
|
|
||||||
return $prices;
|
return $prices;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue