From 60c5e24c94eba41f08cda2b1a3bba8cea968cecc Mon Sep 17 00:00:00 2001 From: swdee Date: Mon, 16 Mar 2026 06:57:54 +1300 Subject: [PATCH] Bug fix: Remove fallback from LCSC barcode part resolver (#1302) --- .../BarcodeScanner/BarcodeScanResultHandler.php | 11 +++-------- .../BarcodeScanner/BarcodeScanResultHandlerTest.php | 4 ++-- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/Services/LabelSystem/BarcodeScanner/BarcodeScanResultHandler.php b/src/Services/LabelSystem/BarcodeScanner/BarcodeScanResultHandler.php index 45fdd16e..1927edb9 100644 --- a/src/Services/LabelSystem/BarcodeScanner/BarcodeScanResultHandler.php +++ b/src/Services/LabelSystem/BarcodeScanner/BarcodeScanResultHandler.php @@ -217,8 +217,8 @@ final readonly class BarcodeScanResultHandler * 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) + * 2) Fallback to search across supplier part number (SPN) */ private function resolvePartFromLCSC(LCSCBarcodeScanResult $barcodeScan): ?Part { @@ -231,13 +231,8 @@ final readonly class BarcodeScanResultHandler } } - // Fallback to MPN (pm) - $pm = $barcodeScan->mpn; // e.g. RC0402FR-071ML - if (!$pm) { - return null; - } - - return $this->em->getRepository(Part::class)->getPartByMPN($pm); + // fallback to search by SPN + return $this->em->getRepository(Part::class)->getPartBySPN($pc); } diff --git a/tests/Services/LabelSystem/BarcodeScanner/BarcodeScanResultHandlerTest.php b/tests/Services/LabelSystem/BarcodeScanner/BarcodeScanResultHandlerTest.php index 95313e13..1cfe76b5 100644 --- a/tests/Services/LabelSystem/BarcodeScanner/BarcodeScanResultHandlerTest.php +++ b/tests/Services/LabelSystem/BarcodeScanner/BarcodeScanResultHandlerTest.php @@ -115,8 +115,8 @@ final class BarcodeScanResultHandlerTest extends KernelTestCase 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));