Added ability to get GTINs for reichelt and Generic WebURL

This commit is contained in:
Jan Böhmer 2026-02-08 15:43:50 +01:00
parent fd76ca12fc
commit 1130f71075
3 changed files with 28 additions and 10 deletions

View file

@ -227,10 +227,11 @@ class GenericWebProvider implements InfoProviderInterface
mpn: $product->mpn?->toString(), mpn: $product->mpn?->toString(),
preview_image_url: $image, preview_image_url: $image,
provider_url: $url, provider_url: $url,
gtin: $product->gtin14?->toString() ?? $product->gtin13?->toString() ?? $product->gtin12?->toString() ?? $product->gtin8?->toString(),
notes: $notes, notes: $notes,
parameters: $parameters, parameters: $parameters,
vendor_infos: $vendor_infos, vendor_infos: $vendor_infos,
mass: $mass mass: $mass,
); );
} }
@ -429,7 +430,8 @@ class GenericWebProvider implements InfoProviderInterface
return [ return [
ProviderCapabilities::BASIC, ProviderCapabilities::BASIC,
ProviderCapabilities::PICTURE, ProviderCapabilities::PICTURE,
ProviderCapabilities::PRICE ProviderCapabilities::PRICE,
ProviderCapabilities::GTIN,
]; ];
} }
} }

View file

@ -84,6 +84,8 @@ class ReicheltProvider implements InfoProviderInterface
$name = $element->filter('meta[itemprop="name"]')->attr('content'); $name = $element->filter('meta[itemprop="name"]')->attr('content');
$sku = $element->filter('meta[itemprop="sku"]')->attr('content'); $sku = $element->filter('meta[itemprop="sku"]')->attr('content');
//Try to extract a picture URL: //Try to extract a picture URL:
$pictureURL = $element->filter("div.al_artlogo img")->attr('src'); $pictureURL = $element->filter("div.al_artlogo img")->attr('src');
@ -95,7 +97,8 @@ class ReicheltProvider implements InfoProviderInterface
category: null, category: null,
manufacturer: $sku, manufacturer: $sku,
preview_image_url: $pictureURL, preview_image_url: $pictureURL,
provider_url: $element->filter('a.al_artinfo_link')->attr('href') provider_url: $element->filter('a.al_artinfo_link')->attr('href'),
); );
}); });
@ -146,6 +149,14 @@ class ReicheltProvider implements InfoProviderInterface
$priceString = $dom->filter('meta[itemprop="price"]')->attr('content'); $priceString = $dom->filter('meta[itemprop="price"]')->attr('content');
$currency = $dom->filter('meta[itemprop="priceCurrency"]')->attr('content', 'EUR'); $currency = $dom->filter('meta[itemprop="priceCurrency"]')->attr('content', 'EUR');
foreach (['gtin13', 'gtin14', 'gtin12', 'gtin8'] as $gtinType) {
if ($dom->filter("[itemprop=\"$gtinType\"]")->count() > 0) {
$gtin = $dom->filter("[itemprop=\"$gtinType\"]")->innerText();
break;
}
}
//Create purchase info //Create purchase info
$purchaseInfo = new PurchaseInfoDTO( $purchaseInfo = new PurchaseInfoDTO(
distributor_name: self::DISTRIBUTOR_NAME, distributor_name: self::DISTRIBUTOR_NAME,
@ -167,10 +178,11 @@ class ReicheltProvider implements InfoProviderInterface
mpn: $this->parseMPN($dom), mpn: $this->parseMPN($dom),
preview_image_url: $json[0]['article_picture'], preview_image_url: $json[0]['article_picture'],
provider_url: $productPage, provider_url: $productPage,
gtin: $gtin,
notes: $notes, notes: $notes,
datasheets: $datasheets, datasheets: $datasheets,
parameters: $this->parseParameters($dom), parameters: $this->parseParameters($dom),
vendor_infos: [$purchaseInfo] vendor_infos: [$purchaseInfo],
); );
} }
@ -273,6 +285,7 @@ class ReicheltProvider implements InfoProviderInterface
ProviderCapabilities::PICTURE, ProviderCapabilities::PICTURE,
ProviderCapabilities::DATASHEET, ProviderCapabilities::DATASHEET,
ProviderCapabilities::PRICE, ProviderCapabilities::PRICE,
ProviderCapabilities::GTIN,
]; ];
} }
} }

View file

@ -159,12 +159,13 @@ class DTOtoEntityConverterTest extends WebTestCase
$shopping_infos = [new PurchaseInfoDTO('TestDistributor', 'TestOrderNumber', [new PriceDTO(1, "10.0", 'EUR')])]; $shopping_infos = [new PurchaseInfoDTO('TestDistributor', 'TestOrderNumber', [new PriceDTO(1, "10.0", 'EUR')])];
$dto = new PartDetailDTO( $dto = new PartDetailDTO(
provider_key: 'test_provider', provider_id: 'test_id', provider_url: 'https://invalid.invalid/test_id', provider_key: 'test_provider', provider_id: 'test_id', name: 'TestPart',
name: 'TestPart', description: 'TestDescription', category: 'TestCategory', description: 'TestDescription', category: 'TestCategory', manufacturer: 'TestManufacturer',
manufacturer: 'TestManufacturer', mpn: 'TestMPN', manufacturing_status: ManufacturingStatus::EOL, mpn: 'TestMPN', preview_image_url: 'https://invalid.invalid/image.png',
preview_image_url: 'https://invalid.invalid/image.png', manufacturing_status: ManufacturingStatus::EOL,
footprint: 'DIP8', notes: 'TestNotes', mass: 10.4, provider_url: 'https://invalid.invalid/test_id',
parameters: $parameters, datasheets: $datasheets, vendor_infos: $shopping_infos, images: $images footprint: 'DIP8', gtin: "1234567890123", notes: 'TestNotes', datasheets: $datasheets,
images: $images, parameters: $parameters, vendor_infos: $shopping_infos, mass: 10.4
); );
$entity = $this->service->convertPart($dto); $entity = $this->service->convertPart($dto);
@ -180,6 +181,8 @@ class DTOtoEntityConverterTest extends WebTestCase
$this->assertEquals($dto->mass, $entity->getMass()); $this->assertEquals($dto->mass, $entity->getMass());
$this->assertEquals($dto->footprint, $entity->getFootprint()); $this->assertEquals($dto->footprint, $entity->getFootprint());
$this->assertEquals($dto->gtin, $entity->getGtin());
//We just check that the lenghts of parameters, datasheets, images and shopping infos are the same //We just check that the lenghts of parameters, datasheets, images and shopping infos are the same
//The actual content is tested in the corresponding tests //The actual content is tested in the corresponding tests
$this->assertCount(count($parameters), $entity->getParameters()); $this->assertCount(count($parameters), $entity->getParameters());