fix: ignorer les désactivations lors d'un sync filtré par famille
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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'
|
||||
|
||||
@@ -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,11 +51,14 @@ export function computeDiff(
|
||||
}
|
||||
}
|
||||
|
||||
// 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 })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const summary = {
|
||||
create: changes.filter((c) => c.type === 'create').length,
|
||||
|
||||
Reference in New Issue
Block a user