feat: Improve Buy Box header detection and add Spanish aliases

This commit is contained in:
Christian Vidal Wolf
2026-02-05 08:44:33 +01:00
parent 9a042c6478
commit 299d2032bc
+21 -5
View File
@@ -2180,7 +2180,23 @@ export const processBuyBoxExcel = async (fileOrBuffer: File | ArrayBuffer): Prom
const jsonData: any[][] = XLSX.utils.sheet_to_json(worksheet, { header: 1 });
if (jsonData.length === 0) continue;
const headers: any[] = jsonData[0] || [];
// Find the header row (first row with ASIN or similar)
let headerRowIdx = 0;
let headers: any[] = jsonData[0] || [];
for (let r = 0; r < Math.min(jsonData.length, 10); r++) {
const rowData = jsonData[r];
if (!rowData) continue;
const isHeader = rowData.some(cell => {
const s = String(cell || '').toUpperCase().trim();
return s === 'ASIN' || s.includes('AMAZON ASIN') || s.includes('PRODUCT ID') || s.includes('SKU');
});
if (isHeader) {
headerRowIdx = r;
headers = rowData;
break;
}
}
const asinIdx = headers.findIndex(h => {
const s = String(h || '').toUpperCase().trim();
return s === 'ASIN' || s.includes('AMAZON ASIN') || s.includes('IDENTIFIER') || s.includes('PRODUCT ID') || s.includes('SKU');
@@ -2190,7 +2206,7 @@ export const processBuyBoxExcel = async (fileOrBuffer: File | ArrayBuffer): Prom
// Dynamically find the "Issue Type" or "Reason" column
let reasonIdx = headers.findIndex(h => {
const s = String(h || '').toUpperCase();
return s.includes('ISSUE TYPE') || s.includes('REASON') || s.includes('BUY BOX STATUS') || s.includes('LBB REASON') || s.includes('ESTADO BB') || s.includes('COMENTARIO');
return s.includes('ISSUE TYPE') || s.includes('REASON') || s.includes('BUY BOX STATUS') || s.includes('LBB REASON') || s.includes('ESTADO BB') || s.includes('COMENTARIO') || s.includes('MOTIVO') || s.includes('CAUSA');
});
// Fallback to previous hardcoded indices if header search fails
@@ -2203,10 +2219,10 @@ export const processBuyBoxExcel = async (fileOrBuffer: File | ArrayBuffer): Prom
else reasonIdx = 13;
}
console.log(`[BuyBox] Sheet "${sheetName}" (Country: ${config.country}): ASIN Col=${finalAsinIdx} ("${headers[finalAsinIdx]}"), Reason Col=${reasonIdx} ("${headers[reasonIdx] || 'N/A'}")`);
console.log(`[BuyBox] Sheet "${sheetName}" (Country: ${config.country}): HeaderRow=${headerRowIdx}, ASIN Col=${finalAsinIdx} ("${headers[finalAsinIdx]}"), Reason Col=${reasonIdx} ("${headers[reasonIdx] || 'N/A'}")`);
// Skip header row (index 0)
for (let i = 1; i < jsonData.length; i++) {
// Skip header row and all rows above it
for (let i = headerRowIdx + 1; i < jsonData.length; i++) {
const row = jsonData[i];
if (!row || row.length <= Math.max(finalAsinIdx, reasonIdx)) continue;