mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-02-15 14:09:36 +00:00
Added ability to get GTINs for reichelt and Generic WebURL
This commit is contained in:
parent
fd76ca12fc
commit
1130f71075
3 changed files with 28 additions and 10 deletions
|
|
@ -227,10 +227,11 @@ class GenericWebProvider implements InfoProviderInterface
|
|||
mpn: $product->mpn?->toString(),
|
||||
preview_image_url: $image,
|
||||
provider_url: $url,
|
||||
gtin: $product->gtin14?->toString() ?? $product->gtin13?->toString() ?? $product->gtin12?->toString() ?? $product->gtin8?->toString(),
|
||||
notes: $notes,
|
||||
parameters: $parameters,
|
||||
vendor_infos: $vendor_infos,
|
||||
mass: $mass
|
||||
mass: $mass,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -429,7 +430,8 @@ class GenericWebProvider implements InfoProviderInterface
|
|||
return [
|
||||
ProviderCapabilities::BASIC,
|
||||
ProviderCapabilities::PICTURE,
|
||||
ProviderCapabilities::PRICE
|
||||
ProviderCapabilities::PRICE,
|
||||
ProviderCapabilities::GTIN,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,6 +84,8 @@ class ReicheltProvider implements InfoProviderInterface
|
|||
$name = $element->filter('meta[itemprop="name"]')->attr('content');
|
||||
$sku = $element->filter('meta[itemprop="sku"]')->attr('content');
|
||||
|
||||
|
||||
|
||||
//Try to extract a picture URL:
|
||||
$pictureURL = $element->filter("div.al_artlogo img")->attr('src');
|
||||
|
||||
|
|
@ -95,7 +97,8 @@ class ReicheltProvider implements InfoProviderInterface
|
|||
category: null,
|
||||
manufacturer: $sku,
|
||||
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');
|
||||
$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
|
||||
$purchaseInfo = new PurchaseInfoDTO(
|
||||
distributor_name: self::DISTRIBUTOR_NAME,
|
||||
|
|
@ -167,10 +178,11 @@ class ReicheltProvider implements InfoProviderInterface
|
|||
mpn: $this->parseMPN($dom),
|
||||
preview_image_url: $json[0]['article_picture'],
|
||||
provider_url: $productPage,
|
||||
gtin: $gtin,
|
||||
notes: $notes,
|
||||
datasheets: $datasheets,
|
||||
parameters: $this->parseParameters($dom),
|
||||
vendor_infos: [$purchaseInfo]
|
||||
vendor_infos: [$purchaseInfo],
|
||||
);
|
||||
|
||||
}
|
||||
|
|
@ -273,6 +285,7 @@ class ReicheltProvider implements InfoProviderInterface
|
|||
ProviderCapabilities::PICTURE,
|
||||
ProviderCapabilities::DATASHEET,
|
||||
ProviderCapabilities::PRICE,
|
||||
ProviderCapabilities::GTIN,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -159,12 +159,13 @@ class DTOtoEntityConverterTest extends WebTestCase
|
|||
$shopping_infos = [new PurchaseInfoDTO('TestDistributor', 'TestOrderNumber', [new PriceDTO(1, "10.0", 'EUR')])];
|
||||
|
||||
$dto = new PartDetailDTO(
|
||||
provider_key: 'test_provider', provider_id: 'test_id', provider_url: 'https://invalid.invalid/test_id',
|
||||
name: 'TestPart', description: 'TestDescription', category: 'TestCategory',
|
||||
manufacturer: 'TestManufacturer', mpn: 'TestMPN', manufacturing_status: ManufacturingStatus::EOL,
|
||||
preview_image_url: 'https://invalid.invalid/image.png',
|
||||
footprint: 'DIP8', notes: 'TestNotes', mass: 10.4,
|
||||
parameters: $parameters, datasheets: $datasheets, vendor_infos: $shopping_infos, images: $images
|
||||
provider_key: 'test_provider', provider_id: 'test_id', name: 'TestPart',
|
||||
description: 'TestDescription', category: 'TestCategory', manufacturer: 'TestManufacturer',
|
||||
mpn: 'TestMPN', preview_image_url: 'https://invalid.invalid/image.png',
|
||||
manufacturing_status: ManufacturingStatus::EOL,
|
||||
provider_url: 'https://invalid.invalid/test_id',
|
||||
footprint: 'DIP8', gtin: "1234567890123", notes: 'TestNotes', datasheets: $datasheets,
|
||||
images: $images, parameters: $parameters, vendor_infos: $shopping_infos, mass: 10.4
|
||||
);
|
||||
|
||||
$entity = $this->service->convertPart($dto);
|
||||
|
|
@ -180,6 +181,8 @@ class DTOtoEntityConverterTest extends WebTestCase
|
|||
$this->assertEquals($dto->mass, $entity->getMass());
|
||||
$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
|
||||
//The actual content is tested in the corresponding tests
|
||||
$this->assertCount(count($parameters), $entity->getParameters());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue