@@ -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