fix: vérifier le SKU exact dans la réponse Shopify (l'API ignore le filtre sur les SKUs avec tirets)
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 <noreply@anthropic.com>
This commit is contained in:
+4
-3
@@ -36,18 +36,19 @@ export async function searchProductByRef(ref: string): Promise<ShopifyProductRes
|
||||
if (!res.ok) return { found: false }
|
||||
const data = await res.json()
|
||||
const variants = (data.variants ?? []) as Array<{ id: number; sku: string; product_id: number }>
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user