goods-exporter 1.1.2 → 1.2.0

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 CHANGED
@@ -5,7 +5,6 @@
5
5
  ![GitHub issues](https://img.shields.io/github/issues/Bagi4-source/goods-converter)
6
6
  [![License](https://img.shields.io/badge/license-MIT-green)](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 '../src';
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
- (products) => products.map(product => ({
82
- ...product,
83
- price: product.price + 10000
81
+ (products) =>
82
+ products.map((product) => ({
83
+ ...product,
84
+ price: product.price + 10000,
84
85
  })),
85
- (products) => products.map(product => ({
86
- ...product,
87
- images: product.images?.map(image => image.replace("image", "pic"))
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
  [![PoizonAPI](https://i.ibb.co/HBbTpp0/Group-1.png)](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;
@@ -656,6 +670,11 @@ declare class YMLFormatter implements FormatterAbstract {
656
670
  private getOffer;
657
671
  }
658
672
 
673
+ declare class XMLFormatter extends YMLFormatter {
674
+ formatterName: string;
675
+ fileExtension: Extension;
676
+ }
677
+
659
678
  declare const Formatters: {
660
679
  TildaFormatter: typeof TildaFormatter;
661
680
  CSVFormatter: typeof CSVFormatter;
@@ -665,6 +684,8 @@ declare const Formatters: {
665
684
  ExcelFormatter: typeof ExcelFormatter;
666
685
  JSONFormatter: typeof JSONFormatter;
667
686
  SimpleJSONFormatter: typeof SimpleJSONFormatter;
687
+ XMLFormatter: typeof XMLFormatter;
688
+ WooCommerceFormatter: typeof WooCommerceFormatter;
668
689
  };
669
690
 
670
691
  type Transformer = (products: Product[]) => Product[] | Promise<Product[]>;
@@ -680,4 +701,6 @@ declare class GoodsExporter {
680
701
  export(products: Product[], categories?: Category[], brands?: Brand[], option?: FormatterOptions): Promise<void>;
681
702
  }
682
703
 
683
- export { type Brand, type Category, Currency, type Exporter, Extension, FormatterAbstract, type FormatterOptions, Formatters, GoodsExporter, type IParam, type ISize, type Product, type Transformer, Vat };
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 };
@@ -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$9 = Object.defineProperty;
10
- var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
- var __publicField$9 = (obj, key, value) => __defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
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$9(this, "stream", new stream$3.PassThrough());
15
- __publicField$9(this, "delimiter", ";");
16
- __publicField$9(this, "lineSeparator", "\n");
17
- __publicField$9(this, "emptyFieldValue", "");
18
- __publicField$9(this, "columns", /* @__PURE__ */ new Set());
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$8 = Object.defineProperty;
53
- var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
54
- var __publicField$8 = (obj, key, value) => __defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
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$8(this, "formatterName", "CSV");
58
- __publicField$8(this, "fileExtension", Extension.CSV);
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$7 = Object.defineProperty;
122
- var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
123
- var __publicField$7 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
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$7(this, "formatterName", "Excel");
128
- __publicField$7(this, "fileExtension", Extension.XLSX);
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$6 = Object.defineProperty;
194
- var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
195
- var __publicField$6 = (obj, key, value) => __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
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$6(this, "formatterName", "Insales");
200
- __publicField$6(this, "fileExtension", Extension.XLSX);
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 = {};
@@ -326,13 +326,13 @@ class InsalesFormatter {
326
326
  }
327
327
  }
328
328
 
329
- var __defProp$5 = Object.defineProperty;
330
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
331
- var __publicField$5 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
329
+ var __defProp$7 = Object.defineProperty;
330
+ var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
331
+ var __publicField$7 = (obj, key, value) => __defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
332
332
  class JSONFormatter {
333
333
  constructor() {
334
- __publicField$5(this, "formatterName", "JSON");
335
- __publicField$5(this, "fileExtension", Extension.JSON);
334
+ __publicField$7(this, "formatterName", "JSON");
335
+ __publicField$7(this, "fileExtension", Extension.JSON);
336
336
  }
337
337
  async format(writableStream, products, categories, brands, _) {
338
338
  const stream = new jsonStreamStringify.JsonStreamStringify({
@@ -344,13 +344,13 @@ class JSONFormatter {
344
344
  }
345
345
  }
346
346
 
347
- var __defProp$4 = Object.defineProperty;
348
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
349
- var __publicField$4 = (obj, key, value) => __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
347
+ var __defProp$6 = Object.defineProperty;
348
+ var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
349
+ var __publicField$6 = (obj, key, value) => __defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
350
350
  class SimpleJSONFormatter {
351
351
  constructor() {
352
- __publicField$4(this, "formatterName", "JSON");
353
- __publicField$4(this, "fileExtension", Extension.JSON);
352
+ __publicField$6(this, "formatterName", "JSON");
353
+ __publicField$6(this, "fileExtension", Extension.JSON);
354
354
  }
355
355
  async format(writableStream, products, categories, brands, _) {
356
356
  const groupedProduct = /* @__PURE__ */ new Map();
@@ -376,14 +376,14 @@ class SimpleJSONFormatter {
376
376
  }
377
377
  }
378
378
 
379
- var __defProp$3 = Object.defineProperty;
380
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
381
- var __publicField$3 = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
379
+ var __defProp$5 = Object.defineProperty;
380
+ var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
381
+ var __publicField$5 = (obj, key, value) => __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
382
382
  const { stream } = pkg;
383
383
  class TgShopFormatter {
384
384
  constructor() {
385
- __publicField$3(this, "formatterName", "TgShop");
386
- __publicField$3(this, "fileExtension", Extension.XLSX);
385
+ __publicField$5(this, "formatterName", "TgShop");
386
+ __publicField$5(this, "fileExtension", Extension.XLSX);
387
387
  }
388
388
  async format(writableStream, products, categories, _, __) {
389
389
  const getParameter = (product, key) => product.params?.find((value) => value.key === key);
@@ -454,13 +454,13 @@ class TgShopFormatter {
454
454
  }
455
455
  }
456
456
 
457
- var __defProp$2 = Object.defineProperty;
458
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
459
- var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
457
+ var __defProp$4 = Object.defineProperty;
458
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
459
+ var __publicField$4 = (obj, key, value) => __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
460
460
  class TildaFormatter {
461
461
  constructor() {
462
- __publicField$2(this, "formatterName", "Tilda");
463
- __publicField$2(this, "fileExtension", Extension.CSV);
462
+ __publicField$4(this, "formatterName", "Tilda");
463
+ __publicField$4(this, "fileExtension", Extension.CSV);
464
464
  }
465
465
  async format(writableStream, products, categories, _, __) {
466
466
  const mappedCategories = {};
@@ -507,13 +507,233 @@ class TildaFormatter {
507
507
  }
508
508
  }
509
509
 
510
- var __defProp$1 = Object.defineProperty;
511
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
512
- var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
510
+ const buildCategoryPaths = (categories) => {
511
+ const idToCategory = /* @__PURE__ */ new Map();
512
+ categories.forEach((category) => {
513
+ idToCategory.set(category.id, category);
514
+ });
515
+ const categoryPaths = /* @__PURE__ */ new Map();
516
+ categories.forEach((category) => {
517
+ const path = [];
518
+ let currentCategory = category;
519
+ while (currentCategory) {
520
+ path.unshift(currentCategory);
521
+ if (currentCategory.parentId !== void 0) {
522
+ currentCategory = idToCategory.get(currentCategory.parentId);
523
+ } else {
524
+ currentCategory = void 0;
525
+ }
526
+ }
527
+ categoryPaths.set(category.id, path);
528
+ });
529
+ return categoryPaths;
530
+ };
531
+
532
+ var __defProp$3 = Object.defineProperty;
533
+ var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
534
+ var __publicField$3 = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
535
+ class WooCommerceFormatter {
536
+ constructor() {
537
+ __publicField$3(this, "formatterName", "WooCommerce");
538
+ __publicField$3(this, "fileExtension", Extension.CSV);
539
+ __publicField$3(this, "DEFAULT_COLUMNS", [
540
+ "ID",
541
+ "Type",
542
+ "SKU",
543
+ "Name",
544
+ "Parent",
545
+ "Short description",
546
+ "Description",
547
+ "Stock",
548
+ "Regular price",
549
+ "Position",
550
+ "Categories",
551
+ "Tags",
552
+ "Images"
553
+ ]);
554
+ }
555
+ formatKeyAttribute(key) {
556
+ const keyWithoutInvalidCharacters = key.replaceAll(",", "").replaceAll(";", "");
557
+ return keyWithoutInvalidCharacters.length >= 28 ? keyWithoutInvalidCharacters.slice(0, 24) + "..." : keyWithoutInvalidCharacters;
558
+ }
559
+ formatValueAttribute(value) {
560
+ return value.replaceAll(",", "").replaceAll(";", "");
561
+ }
562
+ formatProducts(products) {
563
+ const formatParams = (params) => {
564
+ return params?.map(({ key, value }) => {
565
+ const formatedKey = this.formatKeyAttribute(key);
566
+ const formatedValue = this.formatValueAttribute(value);
567
+ return { key: formatedKey, value: formatedValue };
568
+ });
569
+ };
570
+ return products.map((product) => {
571
+ const params = formatParams(product.params);
572
+ const properties = formatParams(product.properties);
573
+ return { ...product, params, properties };
574
+ });
575
+ }
576
+ createAttribute(data) {
577
+ if (!data?.name || data.id === void 0) return;
578
+ const attributeStartName = "Attribute";
579
+ const attribute = {};
580
+ attribute[`${attributeStartName} ${data.id} name`] = data.name;
581
+ if (data.values !== void 0)
582
+ attribute[`${attributeStartName} ${data.id} value(s)`] = data.values;
583
+ if (data.visible !== void 0)
584
+ attribute[`${attributeStartName} ${data.id} visible`] = data.visible;
585
+ if (data.global !== void 0)
586
+ attribute[`${attributeStartName} ${data.id} global`] = data.global;
587
+ return attribute;
588
+ }
589
+ extractAttributes(products) {
590
+ const formatedProducts = this.formatProducts(products);
591
+ const paramsMap = /* @__PURE__ */ new Map();
592
+ const propertiesMap = /* @__PURE__ */ new Map();
593
+ const uniqueAttributes = /* @__PURE__ */ new Map();
594
+ formatedProducts.forEach((product) => {
595
+ product.params?.forEach(({ key }) => {
596
+ if (!uniqueAttributes.has(key)) {
597
+ uniqueAttributes.set(key, uniqueAttributes.size);
598
+ }
599
+ });
600
+ product.properties?.forEach(({ key }) => {
601
+ if (!uniqueAttributes.has(key)) {
602
+ uniqueAttributes.set(key, uniqueAttributes.size);
603
+ }
604
+ });
605
+ });
606
+ formatedProducts.forEach((product) => {
607
+ const paramAttributes = paramsMap.get(product.variantId) ?? {};
608
+ const propertyAttributes = propertiesMap.get(product.variantId) ?? {};
609
+ product.params?.forEach(({ key, value }) => {
610
+ const index = uniqueAttributes.get(key);
611
+ if (index === void 0) {
612
+ 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}`);
613
+ return;
614
+ }
615
+ const attribute = this.createAttribute({
616
+ name: key,
617
+ id: index,
618
+ values: value,
619
+ visible: 0,
620
+ global: 0
621
+ });
622
+ if (!attribute) return;
623
+ Object.entries(attribute).forEach(
624
+ ([key2, value2]) => paramAttributes[key2] = value2
625
+ );
626
+ });
627
+ product.properties?.forEach(({ key, value }) => {
628
+ const index = uniqueAttributes.get(key);
629
+ if (index === void 0) {
630
+ 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}`);
631
+ return;
632
+ }
633
+ if (paramAttributes[`Attribute ${index} name`]) {
634
+ 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}`);
635
+ return;
636
+ }
637
+ const attribute = this.createAttribute({
638
+ name: key,
639
+ id: index,
640
+ values: value,
641
+ global: 0
642
+ });
643
+ if (!attribute) return;
644
+ Object.entries(attribute).forEach(
645
+ ([key2, value2]) => propertyAttributes[key2] = value2
646
+ );
647
+ });
648
+ paramsMap.set(product.variantId, paramAttributes);
649
+ propertiesMap.set(product.variantId, propertyAttributes);
650
+ });
651
+ return { params: paramsMap, properties: propertiesMap };
652
+ }
653
+ removeVisibleFromAttributes(params) {
654
+ Object.entries(params).forEach(([key]) => {
655
+ if (key.includes("visible")) params[key] = "";
656
+ });
657
+ }
658
+ async format(writableStream, products, categories, _, __) {
659
+ const categoriePaths = buildCategoryPaths(categories ?? []);
660
+ const csvStream = new CSVStream({
661
+ delimiter: ";",
662
+ emptyFieldValue: "",
663
+ lineSeparator: "\n"
664
+ });
665
+ csvStream.getWritableStream().pipe(writableStream);
666
+ const columns = new Set(this.DEFAULT_COLUMNS);
667
+ const attributes = this.extractAttributes(products);
668
+ const variations = products.map((product, index) => {
669
+ const pathsArray = categoriePaths.get(product.categoryId)?.map((category) => category.name);
670
+ let row = {
671
+ ID: product.variantId,
672
+ Type: "variation",
673
+ SKU: product.variantId,
674
+ Name: product.title,
675
+ Parent: product.parentId ?? 0,
676
+ "Short description": "",
677
+ Description: product.description,
678
+ Stock: product.count ?? 0,
679
+ "Regular price": product.price,
680
+ Position: index + 1,
681
+ Categories: pathsArray?.join(" > "),
682
+ Tags: product.keywords?.join(","),
683
+ Images: product.images?.join(",")
684
+ };
685
+ const productParams = attributes.params.get(product.variantId) ?? {};
686
+ this.removeVisibleFromAttributes(productParams);
687
+ row = { ...row, ...productParams };
688
+ return row;
689
+ });
690
+ const parentProducts = /* @__PURE__ */ new Map();
691
+ variations.forEach((product) => {
692
+ const currentParent = parentProducts.get(product.Parent);
693
+ let row = {
694
+ ...product,
695
+ Type: "variable",
696
+ ID: product.Parent,
697
+ SKU: product.Parent,
698
+ Position: 0,
699
+ Parent: "",
700
+ "Regular price": ""
701
+ };
702
+ row.Stock = (currentParent?.Stock || 0) + (product?.Stock || 0);
703
+ const productParams = attributes.params.get(product.SKU) ?? {};
704
+ const productProperties = attributes.properties.get(product.SKU) ?? {};
705
+ Object.entries(productParams).forEach(([key]) => {
706
+ if (key.includes("visible")) productParams[key] = 0;
707
+ });
708
+ if (currentParent) {
709
+ Object.entries(productParams).forEach(([key, value]) => {
710
+ if (key.includes("value(s)")) {
711
+ productParams[key] = currentParent[key] + `, ${value}`;
712
+ }
713
+ });
714
+ }
715
+ Object.keys({ ...row, ...productParams, ...productProperties }).forEach(
716
+ (item) => columns.add(item)
717
+ );
718
+ row = { ...row, ...productParams, ...productProperties };
719
+ parentProducts.set(product.Parent, row);
720
+ });
721
+ const variableProducts = Array.from(parentProducts.values());
722
+ csvStream.setColumns(columns);
723
+ [...variableProducts, ...variations].forEach((product) => {
724
+ csvStream.addRow(product);
725
+ });
726
+ csvStream.getWritableStream().end();
727
+ }
728
+ }
729
+
730
+ var __defProp$2 = Object.defineProperty;
731
+ var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
732
+ var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
513
733
  class YMLFormatter {
514
734
  constructor() {
515
- __publicField$1(this, "formatterName", "YMl");
516
- __publicField$1(this, "fileExtension", Extension.YML);
735
+ __publicField$2(this, "formatterName", "YMl");
736
+ __publicField$2(this, "fileExtension", Extension.YML);
517
737
  }
518
738
  async format(writableStream, products, categories, brands, options) {
519
739
  const result = new stream$3.PassThrough();
@@ -660,6 +880,17 @@ class YMLFormatter {
660
880
  }
661
881
  }
662
882
 
883
+ var __defProp$1 = Object.defineProperty;
884
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
885
+ var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
886
+ class XMLFormatter extends YMLFormatter {
887
+ constructor() {
888
+ super(...arguments);
889
+ __publicField$1(this, "formatterName", "XML");
890
+ __publicField$1(this, "fileExtension", Extension.XML);
891
+ }
892
+ }
893
+
663
894
  const Formatters = {
664
895
  TildaFormatter,
665
896
  CSVFormatter,
@@ -668,7 +899,9 @@ const Formatters = {
668
899
  TgShopFormatter,
669
900
  ExcelFormatter,
670
901
  JSONFormatter,
671
- SimpleJSONFormatter
902
+ SimpleJSONFormatter,
903
+ XMLFormatter,
904
+ WooCommerceFormatter
672
905
  };
673
906
 
674
907
  var __defProp = Object.defineProperty;
@@ -731,4 +964,5 @@ exports.FormatterAbstract = FormatterAbstract;
731
964
  exports.Formatters = Formatters;
732
965
  exports.GoodsExporter = GoodsExporter;
733
966
  exports.Vat = Vat;
967
+ exports.buildCategoryPaths = buildCategoryPaths;
734
968
  //# sourceMappingURL=index.cjs.map