2424namespace App \Services \InfoProviderSystem \Providers ;
2525
2626use App \Services \InfoProviderSystem \DTOs \PartDetailDTO ;
27+ use App \Services \InfoProviderSystem \DTOs \PriceDTO ;
28+ use App \Services \InfoProviderSystem \DTOs \PurchaseInfoDTO ;
2729use App \Services \InfoProviderSystem \DTOs \SearchResultDTO ;
2830use Facebook \WebDriver \Chrome \ChromeOptions ;
2931use Facebook \WebDriver \WebDriverDimension ;
@@ -164,6 +166,30 @@ public function getDetails(string $id): PartDetailDTO
164166 //Remove any script tags. This is just to prevent any weird output in the notes field, this is not really a security measure
165167 $ description = preg_replace ('/<script\b[^>]*>(.*?)<\/script>/is ' , "" , $ description );
166168
169+ //Find price
170+ $ dom = $ client ->waitFor ('span.product-price-value ' );
171+ $ price_str = $ dom ->filter ('span.product-price-value ' )->text ();
172+ //Try to extract the price from the text
173+ $ matches = [];
174+ preg_match ('/([\d,\.]+)/ ' , $ price_str , $ matches );
175+
176+ //Try to parse the price as a float
177+ $ price = str_replace (', ' , '. ' , $ matches [1 ] ?? '0 ' );
178+
179+ $ client ->quit ();
180+
181+ $ price = new PriceDTO (
182+ minimum_discount_amount: 1 ,
183+ price: $ price ,
184+ currency_iso_code: "EUR "
185+ );
186+
187+ $ vendor_info = new PurchaseInfoDTO (
188+ distributor_name: "Aliexpress " ,
189+ order_number: $ id ,
190+ prices: [$ price ],
191+ product_url: $ product_page
192+ );
167193
168194 return new PartDetailDTO (
169195 provider_key: $ this ->getProviderKey (),
@@ -172,6 +198,7 @@ public function getDetails(string $id): PartDetailDTO
172198 description: "" ,
173199 provider_url: $ product_page ,
174200 notes: $ description ,
201+ vendor_infos: [$ vendor_info ]
175202 );
176203 }
177204
0 commit comments