Added basic price info retrieval from reichelt

This commit is contained in:
Jan Böhmer 2025-02-20 00:32:03 +01:00
parent e287918121
commit 39bc400376
2 changed files with 18 additions and 3 deletions

View file

@ -33,8 +33,8 @@ use Symfony\Contracts\Cache\ItemInterface;
final class PartInfoRetriever final class PartInfoRetriever
{ {
private const CACHE_DETAIL_EXPIRATION = 60 * 60 * 24 * 4; // 4 days private const CACHE_DETAIL_EXPIRATION = 5; // 4 days
private const CACHE_RESULT_EXPIRATION = 60 * 60 * 24 * 7; // 7 days private const CACHE_RESULT_EXPIRATION = 5; // 7 days
public function __construct(private readonly ProviderRegistry $provider_registry, public function __construct(private readonly ProviderRegistry $provider_registry,
private readonly DTOtoEntityConverter $dto_to_entity_converter, private readonly CacheInterface $partInfoCache) private readonly DTOtoEntityConverter $dto_to_entity_converter, private readonly CacheInterface $partInfoCache)

View file

@ -26,6 +26,8 @@ namespace App\Services\InfoProviderSystem\Providers;
use App\Services\InfoProviderSystem\DTOs\FileDTO; use App\Services\InfoProviderSystem\DTOs\FileDTO;
use App\Services\InfoProviderSystem\DTOs\ParameterDTO; use App\Services\InfoProviderSystem\DTOs\ParameterDTO;
use App\Services\InfoProviderSystem\DTOs\PartDetailDTO; 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 App\Services\InfoProviderSystem\DTOs\SearchResultDTO;
use Symfony\Component\DomCrawler\Crawler; use Symfony\Component\DomCrawler\Crawler;
use Symfony\Contracts\HttpClient\HttpClientInterface; use Symfony\Contracts\HttpClient\HttpClientInterface;
@ -33,6 +35,8 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
class ReicheltProvider implements InfoProviderInterface 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"; 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) 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()); $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 //Create part object
return new PartDetailDTO( return new PartDetailDTO(
provider_key: $this->getProviderKey(), provider_key: $this->getProviderKey(),
@ -137,7 +151,8 @@ class ReicheltProvider implements InfoProviderInterface
provider_url: $productPage, provider_url: $productPage,
notes: $notes, notes: $notes,
datasheets: $datasheets, datasheets: $datasheets,
parameters: $this->parseParameters($dom) parameters: $this->parseParameters($dom),
vendor_infos: [$purchaseInfo]
); );
} }