From da52080e3ebc3096c01d5c967edf4ce9b90875df Mon Sep 17 00:00:00 2001 From: Mathieu Date: Wed, 10 Jun 2026 09:17:22 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20match=20UGS=20en=20pr=C3=A9fixe=20dans?= =?UTF-8?q?=20search-sheets=20pour=20les=20images=20avec=20suffixe=20(dess?= =?UTF-8?q?us,=20-2,=20etc.)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/api/products/search-sheets/route.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/app/api/products/search-sheets/route.ts b/src/app/api/products/search-sheets/route.ts index 8ddba3e..3f96fbc 100644 --- a/src/app/api/products/search-sheets/route.ts +++ b/src/app/api/products/search-sheets/route.ts @@ -46,7 +46,15 @@ export async function GET(req: NextRequest) { // col C = UGS (index 2 car on commence à A) const ugs = (row[2] ?? '').trim() - if (ugs.toLowerCase() === ref.toLowerCase() && shopifyId) { + // Match exact OU le ref commence par l'UGS suivi d'un séparateur + // ex: "REF-1042-dessus" → UGS "REF-1042" ✓ ; "REF-1042 2" → "REF-1042" ✓ + const refLower = ref.toLowerCase() + const ugsLower = ugs.toLowerCase() + const isMatch = ugs && + (refLower === ugsLower || + (refLower.startsWith(ugsLower) && /^[-_ ]/.test(ref.slice(ugs.length)))) + + if (isMatch && shopifyId) { const title = (row[3] ?? '').trim() // col D = Nom return NextResponse.json({ found: true, shopifyId, title }) }