Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ public function resolveEntity(BarcodeScanResultInterface $barcodeScan): Part|Par
}

if ($barcodeScan instanceof LCSCBarcodeScanResult) {
return $this->resolvePartFromLCSC($barcodeScan);
return $this->resolvePartFromLCSC($barcodeScan)
?? $this->em->getRepository(Part::class)->getPartBySPN($barcodeScan->mpn);
}

if ($barcodeScan instanceof AmazonBarcodeScanResult) {
Expand Down Expand Up @@ -217,7 +218,6 @@ private function resolvePartFromVendor(EIGP114BarcodeScanResult $barcodeScan) :
* Resolve LCSC barcode -> Part.
* Strategy:
* 1) Try providerReference.provider_id == pc (LCSC "Cxxxxxx") if you store it there
* 2) Fallback to manufacturer_product_number == pm (MPN)
* Returns first match (consistent with EIGP114 logic)
*/
private function resolvePartFromLCSC(LCSCBarcodeScanResult $barcodeScan): ?Part
Expand All @@ -231,13 +231,8 @@ private function resolvePartFromLCSC(LCSCBarcodeScanResult $barcodeScan): ?Part
}
}

// Fallback to MPN (pm)
$pm = $barcodeScan->mpn; // e.g. RC0402FR-071ML
if (!$pm) {
return null;
}

return $this->em->getRepository(Part::class)->getPartByMPN($pm);
// part does not exist in DB
return null;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ public function testEIGPBarcodeResolvePartOrNullReturnsNullWhenNotFound(): void
public function testLCSCBarcodeResolvePartOrNullReturnsNullWhenNotFound(): void
{
$scan = new LCSCBarcodeScanResult(
fields: ['pc' => 'C0000000', 'pm' => ''],
rawInput: '{pc:C0000000,pm:}'
fields: ['pc' => 'C0000000', 'pm' => 'NON_EXISTENT_MPN_12345'],
rawInput: '{pc:C0000000,pm:NON_EXISTENT_MPN_12345}'
);

$this->assertNull($this->service->resolvePart($scan));
Expand Down
Loading