From a2c07896254841f0abf600e838f81434f00a51f9 Mon Sep 17 00:00:00 2001 From: Mathieu Date: Thu, 11 Jun 2026 23:37:29 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20ignorer=20les=20d=C3=A9sactivations=20lo?= =?UTF-8?q?rs=20d'un=20sync=20filtr=C3=A9=20par=20famille?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Quand un onglet est sélectionné, les produits Shopify absents du tab peuvent appartenir à d'autres familles — ne pas les marquer 'deactivate'. Les désactivations ne s'appliquent qu'en mode catalogue complet (sans filtre). Co-Authored-By: Claude Sonnet 4.6 --- src/app/api/sync/preview/route.ts | 2 +- src/lib/syncDiff.ts | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/app/api/sync/preview/route.ts b/src/app/api/sync/preview/route.ts index f0a42d5..f84b321 100644 --- a/src/app/api/sync/preview/route.ts +++ b/src/app/api/sync/preview/route.ts @@ -11,7 +11,7 @@ export async function GET(req: NextRequest) { fetchAllShopifyProducts(), ]) - const diff = computeDiff(sheetProducts, shopifyProducts) + const diff = computeDiff(sheetProducts, shopifyProducts, tab) return NextResponse.json(diff) } catch (err) { const message = err instanceof Error ? err.message : 'Erreur inconnue' diff --git a/src/lib/syncDiff.ts b/src/lib/syncDiff.ts index f13f423..8036da7 100644 --- a/src/lib/syncDiff.ts +++ b/src/lib/syncDiff.ts @@ -18,10 +18,13 @@ function getChangedFields( /** * Calcule le diff entre les produits Sheets et Shopify. * Matching par handle (ref normalisée). + * Si tabFilter est fourni, les désactivations sont ignorées : on ne peut pas savoir + * si un produit Shopify absent du tab appartient à une autre famille ou a été supprimé. */ export function computeDiff( sheetProducts: SyncProduct[], shopifyProducts: ShopifyProductFull[], + tabFilter?: string, ): DiffResult { const shopifyMap = new Map(shopifyProducts.map((p) => [p.handle, p])) const sheetHandles = new Set(sheetProducts.map((p) => p.handle)) @@ -48,9 +51,12 @@ export function computeDiff( } } - for (const shopify of shopifyProducts) { - if (shopify.status === 'active' && !sheetHandles.has(shopify.handle)) { - changes.push({ type: 'deactivate', ref: shopify.ref, shopifyProduct: shopify }) + // Désactivations uniquement en mode catalogue complet (sans filtre par famille) + if (!tabFilter) { + for (const shopify of shopifyProducts) { + if (shopify.status === 'active' && !sheetHandles.has(shopify.handle)) { + changes.push({ type: 'deactivate', ref: shopify.ref, shopifyProduct: shopify }) + } } }