Provide footprint information on TMEProvider

This commit is contained in:
Jan Böhmer 2023-07-15 01:52:46 +02:00
parent 94a26ae75a
commit de82249d8d
2 changed files with 17 additions and 2 deletions

View file

@ -28,6 +28,7 @@ use App\Entity\Attachments\PartAttachment;
use App\Entity\Base\AbstractStructuralDBElement; use App\Entity\Base\AbstractStructuralDBElement;
use App\Entity\Parameters\AbstractParameter; use App\Entity\Parameters\AbstractParameter;
use App\Entity\Parameters\PartParameter; use App\Entity\Parameters\PartParameter;
use App\Entity\Parts\Footprint;
use App\Entity\Parts\Manufacturer; use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\ManufacturingStatus; use App\Entity\Parts\ManufacturingStatus;
use App\Entity\Parts\Part; use App\Entity\Parts\Part;
@ -125,6 +126,7 @@ class DTOtoEntityConverter
$entity->setMass($dto->mass); $entity->setMass($dto->mass);
$entity->setManufacturer($this->getOrCreateEntity(Manufacturer::class, $dto->manufacturer)); $entity->setManufacturer($this->getOrCreateEntity(Manufacturer::class, $dto->manufacturer));
$entity->setFootprint($this->getOrCreateEntity(Footprint::class, $dto->footprint));
$entity->setManufacturerProductNumber($dto->mpn ?? ''); $entity->setManufacturerProductNumber($dto->mpn ?? '');
$entity->setManufacturingStatus($dto->manufacturing_status ?? ManufacturingStatus::NOT_SET); $entity->setManufacturingStatus($dto->manufacturing_status ?? ManufacturingStatus::NOT_SET);

View file

@ -115,6 +115,10 @@ class TMEProvider implements InfoProviderInterface
$files = $this->getFiles($id); $files = $this->getFiles($id);
$footprint = null;
$parameters = $this->getParameters($id, $footprint);
return new PartDetailDTO( return new PartDetailDTO(
provider_key: $this->getProviderKey(), provider_key: $this->getProviderKey(),
provider_id: $product['Symbol'], provider_id: $product['Symbol'],
@ -126,8 +130,9 @@ class TMEProvider implements InfoProviderInterface
preview_image_url: $this->normalizeURL($product['Photo']), preview_image_url: $this->normalizeURL($product['Photo']),
manufacturing_status: $this->productStatusArrayToManufacturingStatus($product['ProductStatusList']), manufacturing_status: $this->productStatusArrayToManufacturingStatus($product['ProductStatusList']),
provider_url: $productInfoPage, provider_url: $productInfoPage,
footprint: $footprint,
datasheets: $files['datasheets'], datasheets: $files['datasheets'],
parameters: $this->getParameters($id), parameters: $parameters,
vendor_infos: [$this->getVendorInfo($id, $productInfoPage)], vendor_infos: [$this->getVendorInfo($id, $productInfoPage)],
mass: $product['WeightUnit'] === 'g' ? $product['Weight'] : null, mass: $product['WeightUnit'] === 'g' ? $product['Weight'] : null,
); );
@ -211,9 +216,10 @@ class TMEProvider implements InfoProviderInterface
/** /**
* Fetches the parameters of a product * Fetches the parameters of a product
* @param string $id * @param string $id
* @param string|null $footprint_name You can pass a variable by reference, where the name of the footprint will be stored
* @return ParameterDTO[] * @return ParameterDTO[]
*/ */
public function getParameters(string $id): array public function getParameters(string $id, string|null &$footprint_name = null): array
{ {
$response = $this->tmeClient->makeRequest('Products/GetParameters', [ $response = $this->tmeClient->makeRequest('Products/GetParameters', [
'Country' => $this->country, 'Country' => $this->country,
@ -225,8 +231,15 @@ class TMEProvider implements InfoProviderInterface
$result = []; $result = [];
$footprint_name = null;
foreach($data['ParameterList'] as $parameter) { foreach($data['ParameterList'] as $parameter) {
$result[] = ParameterDTO::parseValueIncludingUnit($parameter['ParameterName'], $parameter['ParameterValue']); $result[] = ParameterDTO::parseValueIncludingUnit($parameter['ParameterName'], $parameter['ParameterValue']);
//Check if the parameter is the case/footprint
if ($parameter['ParameterId'] === 35) {
$footprint_name = $parameter['ParameterValue'];
}
} }
return $result; return $result;