goods-exporter 1.1.3 → 1.2.1
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/README.md +19 -16
- package/dist/bundle.d.ts +18 -1
- package/dist/cjs/index.cjs +268 -45
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.mjs +268 -46
- package/dist/esm/index.mjs.map +1 -1
- package/dist/package.json +87 -0
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|

|
|
6
6
|
[](https://github.com/Bagi4-source/goods-converter/blob/main/LICENSE)
|
|
7
7
|
|
|
8
|
-
|
|
9
8
|
A versatile JavaScript library for exporting goods data to various formats such as YML, CSV, and Excel. Simplify data
|
|
10
9
|
export tasks with ease.
|
|
11
10
|
|
|
@@ -29,6 +28,7 @@ export tasks with ease.
|
|
|
29
28
|
- TgShop
|
|
30
29
|
- Insales
|
|
31
30
|
- Tilda
|
|
31
|
+
- WooCommerce
|
|
32
32
|
|
|
33
33
|
## Installation
|
|
34
34
|
|
|
@@ -43,14 +43,14 @@ yarn add goods-exporter
|
|
|
43
43
|
## Quick start
|
|
44
44
|
|
|
45
45
|
```typescript
|
|
46
|
-
import { GoodsExporter, Product, Category, Formatters } from
|
|
46
|
+
import { GoodsExporter, Product, Category, Formatters } from "../src";
|
|
47
47
|
import { PassThrough } from "stream";
|
|
48
48
|
|
|
49
49
|
// Create an instance of the GoodsExporter class.
|
|
50
|
-
const exporter = new GoodsExporter()
|
|
50
|
+
const exporter = new GoodsExporter();
|
|
51
51
|
|
|
52
|
-
const products: Product[] = [] // Put your products;
|
|
53
|
-
const categories: Category[] = [{ id: 1, name:
|
|
52
|
+
const products: Product[] = []; // Put your products;
|
|
53
|
+
const categories: Category[] = [{ id: 1, name: "Обувь" }];
|
|
54
54
|
|
|
55
55
|
// Call the data export method.
|
|
56
56
|
const stream = new PassThrough();
|
|
@@ -74,22 +74,24 @@ await exporter.export(products, categories);
|
|
|
74
74
|
import fs from "fs"; // Import the 'fs' module for file writing.
|
|
75
75
|
|
|
76
76
|
// Create an instance of the GoodsExporter class.
|
|
77
|
-
const exporter = new GoodsExporter()
|
|
77
|
+
const exporter = new GoodsExporter();
|
|
78
78
|
|
|
79
79
|
// Define an object 'transformers' that contains data transformation functions.
|
|
80
80
|
const transformers: Transformer[] = [
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
(products) =>
|
|
82
|
+
products.map((product) => ({
|
|
83
|
+
...product,
|
|
84
|
+
price: product.price + 10000,
|
|
84
85
|
})),
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
(products) =>
|
|
87
|
+
products.map((product) => ({
|
|
88
|
+
...product,
|
|
89
|
+
images: product.images?.map((image) => image.replace("image", "pic")),
|
|
90
|
+
})),
|
|
91
|
+
];
|
|
90
92
|
|
|
91
93
|
// Set the formatter for exporting data to YML.
|
|
92
|
-
exporter.setFormatter(new Formatters.YMLFormatter()) // or your own Formatter;
|
|
94
|
+
exporter.setFormatter(new Formatters.YMLFormatter()); // or your own Formatter;
|
|
93
95
|
|
|
94
96
|
// Set transformers based on the specified keys.
|
|
95
97
|
exporter.setTransformers(transformers);
|
|
@@ -99,5 +101,6 @@ exporter.setExporter(fs.createWriteStream("output.yml"));
|
|
|
99
101
|
await exporter.export(products, categories);
|
|
100
102
|
```
|
|
101
103
|
|
|
102
|
-
# Supported by [PoizonAPI](https://t.me/PoizonAPI)
|
|
104
|
+
# Supported by [PoizonAPI](https://t.me/PoizonAPI)
|
|
105
|
+
|
|
103
106
|
[](https://t.me/PoizonAPI)
|
package/dist/bundle.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Writable } from 'stream';
|
|
2
|
+
import { Category as Category$1 } from 'dist/bundle';
|
|
2
3
|
|
|
3
4
|
interface Product {
|
|
4
5
|
/**
|
|
@@ -647,6 +648,19 @@ declare class TildaFormatter implements FormatterAbstract {
|
|
|
647
648
|
format(writableStream: Writable, products: Product[], categories?: Category[], _?: Brand[], __?: FormatterOptions): Promise<void>;
|
|
648
649
|
}
|
|
649
650
|
|
|
651
|
+
declare class WooCommerceFormatter implements FormatterAbstract {
|
|
652
|
+
formatterName: string;
|
|
653
|
+
fileExtension: Extension;
|
|
654
|
+
private readonly DEFAULT_COLUMNS;
|
|
655
|
+
private formatKeyAttribute;
|
|
656
|
+
private formatValueAttribute;
|
|
657
|
+
private formatProducts;
|
|
658
|
+
private createAttribute;
|
|
659
|
+
private extractAttributes;
|
|
660
|
+
private removeVisibleFromAttributes;
|
|
661
|
+
format(writableStream: Writable, products: Product[], categories?: Category[], _?: Brand[], __?: FormatterOptions): Promise<void>;
|
|
662
|
+
}
|
|
663
|
+
|
|
650
664
|
declare class YMLFormatter implements FormatterAbstract {
|
|
651
665
|
formatterName: string;
|
|
652
666
|
fileExtension: Extension;
|
|
@@ -671,6 +685,7 @@ declare const Formatters: {
|
|
|
671
685
|
JSONFormatter: typeof JSONFormatter;
|
|
672
686
|
SimpleJSONFormatter: typeof SimpleJSONFormatter;
|
|
673
687
|
XMLFormatter: typeof XMLFormatter;
|
|
688
|
+
WooCommerceFormatter: typeof WooCommerceFormatter;
|
|
674
689
|
};
|
|
675
690
|
|
|
676
691
|
type Transformer = (products: Product[]) => Product[] | Promise<Product[]>;
|
|
@@ -686,4 +701,6 @@ declare class GoodsExporter {
|
|
|
686
701
|
export(products: Product[], categories?: Category[], brands?: Brand[], option?: FormatterOptions): Promise<void>;
|
|
687
702
|
}
|
|
688
703
|
|
|
689
|
-
|
|
704
|
+
declare const buildCategoryPaths: (categories: Category$1[]) => Map<number, Category$1[]>;
|
|
705
|
+
|
|
706
|
+
export { type Brand, type Category, Currency, type Exporter, Extension, FormatterAbstract, type FormatterOptions, Formatters, GoodsExporter, type IParam, type ISize, type Product, type Transformer, Vat, buildCategoryPaths };
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -6,16 +6,16 @@ var jsonStreamStringify = require('json-stream-stringify');
|
|
|
6
6
|
var fastXmlParser = require('fast-xml-parser');
|
|
7
7
|
var fs = require('fs');
|
|
8
8
|
|
|
9
|
-
var __defProp$
|
|
10
|
-
var __defNormalProp$
|
|
11
|
-
var __publicField$
|
|
9
|
+
var __defProp$b = Object.defineProperty;
|
|
10
|
+
var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __publicField$b = (obj, key, value) => __defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
12
12
|
class CSVStream {
|
|
13
13
|
constructor({ delimiter, lineSeparator, emptyFieldValue }) {
|
|
14
|
-
__publicField$
|
|
15
|
-
__publicField$
|
|
16
|
-
__publicField$
|
|
17
|
-
__publicField$
|
|
18
|
-
__publicField$
|
|
14
|
+
__publicField$b(this, "stream", new stream$3.PassThrough());
|
|
15
|
+
__publicField$b(this, "delimiter", ";");
|
|
16
|
+
__publicField$b(this, "lineSeparator", "\n");
|
|
17
|
+
__publicField$b(this, "emptyFieldValue", "");
|
|
18
|
+
__publicField$b(this, "columns", /* @__PURE__ */ new Set());
|
|
19
19
|
if (delimiter !== void 0) this.delimiter = delimiter;
|
|
20
20
|
if (lineSeparator !== void 0) this.lineSeparator = lineSeparator;
|
|
21
21
|
if (emptyFieldValue !== void 0) this.emptyFieldValue = emptyFieldValue;
|
|
@@ -49,13 +49,13 @@ var Extension = /* @__PURE__ */ ((Extension2) => {
|
|
|
49
49
|
return Extension2;
|
|
50
50
|
})(Extension || {});
|
|
51
51
|
|
|
52
|
-
var __defProp$
|
|
53
|
-
var __defNormalProp$
|
|
54
|
-
var __publicField$
|
|
52
|
+
var __defProp$a = Object.defineProperty;
|
|
53
|
+
var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
54
|
+
var __publicField$a = (obj, key, value) => __defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
55
55
|
class CSVFormatter {
|
|
56
56
|
constructor() {
|
|
57
|
-
__publicField$
|
|
58
|
-
__publicField$
|
|
57
|
+
__publicField$a(this, "formatterName", "CSV");
|
|
58
|
+
__publicField$a(this, "fileExtension", Extension.CSV);
|
|
59
59
|
}
|
|
60
60
|
async format(writableStream, products, categories, _, __) {
|
|
61
61
|
const mappedCategories = {};
|
|
@@ -118,14 +118,14 @@ class CSVFormatter {
|
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
var __defProp$
|
|
122
|
-
var __defNormalProp$
|
|
123
|
-
var __publicField$
|
|
121
|
+
var __defProp$9 = Object.defineProperty;
|
|
122
|
+
var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
123
|
+
var __publicField$9 = (obj, key, value) => __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
124
124
|
const { stream: stream$2 } = pkg;
|
|
125
125
|
class ExcelFormatter {
|
|
126
126
|
constructor() {
|
|
127
|
-
__publicField$
|
|
128
|
-
__publicField$
|
|
127
|
+
__publicField$9(this, "formatterName", "Excel");
|
|
128
|
+
__publicField$9(this, "fileExtension", Extension.XLSX);
|
|
129
129
|
}
|
|
130
130
|
async format(writableStream, products, categories, _, __) {
|
|
131
131
|
const mappedCategories = {};
|
|
@@ -190,14 +190,14 @@ class ExcelFormatter {
|
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
|
|
193
|
-
var __defProp$
|
|
194
|
-
var __defNormalProp$
|
|
195
|
-
var __publicField$
|
|
193
|
+
var __defProp$8 = Object.defineProperty;
|
|
194
|
+
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
195
|
+
var __publicField$8 = (obj, key, value) => __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
196
196
|
const { stream: stream$1 } = pkg;
|
|
197
197
|
class InsalesFormatter {
|
|
198
198
|
constructor() {
|
|
199
|
-
__publicField$
|
|
200
|
-
__publicField$
|
|
199
|
+
__publicField$8(this, "formatterName", "Insales");
|
|
200
|
+
__publicField$8(this, "fileExtension", Extension.XLSX);
|
|
201
201
|
}
|
|
202
202
|
async format(writableStream, products, categories, _, __) {
|
|
203
203
|
const mappedCategories = {};
|
|
@@ -288,8 +288,9 @@ class InsalesFormatter {
|
|
|
288
288
|
key: column
|
|
289
289
|
}));
|
|
290
290
|
products.forEach((product) => {
|
|
291
|
+
const externalId = `${product.productId}-${product.variantId}`;
|
|
291
292
|
const row = {
|
|
292
|
-
"\u0412\u043D\u0435\u0448\u043D\u0438\u0439 ID":
|
|
293
|
+
"\u0412\u043D\u0435\u0448\u043D\u0438\u0439 ID": externalId,
|
|
293
294
|
"\u0421\u0441\u044B\u043B\u043A\u0430 \u043D\u0430 \u0442\u043E\u0432\u0430\u0440": product.url,
|
|
294
295
|
\u0410\u0440\u0442\u0438\u043A\u0443\u043B: product.vendorCode,
|
|
295
296
|
"\u041D\u0430\u0437\u0432\u0430\u043D\u0438\u0435 \u0442\u043E\u0432\u0430\u0440\u0430 \u0438\u043B\u0438 \u0443\u0441\u043B\u0443\u0433\u0438": product.title,
|
|
@@ -326,13 +327,13 @@ class InsalesFormatter {
|
|
|
326
327
|
}
|
|
327
328
|
}
|
|
328
329
|
|
|
329
|
-
var __defProp$
|
|
330
|
-
var __defNormalProp$
|
|
331
|
-
var __publicField$
|
|
330
|
+
var __defProp$7 = Object.defineProperty;
|
|
331
|
+
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
332
|
+
var __publicField$7 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
332
333
|
class JSONFormatter {
|
|
333
334
|
constructor() {
|
|
334
|
-
__publicField$
|
|
335
|
-
__publicField$
|
|
335
|
+
__publicField$7(this, "formatterName", "JSON");
|
|
336
|
+
__publicField$7(this, "fileExtension", Extension.JSON);
|
|
336
337
|
}
|
|
337
338
|
async format(writableStream, products, categories, brands, _) {
|
|
338
339
|
const stream = new jsonStreamStringify.JsonStreamStringify({
|
|
@@ -344,13 +345,13 @@ class JSONFormatter {
|
|
|
344
345
|
}
|
|
345
346
|
}
|
|
346
347
|
|
|
347
|
-
var __defProp$
|
|
348
|
-
var __defNormalProp$
|
|
349
|
-
var __publicField$
|
|
348
|
+
var __defProp$6 = Object.defineProperty;
|
|
349
|
+
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
350
|
+
var __publicField$6 = (obj, key, value) => __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
350
351
|
class SimpleJSONFormatter {
|
|
351
352
|
constructor() {
|
|
352
|
-
__publicField$
|
|
353
|
-
__publicField$
|
|
353
|
+
__publicField$6(this, "formatterName", "JSON");
|
|
354
|
+
__publicField$6(this, "fileExtension", Extension.JSON);
|
|
354
355
|
}
|
|
355
356
|
async format(writableStream, products, categories, brands, _) {
|
|
356
357
|
const groupedProduct = /* @__PURE__ */ new Map();
|
|
@@ -376,14 +377,14 @@ class SimpleJSONFormatter {
|
|
|
376
377
|
}
|
|
377
378
|
}
|
|
378
379
|
|
|
379
|
-
var __defProp$
|
|
380
|
-
var __defNormalProp$
|
|
381
|
-
var __publicField$
|
|
380
|
+
var __defProp$5 = Object.defineProperty;
|
|
381
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
382
|
+
var __publicField$5 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
382
383
|
const { stream } = pkg;
|
|
383
384
|
class TgShopFormatter {
|
|
384
385
|
constructor() {
|
|
385
|
-
__publicField$
|
|
386
|
-
__publicField$
|
|
386
|
+
__publicField$5(this, "formatterName", "TgShop");
|
|
387
|
+
__publicField$5(this, "fileExtension", Extension.XLSX);
|
|
387
388
|
}
|
|
388
389
|
async format(writableStream, products, categories, _, __) {
|
|
389
390
|
const getParameter = (product, key) => product.params?.find((value) => value.key === key);
|
|
@@ -454,13 +455,13 @@ class TgShopFormatter {
|
|
|
454
455
|
}
|
|
455
456
|
}
|
|
456
457
|
|
|
457
|
-
var __defProp$
|
|
458
|
-
var __defNormalProp$
|
|
459
|
-
var __publicField$
|
|
458
|
+
var __defProp$4 = Object.defineProperty;
|
|
459
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
460
|
+
var __publicField$4 = (obj, key, value) => __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
460
461
|
class TildaFormatter {
|
|
461
462
|
constructor() {
|
|
462
|
-
__publicField$
|
|
463
|
-
__publicField$
|
|
463
|
+
__publicField$4(this, "formatterName", "Tilda");
|
|
464
|
+
__publicField$4(this, "fileExtension", Extension.CSV);
|
|
464
465
|
}
|
|
465
466
|
async format(writableStream, products, categories, _, __) {
|
|
466
467
|
const mappedCategories = {};
|
|
@@ -507,6 +508,226 @@ class TildaFormatter {
|
|
|
507
508
|
}
|
|
508
509
|
}
|
|
509
510
|
|
|
511
|
+
const buildCategoryPaths = (categories) => {
|
|
512
|
+
const idToCategory = /* @__PURE__ */ new Map();
|
|
513
|
+
categories.forEach((category) => {
|
|
514
|
+
idToCategory.set(category.id, category);
|
|
515
|
+
});
|
|
516
|
+
const categoryPaths = /* @__PURE__ */ new Map();
|
|
517
|
+
categories.forEach((category) => {
|
|
518
|
+
const path = [];
|
|
519
|
+
let currentCategory = category;
|
|
520
|
+
while (currentCategory) {
|
|
521
|
+
path.unshift(currentCategory);
|
|
522
|
+
if (currentCategory.parentId !== void 0) {
|
|
523
|
+
currentCategory = idToCategory.get(currentCategory.parentId);
|
|
524
|
+
} else {
|
|
525
|
+
currentCategory = void 0;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
categoryPaths.set(category.id, path);
|
|
529
|
+
});
|
|
530
|
+
return categoryPaths;
|
|
531
|
+
};
|
|
532
|
+
|
|
533
|
+
var __defProp$3 = Object.defineProperty;
|
|
534
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
535
|
+
var __publicField$3 = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
536
|
+
class WooCommerceFormatter {
|
|
537
|
+
constructor() {
|
|
538
|
+
__publicField$3(this, "formatterName", "WooCommerce");
|
|
539
|
+
__publicField$3(this, "fileExtension", Extension.CSV);
|
|
540
|
+
__publicField$3(this, "DEFAULT_COLUMNS", [
|
|
541
|
+
"ID",
|
|
542
|
+
"Type",
|
|
543
|
+
"SKU",
|
|
544
|
+
"Name",
|
|
545
|
+
"Parent",
|
|
546
|
+
"Short description",
|
|
547
|
+
"Description",
|
|
548
|
+
"Stock",
|
|
549
|
+
"Regular price",
|
|
550
|
+
"Position",
|
|
551
|
+
"Categories",
|
|
552
|
+
"Tags",
|
|
553
|
+
"Images"
|
|
554
|
+
]);
|
|
555
|
+
}
|
|
556
|
+
formatKeyAttribute(key) {
|
|
557
|
+
const keyWithoutInvalidCharacters = key.replaceAll(",", "").replaceAll(";", "");
|
|
558
|
+
return keyWithoutInvalidCharacters.length >= 28 ? keyWithoutInvalidCharacters.slice(0, 24) + "..." : keyWithoutInvalidCharacters;
|
|
559
|
+
}
|
|
560
|
+
formatValueAttribute(value) {
|
|
561
|
+
return value.replaceAll(",", "").replaceAll(";", "");
|
|
562
|
+
}
|
|
563
|
+
formatProducts(products) {
|
|
564
|
+
const formatParams = (params) => {
|
|
565
|
+
return params?.map(({ key, value }) => {
|
|
566
|
+
const formatedKey = this.formatKeyAttribute(key);
|
|
567
|
+
const formatedValue = this.formatValueAttribute(value);
|
|
568
|
+
return { key: formatedKey, value: formatedValue };
|
|
569
|
+
});
|
|
570
|
+
};
|
|
571
|
+
return products.map((product) => {
|
|
572
|
+
const params = formatParams(product.params);
|
|
573
|
+
const properties = formatParams(product.properties);
|
|
574
|
+
return { ...product, params, properties };
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
createAttribute(data) {
|
|
578
|
+
if (!data?.name || data.id === void 0) return;
|
|
579
|
+
const attributeStartName = "Attribute";
|
|
580
|
+
const attribute = {};
|
|
581
|
+
attribute[`${attributeStartName} ${data.id} name`] = data.name;
|
|
582
|
+
if (data.values !== void 0)
|
|
583
|
+
attribute[`${attributeStartName} ${data.id} value(s)`] = data.values;
|
|
584
|
+
if (data.visible !== void 0)
|
|
585
|
+
attribute[`${attributeStartName} ${data.id} visible`] = data.visible;
|
|
586
|
+
if (data.global !== void 0)
|
|
587
|
+
attribute[`${attributeStartName} ${data.id} global`] = data.global;
|
|
588
|
+
return attribute;
|
|
589
|
+
}
|
|
590
|
+
extractAttributes(products) {
|
|
591
|
+
const formatedProducts = this.formatProducts(products);
|
|
592
|
+
const paramsMap = /* @__PURE__ */ new Map();
|
|
593
|
+
const propertiesMap = /* @__PURE__ */ new Map();
|
|
594
|
+
const uniqueAttributes = /* @__PURE__ */ new Map();
|
|
595
|
+
formatedProducts.forEach((product) => {
|
|
596
|
+
product.params?.forEach(({ key }) => {
|
|
597
|
+
if (!uniqueAttributes.has(key)) {
|
|
598
|
+
uniqueAttributes.set(key, uniqueAttributes.size);
|
|
599
|
+
}
|
|
600
|
+
});
|
|
601
|
+
product.properties?.forEach(({ key }) => {
|
|
602
|
+
if (!uniqueAttributes.has(key)) {
|
|
603
|
+
uniqueAttributes.set(key, uniqueAttributes.size);
|
|
604
|
+
}
|
|
605
|
+
});
|
|
606
|
+
});
|
|
607
|
+
formatedProducts.forEach((product) => {
|
|
608
|
+
const paramAttributes = paramsMap.get(product.variantId) ?? {};
|
|
609
|
+
const propertyAttributes = propertiesMap.get(product.variantId) ?? {};
|
|
610
|
+
product.params?.forEach(({ key, value }) => {
|
|
611
|
+
const index = uniqueAttributes.get(key);
|
|
612
|
+
if (index === void 0) {
|
|
613
|
+
console.error(`\u041D\u0435 \u043D\u0430\u0448\u043B\u043E\u0441\u044C \u0443\u043D\u0438\u043A\u0430\u043B\u044C\u043D\u043E\u0433\u043E \u043A\u043B\u044E\u0447\u0430 \u0434\u043B\u044F \u043F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u0430 - ${key}`);
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
const attribute = this.createAttribute({
|
|
617
|
+
name: key,
|
|
618
|
+
id: index,
|
|
619
|
+
values: value,
|
|
620
|
+
visible: 0,
|
|
621
|
+
global: 0
|
|
622
|
+
});
|
|
623
|
+
if (!attribute) return;
|
|
624
|
+
Object.entries(attribute).forEach(
|
|
625
|
+
([key2, value2]) => paramAttributes[key2] = value2
|
|
626
|
+
);
|
|
627
|
+
});
|
|
628
|
+
product.properties?.forEach(({ key, value }) => {
|
|
629
|
+
const index = uniqueAttributes.get(key);
|
|
630
|
+
if (index === void 0) {
|
|
631
|
+
console.error(`\u041D\u0435 \u043D\u0430\u0448\u043B\u043E\u0441\u044C \u0443\u043D\u0438\u043A\u0430\u043B\u044C\u043D\u043E\u0433\u043E \u043A\u043B\u044E\u0447\u0430 \u0434\u043B\u044F \u043F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u0430 - ${key}`);
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
if (paramAttributes[`Attribute ${index} name`]) {
|
|
635
|
+
console.warn(`\u0414\u0430\u043D\u043D\u043E\u0435 \u0441\u0432\u043E\u0439\u0441\u0442\u0432\u043E \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0432 \u043F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u0430\u0445 - ${key}`);
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
const attribute = this.createAttribute({
|
|
639
|
+
name: key,
|
|
640
|
+
id: index,
|
|
641
|
+
values: value,
|
|
642
|
+
global: 0
|
|
643
|
+
});
|
|
644
|
+
if (!attribute) return;
|
|
645
|
+
Object.entries(attribute).forEach(
|
|
646
|
+
([key2, value2]) => propertyAttributes[key2] = value2
|
|
647
|
+
);
|
|
648
|
+
});
|
|
649
|
+
paramsMap.set(product.variantId, paramAttributes);
|
|
650
|
+
propertiesMap.set(product.variantId, propertyAttributes);
|
|
651
|
+
});
|
|
652
|
+
return { params: paramsMap, properties: propertiesMap };
|
|
653
|
+
}
|
|
654
|
+
removeVisibleFromAttributes(params) {
|
|
655
|
+
Object.entries(params).forEach(([key]) => {
|
|
656
|
+
if (key.includes("visible")) params[key] = "";
|
|
657
|
+
});
|
|
658
|
+
}
|
|
659
|
+
async format(writableStream, products, categories, _, __) {
|
|
660
|
+
const categoriePaths = buildCategoryPaths(categories ?? []);
|
|
661
|
+
const csvStream = new CSVStream({
|
|
662
|
+
delimiter: ";",
|
|
663
|
+
emptyFieldValue: "",
|
|
664
|
+
lineSeparator: "\n"
|
|
665
|
+
});
|
|
666
|
+
csvStream.getWritableStream().pipe(writableStream);
|
|
667
|
+
const columns = new Set(this.DEFAULT_COLUMNS);
|
|
668
|
+
const attributes = this.extractAttributes(products);
|
|
669
|
+
const variations = products.map((product, index) => {
|
|
670
|
+
const pathsArray = categoriePaths.get(product.categoryId)?.map((category) => category.name);
|
|
671
|
+
let row = {
|
|
672
|
+
ID: product.variantId,
|
|
673
|
+
Type: "variation",
|
|
674
|
+
SKU: product.variantId,
|
|
675
|
+
Name: product.title,
|
|
676
|
+
Parent: product.parentId ?? 0,
|
|
677
|
+
"Short description": "",
|
|
678
|
+
Description: product.description,
|
|
679
|
+
Stock: product.count ?? 0,
|
|
680
|
+
"Regular price": product.price,
|
|
681
|
+
Position: index + 1,
|
|
682
|
+
Categories: pathsArray?.join(" > "),
|
|
683
|
+
Tags: product.keywords?.join(","),
|
|
684
|
+
Images: product.images?.join(",")
|
|
685
|
+
};
|
|
686
|
+
const productParams = attributes.params.get(product.variantId) ?? {};
|
|
687
|
+
this.removeVisibleFromAttributes(productParams);
|
|
688
|
+
row = { ...row, ...productParams };
|
|
689
|
+
return row;
|
|
690
|
+
});
|
|
691
|
+
const parentProducts = /* @__PURE__ */ new Map();
|
|
692
|
+
variations.forEach((product) => {
|
|
693
|
+
const currentParent = parentProducts.get(product.Parent);
|
|
694
|
+
let row = {
|
|
695
|
+
...product,
|
|
696
|
+
Type: "variable",
|
|
697
|
+
ID: product.Parent,
|
|
698
|
+
SKU: product.Parent,
|
|
699
|
+
Position: 0,
|
|
700
|
+
Parent: "",
|
|
701
|
+
"Regular price": ""
|
|
702
|
+
};
|
|
703
|
+
row.Stock = (currentParent?.Stock || 0) + (product?.Stock || 0);
|
|
704
|
+
const productParams = attributes.params.get(product.SKU) ?? {};
|
|
705
|
+
const productProperties = attributes.properties.get(product.SKU) ?? {};
|
|
706
|
+
Object.entries(productParams).forEach(([key]) => {
|
|
707
|
+
if (key.includes("visible")) productParams[key] = 0;
|
|
708
|
+
});
|
|
709
|
+
if (currentParent) {
|
|
710
|
+
Object.entries(productParams).forEach(([key, value]) => {
|
|
711
|
+
if (key.includes("value(s)")) {
|
|
712
|
+
productParams[key] = currentParent[key] + `, ${value}`;
|
|
713
|
+
}
|
|
714
|
+
});
|
|
715
|
+
}
|
|
716
|
+
Object.keys({ ...row, ...productParams, ...productProperties }).forEach(
|
|
717
|
+
(item) => columns.add(item)
|
|
718
|
+
);
|
|
719
|
+
row = { ...row, ...productParams, ...productProperties };
|
|
720
|
+
parentProducts.set(product.Parent, row);
|
|
721
|
+
});
|
|
722
|
+
const variableProducts = Array.from(parentProducts.values());
|
|
723
|
+
csvStream.setColumns(columns);
|
|
724
|
+
[...variableProducts, ...variations].forEach((product) => {
|
|
725
|
+
csvStream.addRow(product);
|
|
726
|
+
});
|
|
727
|
+
csvStream.getWritableStream().end();
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
|
|
510
731
|
var __defProp$2 = Object.defineProperty;
|
|
511
732
|
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
512
733
|
var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
@@ -680,7 +901,8 @@ const Formatters = {
|
|
|
680
901
|
ExcelFormatter,
|
|
681
902
|
JSONFormatter,
|
|
682
903
|
SimpleJSONFormatter,
|
|
683
|
-
XMLFormatter
|
|
904
|
+
XMLFormatter,
|
|
905
|
+
WooCommerceFormatter
|
|
684
906
|
};
|
|
685
907
|
|
|
686
908
|
var __defProp = Object.defineProperty;
|
|
@@ -743,4 +965,5 @@ exports.FormatterAbstract = FormatterAbstract;
|
|
|
743
965
|
exports.Formatters = Formatters;
|
|
744
966
|
exports.GoodsExporter = GoodsExporter;
|
|
745
967
|
exports.Vat = Vat;
|
|
968
|
+
exports.buildCategoryPaths = buildCategoryPaths;
|
|
746
969
|
//# sourceMappingURL=index.cjs.map
|