Skip to content

Commit 5e40519

Browse files
committed
Allow to select if VAT should be included or not
1 parent d137521 commit 5e40519

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ PROVIDER_REICHELT_ENABLED=0
227227
PROVIDER_REICHELT_COUNTRY=DE
228228
# The language to get results in (en, de, fr, nl, pl, it, es)
229229
PROVIDER_REICHELT_LANGUAGE=en
230+
# Include VAT in prices (set to 1 to include VAT, 0 to exclude VAT)
231+
PROVIDER_REICHELT_INCLUDE_VAT=1
230232

231233
##################################################################################
232234
# EDA integration related settings

src/Services/InfoProviderSystem/Providers/ReicheltProvider.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ public function __construct(private readonly HttpClientInterface $client,
4646
#[Autowire(env: "PROVIDER_REICHELT_LANGUAGE")]
4747
private readonly string $language = "en",
4848
#[Autowire(env: "PROVIDER_REICHELT_COUNTRY")]
49-
private readonly string $country = "DE")
49+
private readonly string $country = "DE",
50+
#[Autowire(env: "PROVIDER_REICHELT_INCLUDE_VAT")]
51+
private bool $includeVAT = false
52+
)
5053
{
5154
}
5255

@@ -128,7 +131,11 @@ public function getDetails(string $id): PartDetailDTO
128131
$productPage = $this->getBaseURL() . '/shop/product' . $json[0]['article_path'];
129132

130133

131-
$response = $this->client->request('GET', $productPage);
134+
$response = $this->client->request('GET', $productPage, [
135+
'query' => [
136+
'CCTYPE' => $this->includeVAT ? 'private' : 'business',
137+
],
138+
]);
132139
$html = $response->getContent();
133140
$dom = new Crawler($html);
134141

@@ -141,13 +148,17 @@ public function getDetails(string $id): PartDetailDTO
141148
$datasheets[] = new FileDTO($element->attr('href'), $element->filter('span')->text());
142149
});
143150

151+
//Determine price for one unit
152+
$priceString = $dom->filter('meta[itemprop="price"]')->attr('content');
153+
$currency = $dom->filter('meta[itemprop="priceCurrency"]')->attr('content', 'EUR');
154+
144155
//Create purchase info
145156
$purchaseInfo = new PurchaseInfoDTO(
146157
distributor_name: self::DISTRIBUTOR_NAME,
147158
order_number: $json[0]['article_artnr'],
148159
prices: [
149-
new PriceDTO(1.0, (string) $json[0]['article_price'], 'EUR')
150-
] + $this->parseBatchPrices($dom),
160+
new PriceDTO(1.0, $priceString, $currency, $this->includeVAT)
161+
] + $this->parseBatchPrices($dom, $currency),
151162
product_url: $productPage
152163
);
153164

@@ -183,11 +194,11 @@ private function parseMPN(Crawler $dom): ?string
183194
return $element->filter('span')->text();
184195
}
185196

186-
private function parseBatchPrices(Crawler $dom): array
197+
private function parseBatchPrices(Crawler $dom, string $currency): array
187198
{
188199
//Iterate over each a.inline-block element in div.discountValue
189200
$prices = [];
190-
$dom->filter('div.discountValue a.inline-block')->each(function (Crawler $element) use (&$prices) {
201+
$dom->filter('div.discountValue a.inline-block')->each(function (Crawler $element) use (&$prices, $currency) {
191202
//The minimum amount is the number in the span.block element
192203
$minAmountText = $element->filter('span.block')->text();
193204

@@ -206,7 +217,7 @@ private function parseBatchPrices(Crawler $dom): array
206217
//Strip any non-numeric characters
207218
$priceString = preg_replace('/[^0-9.]/', '', $priceString);
208219

209-
$prices[] = new PriceDTO($minAmount, $priceString, 'EUR');
220+
$prices[] = new PriceDTO($minAmount, $priceString, $currency, $this->includeVAT);
210221
});
211222

212223
return $prices;

0 commit comments

Comments
 (0)