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 }) + } } }