From 39bc40037695931fff5ce765827d3fcad0cc17f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Thu, 20 Feb 2025 00:32:03 +0100 Subject: [PATCH] Added basic price info retrieval from reichelt --- .../InfoProviderSystem/PartInfoRetriever.php | 4 ++-- .../Providers/ReicheltProvider.php | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Services/InfoProviderSystem/PartInfoRetriever.php b/src/Services/InfoProviderSystem/PartInfoRetriever.php index 1a31b197..1db36eee 100644 --- a/src/Services/InfoProviderSystem/PartInfoRetriever.php +++ b/src/Services/InfoProviderSystem/PartInfoRetriever.php @@ -33,8 +33,8 @@ use Symfony\Contracts\Cache\ItemInterface; final class PartInfoRetriever { - private const CACHE_DETAIL_EXPIRATION = 60 * 60 * 24 * 4; // 4 days - private const CACHE_RESULT_EXPIRATION = 60 * 60 * 24 * 7; // 7 days + private const CACHE_DETAIL_EXPIRATION = 5; // 4 days + private const CACHE_RESULT_EXPIRATION = 5; // 7 days public function __construct(private readonly ProviderRegistry $provider_registry, private readonly DTOtoEntityConverter $dto_to_entity_converter, private readonly CacheInterface $partInfoCache) diff --git a/src/Services/InfoProviderSystem/Providers/ReicheltProvider.php b/src/Services/InfoProviderSystem/Providers/ReicheltProvider.php index 6aa4c001..a91d256f 100644 --- a/src/Services/InfoProviderSystem/Providers/ReicheltProvider.php +++ b/src/Services/InfoProviderSystem/Providers/ReicheltProvider.php @@ -26,6 +26,8 @@ namespace App\Services\InfoProviderSystem\Providers; use App\Services\InfoProviderSystem\DTOs\FileDTO; use App\Services\InfoProviderSystem\DTOs\ParameterDTO; use App\Services\InfoProviderSystem\DTOs\PartDetailDTO; +use App\Services\InfoProviderSystem\DTOs\PriceDTO; +use App\Services\InfoProviderSystem\DTOs\PurchaseInfoDTO; use App\Services\InfoProviderSystem\DTOs\SearchResultDTO; use Symfony\Component\DomCrawler\Crawler; use Symfony\Contracts\HttpClient\HttpClientInterface; @@ -33,6 +35,8 @@ use Symfony\Contracts\HttpClient\HttpClientInterface; class ReicheltProvider implements InfoProviderInterface { + public const DISTRIBUTOR_NAME = "Reichelt"; + private const SEARCH_ENDPOINT = "https://www.reichelt.com/index.html?ACTION=446&LA=0&nbc=1&q=%s"; public function __construct(private readonly HttpClientInterface $client) @@ -125,6 +129,16 @@ class ReicheltProvider implements InfoProviderInterface $datasheets[] = new FileDTO($element->attr('href'), $element->filter('span')->text()); }); + //Create purchase info + $purchaseInfo = new PurchaseInfoDTO( + distributor_name: self::DISTRIBUTOR_NAME, + order_number: $json[0]['article_artnr'], + prices: [ + new PriceDTO(1.0, (string) $json[0]['article_price'], 'EUR') + ], + product_url: $productPage + ); + //Create part object return new PartDetailDTO( provider_key: $this->getProviderKey(), @@ -137,7 +151,8 @@ class ReicheltProvider implements InfoProviderInterface provider_url: $productPage, notes: $notes, datasheets: $datasheets, - parameters: $this->parseParameters($dom) + parameters: $this->parseParameters($dom), + vendor_infos: [$purchaseInfo] ); }