goods-exporter 1.2.13 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.d.ts +5 -1
- package/dist/cjs/index.cjs +173 -103
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.mjs +172 -104
- package/dist/esm/index.mjs.map +1 -1
- package/package.json +1 -2
package/dist/esm/index.mjs
CHANGED
|
@@ -1,12 +1,60 @@
|
|
|
1
|
+
import { once } from 'events';
|
|
1
2
|
import { PassThrough } from 'stream';
|
|
2
3
|
import pkg from 'exceljs';
|
|
3
4
|
import { JsonStreamStringify } from 'json-stream-stringify';
|
|
4
5
|
import { XMLBuilder } from 'fast-xml-parser';
|
|
5
6
|
import fs from 'fs';
|
|
6
7
|
|
|
8
|
+
const buildCategoryPaths = (categories) => {
|
|
9
|
+
const idToCategory = /* @__PURE__ */ new Map();
|
|
10
|
+
categories.forEach((category) => {
|
|
11
|
+
idToCategory.set(category.id, category);
|
|
12
|
+
});
|
|
13
|
+
const categoryPaths = /* @__PURE__ */ new Map();
|
|
14
|
+
categories.forEach((category) => {
|
|
15
|
+
const path = [];
|
|
16
|
+
let currentCategory = category;
|
|
17
|
+
while (currentCategory) {
|
|
18
|
+
path.unshift(currentCategory);
|
|
19
|
+
if (currentCategory.parentId !== void 0) {
|
|
20
|
+
currentCategory = idToCategory.get(currentCategory.parentId);
|
|
21
|
+
} else {
|
|
22
|
+
currentCategory = void 0;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
categoryPaths.set(category.id, path);
|
|
26
|
+
});
|
|
27
|
+
return categoryPaths;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const writeWithDrain = (stream) => {
|
|
31
|
+
return async (chunk) => {
|
|
32
|
+
const canWrite = stream.write(chunk);
|
|
33
|
+
if (!canWrite) {
|
|
34
|
+
await once(stream, "drain");
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const delay = async (ms) => await new Promise((resolve) => setTimeout(resolve, ms));
|
|
40
|
+
|
|
41
|
+
const urlQueryEncode = (inputUrl) => {
|
|
42
|
+
try {
|
|
43
|
+
const url = new URL(inputUrl);
|
|
44
|
+
url.search = url.search.replace(/^\?/, "").replace(/,/g, "%2C");
|
|
45
|
+
return url.toString();
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.error("Invalid URL:", error);
|
|
48
|
+
return "";
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
7
52
|
var __defProp$b = Object.defineProperty;
|
|
8
53
|
var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
-
var __publicField$b = (obj, key, value) =>
|
|
54
|
+
var __publicField$b = (obj, key, value) => {
|
|
55
|
+
__defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
56
|
+
return value;
|
|
57
|
+
};
|
|
10
58
|
class CSVStream {
|
|
11
59
|
constructor({ delimiter, lineSeparator, emptyFieldValue }) {
|
|
12
60
|
__publicField$b(this, "stream", new PassThrough());
|
|
@@ -14,11 +62,15 @@ class CSVStream {
|
|
|
14
62
|
__publicField$b(this, "lineSeparator", "\n");
|
|
15
63
|
__publicField$b(this, "emptyFieldValue", "");
|
|
16
64
|
__publicField$b(this, "columns", /* @__PURE__ */ new Set());
|
|
17
|
-
|
|
18
|
-
if (
|
|
19
|
-
|
|
65
|
+
__publicField$b(this, "writer", writeWithDrain(this.stream));
|
|
66
|
+
if (delimiter !== void 0)
|
|
67
|
+
this.delimiter = delimiter;
|
|
68
|
+
if (lineSeparator !== void 0)
|
|
69
|
+
this.lineSeparator = lineSeparator;
|
|
70
|
+
if (emptyFieldValue !== void 0)
|
|
71
|
+
this.emptyFieldValue = emptyFieldValue;
|
|
20
72
|
}
|
|
21
|
-
|
|
73
|
+
get writableStream() {
|
|
22
74
|
return this.stream;
|
|
23
75
|
}
|
|
24
76
|
setColumns(columns) {
|
|
@@ -27,12 +79,11 @@ class CSVStream {
|
|
|
27
79
|
Array.from(this.columns).join(this.delimiter) + this.lineSeparator
|
|
28
80
|
);
|
|
29
81
|
}
|
|
30
|
-
addRow(items) {
|
|
31
|
-
this.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
);
|
|
82
|
+
async addRow(items) {
|
|
83
|
+
const data = Array.from(this.columns).map(
|
|
84
|
+
(key) => items[key] === void 0 ? this.emptyFieldValue : items[key] + ""
|
|
85
|
+
).join(this.delimiter) + this.lineSeparator;
|
|
86
|
+
await this.writer(data);
|
|
36
87
|
}
|
|
37
88
|
}
|
|
38
89
|
|
|
@@ -49,7 +100,10 @@ var Extension = /* @__PURE__ */ ((Extension2) => {
|
|
|
49
100
|
|
|
50
101
|
var __defProp$a = Object.defineProperty;
|
|
51
102
|
var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
52
|
-
var __publicField$a = (obj, key, value) =>
|
|
103
|
+
var __publicField$a = (obj, key, value) => {
|
|
104
|
+
__defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
105
|
+
return value;
|
|
106
|
+
};
|
|
53
107
|
class CSVFormatter {
|
|
54
108
|
constructor() {
|
|
55
109
|
__publicField$a(this, "formatterName", "CSV");
|
|
@@ -63,7 +117,7 @@ class CSVFormatter {
|
|
|
63
117
|
emptyFieldValue: "",
|
|
64
118
|
lineSeparator: "\n"
|
|
65
119
|
});
|
|
66
|
-
csvStream.
|
|
120
|
+
csvStream.writableStream.pipe(writableStream);
|
|
67
121
|
const columns = /* @__PURE__ */ new Set([
|
|
68
122
|
"url",
|
|
69
123
|
"productId",
|
|
@@ -94,11 +148,12 @@ class CSVFormatter {
|
|
|
94
148
|
]);
|
|
95
149
|
products.forEach((product) => {
|
|
96
150
|
Object.entries(product).forEach(([key, value]) => {
|
|
97
|
-
if (value)
|
|
151
|
+
if (value)
|
|
152
|
+
columns.add(key);
|
|
98
153
|
});
|
|
99
154
|
});
|
|
100
155
|
csvStream.setColumns(columns);
|
|
101
|
-
|
|
156
|
+
for (const product of products) {
|
|
102
157
|
const row = {
|
|
103
158
|
...product,
|
|
104
159
|
category: mappedCategories[product.categoryId],
|
|
@@ -114,15 +169,18 @@ class CSVFormatter {
|
|
|
114
169
|
timeDeliveryMin: product.timeDelivery?.min,
|
|
115
170
|
timeDeliveryMax: product.timeDelivery?.max
|
|
116
171
|
};
|
|
117
|
-
csvStream.addRow(row);
|
|
118
|
-
}
|
|
119
|
-
csvStream.
|
|
172
|
+
await csvStream.addRow(row);
|
|
173
|
+
}
|
|
174
|
+
csvStream.writableStream.end();
|
|
120
175
|
}
|
|
121
176
|
}
|
|
122
177
|
|
|
123
178
|
var __defProp$9 = Object.defineProperty;
|
|
124
179
|
var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
125
|
-
var __publicField$9 = (obj, key, value) =>
|
|
180
|
+
var __publicField$9 = (obj, key, value) => {
|
|
181
|
+
__defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
182
|
+
return value;
|
|
183
|
+
};
|
|
126
184
|
const { stream: stream$2 } = pkg;
|
|
127
185
|
class ExcelFormatter {
|
|
128
186
|
constructor() {
|
|
@@ -162,7 +220,8 @@ class ExcelFormatter {
|
|
|
162
220
|
]);
|
|
163
221
|
products.forEach((product) => {
|
|
164
222
|
Object.entries(product).forEach(([key, value]) => {
|
|
165
|
-
if (value)
|
|
223
|
+
if (value)
|
|
224
|
+
columns.add(key);
|
|
166
225
|
});
|
|
167
226
|
});
|
|
168
227
|
const workbook = new stream$2.xlsx.WorkbookWriter({
|
|
@@ -198,7 +257,10 @@ class ExcelFormatter {
|
|
|
198
257
|
|
|
199
258
|
var __defProp$8 = Object.defineProperty;
|
|
200
259
|
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
201
|
-
var __publicField$8 = (obj, key, value) =>
|
|
260
|
+
var __publicField$8 = (obj, key, value) => {
|
|
261
|
+
__defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
262
|
+
return value;
|
|
263
|
+
};
|
|
202
264
|
const { stream: stream$1 } = pkg;
|
|
203
265
|
class InsalesFormatter {
|
|
204
266
|
constructor() {
|
|
@@ -228,7 +290,8 @@ class InsalesFormatter {
|
|
|
228
290
|
const categories2 = {};
|
|
229
291
|
const categoryList = new Array();
|
|
230
292
|
function addCategory(categoryId) {
|
|
231
|
-
if (categoryId === void 0)
|
|
293
|
+
if (categoryId === void 0)
|
|
294
|
+
return;
|
|
232
295
|
const category = mappedCategories[categoryId];
|
|
233
296
|
if (category) {
|
|
234
297
|
categoryList.push(category.name);
|
|
@@ -291,7 +354,7 @@ class InsalesFormatter {
|
|
|
291
354
|
header: column,
|
|
292
355
|
key: column
|
|
293
356
|
}));
|
|
294
|
-
|
|
357
|
+
for (const product of products) {
|
|
295
358
|
const externalId = `${product.productId}-${product.variantId}`;
|
|
296
359
|
const row = {
|
|
297
360
|
"\u0412\u043D\u0435\u0448\u043D\u0438\u0439 ID": externalId,
|
|
@@ -311,7 +374,7 @@ class InsalesFormatter {
|
|
|
311
374
|
"\u0413\u0430\u0431\u0430\u0440\u0438\u0442\u044B \u0432\u0430\u0440\u0438\u0430\u043D\u0442\u0430": product.dimensions,
|
|
312
375
|
\u0412\u0435\u0441: product.weight,
|
|
313
376
|
"\u0420\u0430\u0437\u043C\u0435\u0449\u0435\u043D\u0438\u0435 \u043D\u0430 \u0441\u0430\u0439\u0442\u0435": product.available,
|
|
314
|
-
\u041D\u0414\u0421: product.vat
|
|
377
|
+
\u041D\u0414\u0421: product.vat?.toString(),
|
|
315
378
|
"\u0412\u0430\u043B\u044E\u0442\u0430 \u0441\u043A\u043B\u0430\u0434\u0430": product.currency.toString(),
|
|
316
379
|
"\u0418\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u044F \u0432\u0430\u0440\u0438\u0430\u043D\u0442\u0430": product.parentId === void 0 ? product.images?.join(" ") : void 0,
|
|
317
380
|
\u0418\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u044F: product.parentId === void 0 ? void 0 : product.images?.join(" "),
|
|
@@ -323,7 +386,7 @@ class InsalesFormatter {
|
|
|
323
386
|
"\u041A\u043B\u044E\u0447\u0435\u0432\u044B\u0435 \u0441\u043B\u043E\u0432\u0430": product.keywords?.join(",")
|
|
324
387
|
};
|
|
325
388
|
worksheet.addRow(row).commit();
|
|
326
|
-
}
|
|
389
|
+
}
|
|
327
390
|
worksheet.commit();
|
|
328
391
|
await workbook.commit();
|
|
329
392
|
}
|
|
@@ -331,7 +394,10 @@ class InsalesFormatter {
|
|
|
331
394
|
|
|
332
395
|
var __defProp$7 = Object.defineProperty;
|
|
333
396
|
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
334
|
-
var __publicField$7 = (obj, key, value) =>
|
|
397
|
+
var __publicField$7 = (obj, key, value) => {
|
|
398
|
+
__defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
399
|
+
return value;
|
|
400
|
+
};
|
|
335
401
|
class JSONFormatter {
|
|
336
402
|
constructor() {
|
|
337
403
|
__publicField$7(this, "formatterName", "JSON");
|
|
@@ -349,7 +415,10 @@ class JSONFormatter {
|
|
|
349
415
|
|
|
350
416
|
var __defProp$6 = Object.defineProperty;
|
|
351
417
|
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
352
|
-
var __publicField$6 = (obj, key, value) =>
|
|
418
|
+
var __publicField$6 = (obj, key, value) => {
|
|
419
|
+
__defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
420
|
+
return value;
|
|
421
|
+
};
|
|
353
422
|
class SimpleJSONFormatter {
|
|
354
423
|
constructor() {
|
|
355
424
|
__publicField$6(this, "formatterName", "JSON");
|
|
@@ -358,16 +427,19 @@ class SimpleJSONFormatter {
|
|
|
358
427
|
async format(writableStream, products, categories, brands, _) {
|
|
359
428
|
const groupedProduct = /* @__PURE__ */ new Map();
|
|
360
429
|
products.forEach((product) => {
|
|
361
|
-
if (product.parentId !== void 0)
|
|
430
|
+
if (product.parentId !== void 0)
|
|
431
|
+
return;
|
|
362
432
|
groupedProduct.set(product.variantId, {
|
|
363
433
|
...product,
|
|
364
434
|
children: []
|
|
365
435
|
});
|
|
366
436
|
});
|
|
367
437
|
products.forEach((product) => {
|
|
368
|
-
if (product.parentId === void 0)
|
|
438
|
+
if (product.parentId === void 0)
|
|
439
|
+
return;
|
|
369
440
|
const parent = groupedProduct.get(product.parentId);
|
|
370
|
-
if (!parent)
|
|
441
|
+
if (!parent)
|
|
442
|
+
return;
|
|
371
443
|
parent.children.push(product);
|
|
372
444
|
});
|
|
373
445
|
const stream = new JsonStreamStringify({
|
|
@@ -381,7 +453,10 @@ class SimpleJSONFormatter {
|
|
|
381
453
|
|
|
382
454
|
var __defProp$5 = Object.defineProperty;
|
|
383
455
|
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
384
|
-
var __publicField$5 = (obj, key, value) =>
|
|
456
|
+
var __publicField$5 = (obj, key, value) => {
|
|
457
|
+
__defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
458
|
+
return value;
|
|
459
|
+
};
|
|
385
460
|
const { stream } = pkg;
|
|
386
461
|
class TgShopFormatter {
|
|
387
462
|
constructor() {
|
|
@@ -459,7 +534,10 @@ class TgShopFormatter {
|
|
|
459
534
|
|
|
460
535
|
var __defProp$4 = Object.defineProperty;
|
|
461
536
|
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
462
|
-
var __publicField$4 = (obj, key, value) =>
|
|
537
|
+
var __publicField$4 = (obj, key, value) => {
|
|
538
|
+
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
539
|
+
return value;
|
|
540
|
+
};
|
|
463
541
|
class TildaFormatter {
|
|
464
542
|
constructor() {
|
|
465
543
|
__publicField$4(this, "formatterName", "Tilda");
|
|
@@ -473,7 +551,7 @@ class TildaFormatter {
|
|
|
473
551
|
emptyFieldValue: "",
|
|
474
552
|
lineSeparator: "\n"
|
|
475
553
|
});
|
|
476
|
-
csvStream.
|
|
554
|
+
csvStream.writableStream.pipe(writableStream);
|
|
477
555
|
const columns = /* @__PURE__ */ new Set([
|
|
478
556
|
"SKU",
|
|
479
557
|
"Brand",
|
|
@@ -489,7 +567,7 @@ class TildaFormatter {
|
|
|
489
567
|
"Parent UID"
|
|
490
568
|
]);
|
|
491
569
|
csvStream.setColumns(columns);
|
|
492
|
-
|
|
570
|
+
for (const product of products) {
|
|
493
571
|
const row = {
|
|
494
572
|
SKU: product.vendorCode,
|
|
495
573
|
Brand: product.vendor,
|
|
@@ -504,48 +582,18 @@ class TildaFormatter {
|
|
|
504
582
|
"External ID": product.variantId,
|
|
505
583
|
"Parent UID": product.parentId
|
|
506
584
|
};
|
|
507
|
-
csvStream.addRow(row);
|
|
508
|
-
});
|
|
509
|
-
csvStream.getWritableStream().end();
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
const buildCategoryPaths = (categories) => {
|
|
514
|
-
const idToCategory = /* @__PURE__ */ new Map();
|
|
515
|
-
categories.forEach((category) => {
|
|
516
|
-
idToCategory.set(category.id, category);
|
|
517
|
-
});
|
|
518
|
-
const categoryPaths = /* @__PURE__ */ new Map();
|
|
519
|
-
categories.forEach((category) => {
|
|
520
|
-
const path = [];
|
|
521
|
-
let currentCategory = category;
|
|
522
|
-
while (currentCategory) {
|
|
523
|
-
path.unshift(currentCategory);
|
|
524
|
-
if (currentCategory.parentId !== void 0) {
|
|
525
|
-
currentCategory = idToCategory.get(currentCategory.parentId);
|
|
526
|
-
} else {
|
|
527
|
-
currentCategory = void 0;
|
|
528
|
-
}
|
|
585
|
+
await csvStream.addRow(row);
|
|
529
586
|
}
|
|
530
|
-
|
|
531
|
-
});
|
|
532
|
-
return categoryPaths;
|
|
533
|
-
};
|
|
534
|
-
|
|
535
|
-
const urlQueryEncode = (inputUrl) => {
|
|
536
|
-
try {
|
|
537
|
-
const url = new URL(inputUrl);
|
|
538
|
-
url.search = url.search.replace(/^\?/, "").replace(/,/g, "%2C");
|
|
539
|
-
return url.toString();
|
|
540
|
-
} catch (error) {
|
|
541
|
-
console.error("Invalid URL:", error);
|
|
542
|
-
return "";
|
|
587
|
+
csvStream.writableStream.end();
|
|
543
588
|
}
|
|
544
|
-
}
|
|
589
|
+
}
|
|
545
590
|
|
|
546
591
|
var __defProp$3 = Object.defineProperty;
|
|
547
592
|
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
548
|
-
var __publicField$3 = (obj, key, value) =>
|
|
593
|
+
var __publicField$3 = (obj, key, value) => {
|
|
594
|
+
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
595
|
+
return value;
|
|
596
|
+
};
|
|
549
597
|
class WooCommerceFormatter {
|
|
550
598
|
constructor() {
|
|
551
599
|
__publicField$3(this, "formatterName", "WooCommerce");
|
|
@@ -589,7 +637,8 @@ class WooCommerceFormatter {
|
|
|
589
637
|
});
|
|
590
638
|
}
|
|
591
639
|
createAttribute(data) {
|
|
592
|
-
if (!data?.name || data.id === void 0)
|
|
640
|
+
if (!data?.name || data.id === void 0)
|
|
641
|
+
return;
|
|
593
642
|
const attributeStartName = "Attribute";
|
|
594
643
|
const attribute = {};
|
|
595
644
|
attribute[`${attributeStartName} ${data.id} name`] = data.name;
|
|
@@ -636,7 +685,8 @@ class WooCommerceFormatter {
|
|
|
636
685
|
visible: 0,
|
|
637
686
|
global: 0
|
|
638
687
|
});
|
|
639
|
-
if (!attribute)
|
|
688
|
+
if (!attribute)
|
|
689
|
+
return;
|
|
640
690
|
Object.entries(attribute).forEach(
|
|
641
691
|
([key2, value2]) => paramAttributes[key2] = value2
|
|
642
692
|
);
|
|
@@ -669,7 +719,8 @@ class WooCommerceFormatter {
|
|
|
669
719
|
values: value,
|
|
670
720
|
global: 0
|
|
671
721
|
});
|
|
672
|
-
if (!attribute)
|
|
722
|
+
if (!attribute)
|
|
723
|
+
return;
|
|
673
724
|
Object.entries(attribute).forEach(
|
|
674
725
|
([key2, value2]) => propertyAttributes[key2] = value2
|
|
675
726
|
);
|
|
@@ -681,24 +732,25 @@ class WooCommerceFormatter {
|
|
|
681
732
|
}
|
|
682
733
|
removeVisibleFromAttributes(params) {
|
|
683
734
|
Object.entries(params).forEach(([key]) => {
|
|
684
|
-
if (key.includes("visible"))
|
|
735
|
+
if (key.includes("visible"))
|
|
736
|
+
params[key] = "";
|
|
685
737
|
});
|
|
686
738
|
}
|
|
687
739
|
async format(writableStream, products, categories, _, __) {
|
|
688
|
-
const
|
|
740
|
+
const categoryPaths = buildCategoryPaths(categories ?? []);
|
|
689
741
|
const csvStream = new CSVStream({
|
|
690
742
|
delimiter: ";",
|
|
691
743
|
emptyFieldValue: "",
|
|
692
744
|
lineSeparator: "\n"
|
|
693
745
|
});
|
|
694
|
-
csvStream.
|
|
746
|
+
csvStream.writableStream.pipe(writableStream);
|
|
695
747
|
const columns = new Set(this.DEFAULT_COLUMNS);
|
|
696
748
|
const attributes = this.extractAttributes(products);
|
|
697
749
|
const variationsByParentId = /* @__PURE__ */ new Map();
|
|
698
750
|
const imagesByParentId = /* @__PURE__ */ new Map();
|
|
699
751
|
const sizesByParentId = /* @__PURE__ */ new Map();
|
|
700
752
|
const variations = products.map((product, index) => {
|
|
701
|
-
const pathsArray =
|
|
753
|
+
const pathsArray = categoryPaths.get(product.categoryId)?.map((category) => category.name);
|
|
702
754
|
const price = product.price ? product.price : "";
|
|
703
755
|
let row = {
|
|
704
756
|
ID: product.variantId,
|
|
@@ -754,7 +806,8 @@ class WooCommerceFormatter {
|
|
|
754
806
|
const productParams = attributes.params.get(product.SKU) ?? {};
|
|
755
807
|
const productProperties = attributes.properties.get(product.SKU) ?? {};
|
|
756
808
|
Object.entries(productParams).forEach(([key]) => {
|
|
757
|
-
if (key.includes("visible"))
|
|
809
|
+
if (key.includes("visible"))
|
|
810
|
+
productParams[key] = 0;
|
|
758
811
|
});
|
|
759
812
|
if (currentParent) {
|
|
760
813
|
Object.entries(productParams).forEach(([key, value]) => {
|
|
@@ -771,19 +824,24 @@ class WooCommerceFormatter {
|
|
|
771
824
|
});
|
|
772
825
|
const variableProducts = Array.from(parentProducts.values());
|
|
773
826
|
csvStream.setColumns(columns);
|
|
774
|
-
|
|
775
|
-
csvStream.addRow(parentProduct);
|
|
776
|
-
variationsByParentId.get(
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
827
|
+
for (const parentProduct of variableProducts) {
|
|
828
|
+
await csvStream.addRow(parentProduct);
|
|
829
|
+
for (const variationProduct of variationsByParentId.get(
|
|
830
|
+
parentProduct.ID
|
|
831
|
+
) ?? []) {
|
|
832
|
+
await csvStream.addRow(variationProduct);
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
csvStream.writableStream.end();
|
|
781
836
|
}
|
|
782
837
|
}
|
|
783
838
|
|
|
784
839
|
var __defProp$2 = Object.defineProperty;
|
|
785
840
|
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
786
|
-
var __publicField$2 = (obj, key, value) =>
|
|
841
|
+
var __publicField$2 = (obj, key, value) => {
|
|
842
|
+
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
843
|
+
return value;
|
|
844
|
+
};
|
|
787
845
|
class YMLFormatter {
|
|
788
846
|
constructor() {
|
|
789
847
|
__publicField$2(this, "formatterName", "YMl");
|
|
@@ -802,36 +860,38 @@ class YMLFormatter {
|
|
|
802
860
|
result.write('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n');
|
|
803
861
|
result.write('<yml_catalog date="' + date + '">\n');
|
|
804
862
|
result.write("<shop>\n");
|
|
863
|
+
const resultWriter = writeWithDrain(result);
|
|
805
864
|
if (options?.shopName) {
|
|
806
|
-
|
|
807
|
-
|
|
865
|
+
await resultWriter(builder.build({ name: options.shopName }));
|
|
866
|
+
await resultWriter("\n");
|
|
808
867
|
}
|
|
809
868
|
if (options?.companyName) {
|
|
810
|
-
|
|
811
|
-
|
|
869
|
+
await resultWriter(builder.build({ company: options.companyName }));
|
|
870
|
+
await resultWriter("\n");
|
|
812
871
|
}
|
|
813
872
|
if (categories) {
|
|
814
|
-
|
|
873
|
+
await resultWriter(
|
|
815
874
|
builder.build({
|
|
816
875
|
// tagname: "categories",
|
|
817
876
|
categories: { category: this.getCategories(categories) }
|
|
818
877
|
})
|
|
819
878
|
);
|
|
820
|
-
|
|
879
|
+
await resultWriter("\n");
|
|
821
880
|
}
|
|
822
881
|
if (brands) {
|
|
823
|
-
|
|
882
|
+
await resultWriter(
|
|
824
883
|
builder.build({ brands: { brand: this.getBrands(brands) } })
|
|
825
884
|
);
|
|
826
|
-
|
|
885
|
+
await resultWriter("\n");
|
|
827
886
|
}
|
|
828
|
-
|
|
887
|
+
await resultWriter("<offers>\n");
|
|
829
888
|
const offerStream = new PassThrough();
|
|
889
|
+
const offerWriter = writeWithDrain(offerStream);
|
|
830
890
|
offerStream.pipe(result, { end: false });
|
|
831
|
-
|
|
891
|
+
for (const product of products) {
|
|
832
892
|
const offer = builder.build({ offer: this.getOffer(product) });
|
|
833
|
-
|
|
834
|
-
}
|
|
893
|
+
await offerWriter(offer + "\n");
|
|
894
|
+
}
|
|
835
895
|
offerStream.end();
|
|
836
896
|
offerStream.on("end", () => {
|
|
837
897
|
result.write("</offers>\n");
|
|
@@ -841,7 +901,8 @@ class YMLFormatter {
|
|
|
841
901
|
});
|
|
842
902
|
}
|
|
843
903
|
getBrands(brands) {
|
|
844
|
-
if (!brands)
|
|
904
|
+
if (!brands)
|
|
905
|
+
return [];
|
|
845
906
|
return brands.map((brand) => ({
|
|
846
907
|
"@_id": brand.id,
|
|
847
908
|
"@_url": brand.coverURL ?? "",
|
|
@@ -849,7 +910,8 @@ class YMLFormatter {
|
|
|
849
910
|
}));
|
|
850
911
|
}
|
|
851
912
|
getCategories(categories) {
|
|
852
|
-
if (!categories)
|
|
913
|
+
if (!categories)
|
|
914
|
+
return [];
|
|
853
915
|
return categories.map((cat) => ({
|
|
854
916
|
"@_id": cat.id,
|
|
855
917
|
"@_parentId": cat.parentId ?? "",
|
|
@@ -941,7 +1003,10 @@ class YMLFormatter {
|
|
|
941
1003
|
|
|
942
1004
|
var __defProp$1 = Object.defineProperty;
|
|
943
1005
|
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
944
|
-
var __publicField$1 = (obj, key, value) =>
|
|
1006
|
+
var __publicField$1 = (obj, key, value) => {
|
|
1007
|
+
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1008
|
+
return value;
|
|
1009
|
+
};
|
|
945
1010
|
class XMLFormatter extends YMLFormatter {
|
|
946
1011
|
constructor() {
|
|
947
1012
|
super(...arguments);
|
|
@@ -965,7 +1030,10 @@ const Formatters = {
|
|
|
965
1030
|
|
|
966
1031
|
var __defProp = Object.defineProperty;
|
|
967
1032
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
968
|
-
var __publicField = (obj, key, value) =>
|
|
1033
|
+
var __publicField = (obj, key, value) => {
|
|
1034
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1035
|
+
return value;
|
|
1036
|
+
};
|
|
969
1037
|
class GoodsExporter {
|
|
970
1038
|
constructor(context) {
|
|
971
1039
|
this.context = context;
|
|
@@ -1026,5 +1094,5 @@ var Currency = /* @__PURE__ */ ((Currency2) => {
|
|
|
1026
1094
|
return Currency2;
|
|
1027
1095
|
})(Currency || {});
|
|
1028
1096
|
|
|
1029
|
-
export { Currency, Extension, FormatterAbstract, Formatters, GoodsExporter, Vat, buildCategoryPaths, urlQueryEncode };
|
|
1097
|
+
export { Currency, Extension, FormatterAbstract, Formatters, GoodsExporter, Vat, buildCategoryPaths, delay, urlQueryEncode, writeWithDrain };
|
|
1030
1098
|
//# sourceMappingURL=index.mjs.map
|