u
This commit is contained in:
@@ -555,9 +555,7 @@ export async function executeCompanyImport({
|
||||
articlesWithPictures.push({ sku, pictureFiles: rawPics });
|
||||
}
|
||||
|
||||
if (i % 25 === 0 || i === totalArticles - 1) {
|
||||
onProgress('articles', i + 1, totalArticles, `${sku} - ${name}`);
|
||||
}
|
||||
onProgress('articles', i + 1, totalArticles, `${sku} - ${name}`);
|
||||
}
|
||||
|
||||
console.log(`[Import] Article pass 1 complete. New: ${articlesImported}, Updated: ${articlesUpdated}`);
|
||||
@@ -712,27 +710,28 @@ export async function executeCompanyImport({
|
||||
console.warn(`[Import] Failed to attach child ${childSku} to parent ${parentSku}:`, err.message);
|
||||
}
|
||||
|
||||
if (processedCount % 20 === 0 || processedCount === variantChildren.length) {
|
||||
onProgress('variants', processedCount, variantChildren.length, `${childSku} -> ${parentSku}`);
|
||||
}
|
||||
onProgress('variants', processedCount, variantChildren.length, `${childSku} -> ${parentSku}`);
|
||||
}
|
||||
}
|
||||
console.log(`[Import] Linked ${variantsLinked}/${variantChildren.length} variants`);
|
||||
|
||||
// ─── Phase 4: Article Pictures Import ────────────────────────────────────
|
||||
console.log(`[Import] Importing pictures for ${articlesWithPictures.length} articles...`);
|
||||
onProgress('images', 0, articlesWithPictures.length, 'Importing article pictures');
|
||||
const imageTasks = [];
|
||||
for (const { sku, pictureFiles } of articlesWithPictures) {
|
||||
const lines = pictureFiles.replace(/\r/g, '\n').split('\n').map((l) => l.trim()).filter(Boolean);
|
||||
for (const relPath of lines) {
|
||||
imageTasks.push({ sku, relPath });
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`[Import] Importing ${imageTasks.length} pictures for ${articlesWithPictures.length} articles...`);
|
||||
onProgress('images', 0, imageTasks.length, 'Starting article pictures import');
|
||||
|
||||
let totalImagesImported = 0;
|
||||
for (let i = 0; i < articlesWithPictures.length; i++) {
|
||||
const { sku, pictureFiles } = articlesWithPictures[i];
|
||||
// Picture files may be separated by newline or semicolon
|
||||
const lines = pictureFiles.replace(/\r/g, '\n').split('\n').map((l) => l.trim()).filter(Boolean);
|
||||
|
||||
for (const relPath of lines) {
|
||||
const imgPath = path.join(importDir, relPath);
|
||||
if (!fs.existsSync(imgPath)) continue;
|
||||
|
||||
for (let i = 0; i < imageTasks.length; i++) {
|
||||
const { sku, relPath } = imageTasks[i];
|
||||
const imgPath = path.join(importDir, relPath);
|
||||
if (fs.existsSync(imgPath)) {
|
||||
try {
|
||||
const imgBuf = fs.readFileSync(imgPath);
|
||||
await store.article.addImage(googleAuthId, sku, imgBuf);
|
||||
@@ -742,10 +741,7 @@ export async function executeCompanyImport({
|
||||
console.warn(`[Import] Image add failed for SKU ${sku} (${relPath}):`, err.message);
|
||||
}
|
||||
}
|
||||
|
||||
if (i % 10 === 0 || i === articlesWithPictures.length - 1) {
|
||||
onProgress('images', i + 1, articlesWithPictures.length, `SKU ${sku} (${lines.length} img)`);
|
||||
}
|
||||
onProgress('images', i + 1, imageTasks.length, `${sku} (${path.basename(relPath)})`);
|
||||
}
|
||||
|
||||
console.log(`[Import] Completed article pictures: ${totalImagesImported} images processed`);
|
||||
@@ -825,15 +821,14 @@ export async function executeCompanyImport({
|
||||
|
||||
if (existingOrderNumbers.has(orderNumber)) {
|
||||
ordersSkipped++;
|
||||
if (i % 50 === 0 || i === totalOrders - 1) {
|
||||
onProgress('orders', i + 1, totalOrders, `${orderNumber} (skipped)`);
|
||||
}
|
||||
onProgress('orders', i + 1, totalOrders, `${orderNumber} (skipped)`);
|
||||
continue;
|
||||
}
|
||||
|
||||
const rawItems = itemsByAuftrag.get(String(m.kAuftrag || '').trim()) || [];
|
||||
if (rawItems.length === 0) {
|
||||
ordersSkipped++;
|
||||
onProgress('orders', i + 1, totalOrders, `${orderNumber} (skipped)`);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -880,9 +875,7 @@ export async function executeCompanyImport({
|
||||
console.warn(`[Import] Failed to create order ${orderNumber}:`, err.message);
|
||||
}
|
||||
|
||||
if (i % 50 === 0 || i === totalOrders - 1) {
|
||||
onProgress('orders', i + 1, totalOrders, orderNumber);
|
||||
}
|
||||
onProgress('orders', i + 1, totalOrders, orderNumber);
|
||||
}
|
||||
|
||||
console.log(`[Import] Orders import complete: ${ordersImported} created, ${ordersSkipped} skipped`);
|
||||
|
||||
Reference in New Issue
Block a user