mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 19:45:23 +02:00
feat: Improve Buy Box header detection and add Spanish aliases
This commit is contained in:
@@ -2180,7 +2180,23 @@ export const processBuyBoxExcel = async (fileOrBuffer: File | ArrayBuffer): Prom
|
|||||||
const jsonData: any[][] = XLSX.utils.sheet_to_json(worksheet, { header: 1 });
|
const jsonData: any[][] = XLSX.utils.sheet_to_json(worksheet, { header: 1 });
|
||||||
if (jsonData.length === 0) continue;
|
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 asinIdx = headers.findIndex(h => {
|
||||||
const s = String(h || '').toUpperCase().trim();
|
const s = String(h || '').toUpperCase().trim();
|
||||||
return s === 'ASIN' || s.includes('AMAZON ASIN') || s.includes('IDENTIFIER') || s.includes('PRODUCT ID') || s.includes('SKU');
|
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
|
// Dynamically find the "Issue Type" or "Reason" column
|
||||||
let reasonIdx = headers.findIndex(h => {
|
let reasonIdx = headers.findIndex(h => {
|
||||||
const s = String(h || '').toUpperCase();
|
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
|
// Fallback to previous hardcoded indices if header search fails
|
||||||
@@ -2203,10 +2219,10 @@ export const processBuyBoxExcel = async (fileOrBuffer: File | ArrayBuffer): Prom
|
|||||||
else reasonIdx = 13;
|
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)
|
// Skip header row and all rows above it
|
||||||
for (let i = 1; i < jsonData.length; i++) {
|
for (let i = headerRowIdx + 1; i < jsonData.length; i++) {
|
||||||
const row = jsonData[i];
|
const row = jsonData[i];
|
||||||
if (!row || row.length <= Math.max(finalAsinIdx, reasonIdx)) continue;
|
if (!row || row.length <= Math.max(finalAsinIdx, reasonIdx)) continue;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user