From 15f647f58a71e9c8b3a940b8f83f89b1196e3c62 Mon Sep 17 00:00:00 2001 From: Mathieu Date: Fri, 19 Jun 2026 12:01:02 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20v=C3=A9rifier=20le=20SKU=20exact=20dans?= =?UTF-8?q?=20la=20r=C3=A9ponse=20Shopify=20(l'API=20ignore=20le=20filtre?= =?UTF-8?q?=20sur=20les=20SKUs=20avec=20tirets)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit L'API variants.json ne filtre pas correctement par sku= quand le SKU contient des tirets — elle retourne des variants aléatoires. On vérifie maintenant que le variant retourné a bien le SKU demandé. Co-Authored-By: Claude Sonnet 4.6 --- src/lib/shopify.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lib/shopify.ts b/src/lib/shopify.ts index 005b767..56d50e5 100644 --- a/src/lib/shopify.ts +++ b/src/lib/shopify.ts @@ -36,18 +36,19 @@ export async function searchProductByRef(ref: string): Promise - if (variants.length === 0) return { found: false } + const match = variants.find(v => v.sku === sku) + if (!match) return { found: false } // Récupère le titre du produit const productRes = await fetch( - `${baseUrl}/products/${variants[0].product_id}.json?fields=id,title`, + `${baseUrl}/products/${match.product_id}.json?fields=id,title`, { headers }, ) if (!productRes.ok) return { found: false } const productData = await productRes.json() return { found: true, - shopifyId: String(variants[0].product_id), + shopifyId: String(match.product_id), title: productData.product?.title ?? sku, } }