From 1fb9956a15afe9483edd80ca829af19a8f267e9e Mon Sep 17 00:00:00 2001 From: Christian Vidal Wolf Date: Tue, 3 Mar 2026 15:47:56 +0100 Subject: [PATCH] fix(buybox): hardcode reason column for FR/UK/DE, remove STATUS keyword FR/UK/DE sheets have a 'Status' column that appears before 'Reason', causing the dynamic detector to pick the wrong column. Use confirmed indices: FR=col S(18), UK=col J(9), DE=col N(13). Co-Authored-By: Claude Sonnet 4.6 --- services/dataProcessor.ts | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/services/dataProcessor.ts b/services/dataProcessor.ts index 71a047c..8b8a133 100644 --- a/services/dataProcessor.ts +++ b/services/dataProcessor.ts @@ -2582,18 +2582,22 @@ export const processBuyBoxExcel = async (fileOrBuffer: File | ArrayBuffer): Prom continue; } - // Detect reason column from header row keywords - let reasonColIdx = -1; - for (let r = 0; r < Math.min(rows.length, 15); r++) { - const idx = (rows[r] || []).findIndex((cell: any) => { - const s = String(cell || '').toUpperCase(); - return s.includes('ISSUE') || s.includes('REASON') || s.includes('STATUS') || - s.includes('MOTIVO') || s.includes('CAUSA') || s.includes('ESTADO') || - s.includes('COMMENT') || s.includes('OBSERV') || s.includes('SITUAC') || - s.includes('LBB') || s.includes('PROBLEMA') || s.includes('NOTE') || - s.includes('JUSTIF') || s.includes('DETALL'); - }); - if (idx !== -1) { reasonColIdx = idx; break; } + // Known reason column overrides (confirmed by user): FR=S(18), UK=J(9), DE=N(13) + const REASON_COL_OVERRIDE: Record = { FR: 18, UK: 9, DE: 13 }; + let reasonColIdx = REASON_COL_OVERRIDE[country] ?? -1; + + // For countries without a hardcoded override, detect from header keywords + if (reasonColIdx === -1) { + for (let r = 0; r < Math.min(rows.length, 15); r++) { + const idx = (rows[r] || []).findIndex((cell: any) => { + const s = String(cell || '').toUpperCase(); + return s.includes('ISSUE') || s.includes('REASON') || + s.includes('MOTIVO') || s.includes('CAUSA') || s.includes('ESTADO') || + s.includes('COMMENT') || s.includes('OBSERV') || s.includes('SITUAC') || + s.includes('LBB') || s.includes('PROBLEMA') || s.includes('JUSTIF') || s.includes('DETALL'); + }); + if (idx !== -1) { reasonColIdx = idx; break; } + } } console.log(`[BuyBox] Sheet "${sheetName}" → ${country}: asinCol=${asinColIdx} (${maxHits} ASINs found), reasonCol=${reasonColIdx}`);