goods-exporter 1.3.6 → 1.4.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/dist/bundle.d.ts CHANGED
@@ -729,6 +729,8 @@ declare const writeWithDrain: (stream: Writable) => (chunk: any) => Promise<void
729
729
 
730
730
  declare const delay: (ms: number) => Promise<unknown>;
731
731
 
732
+ declare function getRFC3339Date(date: Date): string;
733
+
732
734
  declare const urlQueryEncode: (inputUrl: string) => string;
733
735
 
734
- export { type Brand, type Category, Currency, type Exporter, Extension, FormatterAbstract, type FormatterOptions, Formatters, GoodsExporter, type IParam, type ISize, type Product, type Transformer, Vat, buildCategoryPaths, delay, urlQueryEncode, writeWithDrain };
736
+ export { type Brand, type Category, Currency, type Exporter, Extension, FormatterAbstract, type FormatterOptions, Formatters, GoodsExporter, type IParam, type ISize, type Product, type Transformer, Vat, buildCategoryPaths, delay, getRFC3339Date, urlQueryEncode, writeWithDrain };
@@ -40,6 +40,21 @@ const writeWithDrain = (stream) => {
40
40
 
41
41
  const delay = async (ms) => await new Promise((resolve) => setTimeout(resolve, ms));
42
42
 
43
+ function getRFC3339Date(date) {
44
+ const pad = (n) => n.toString().padStart(2, "0");
45
+ const year = date.getFullYear();
46
+ const month = pad(date.getMonth() + 1);
47
+ const day = pad(date.getDate());
48
+ const hour = pad(date.getHours());
49
+ const min = pad(date.getMinutes());
50
+ const tzOffset = -date.getTimezoneOffset();
51
+ const sign = tzOffset >= 0 ? "+" : "-";
52
+ const absOffset = Math.abs(tzOffset);
53
+ const offsetHour = pad(Math.floor(absOffset / 60));
54
+ const offsetMin = pad(absOffset % 60);
55
+ return `${year}-${month}-${day}T${hour}:${min}${sign}${offsetHour}:${offsetMin}`;
56
+ }
57
+
43
58
  const urlQueryEncode = (inputUrl) => {
44
59
  try {
45
60
  const url = new URL(inputUrl);
@@ -320,6 +335,7 @@ class InsalesFormatter {
320
335
  "\u0418\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u044F \u0432\u0430\u0440\u0438\u0430\u043D\u0442\u0430",
321
336
  "\u0418\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u044F",
322
337
  "\u0421\u0441\u044B\u043B\u043A\u0430 \u043D\u0430 \u0432\u0438\u0434\u0435\u043E",
338
+ "\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440: \u0410\u0440\u0442\u0438\u043A\u0443\u043B",
323
339
  "\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u044B",
324
340
  "\u0421\u0432\u043E\u0439\u0441\u0442\u0432\u0430",
325
341
  "\u0420\u0430\u0437\u043C\u0435\u0440\u043D\u0430\u044F \u0441\u0435\u0442\u043A\u0430",
@@ -343,7 +359,8 @@ class InsalesFormatter {
343
359
  const row = {
344
360
  "\u0412\u043D\u0435\u0448\u043D\u0438\u0439 ID": externalId,
345
361
  "\u0421\u0441\u044B\u043B\u043A\u0430 \u043D\u0430 \u0442\u043E\u0432\u0430\u0440": product.url,
346
- \u0410\u0440\u0442\u0438\u043A\u0443\u043B: product.vendorCode,
362
+ \u0410\u0440\u0442\u0438\u043A\u0443\u043B: externalId,
363
+ // TODO: product.vendorCode,
347
364
  "\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,
348
365
  "\u0412\u0440\u0435\u043C\u044F \u0434\u043E\u0441\u0442\u0430\u0432\u043A\u0438: \u041C\u0438\u043D\u0438\u043C\u0430\u043B\u044C\u043D\u043E\u0435": product.timeDelivery?.min,
349
366
  "\u0412\u0440\u0435\u043C\u044F \u0434\u043E\u0441\u0442\u0430\u0432\u043A\u0438: \u041C\u0430\u043A\u0441\u0438\u043C\u0430\u043B\u044C\u043D\u043E\u0435": product.timeDelivery?.max,
@@ -363,6 +380,8 @@ class InsalesFormatter {
363
380
  "\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,
364
381
  \u0418\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u044F: product.parentId === void 0 ? void 0 : product.images?.join(" "),
365
382
  "\u0421\u0441\u044B\u043B\u043A\u0430 \u043D\u0430 \u0432\u0438\u0434\u0435\u043E": product.videos ? product.videos[0] : void 0,
383
+ "\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440: \u0410\u0440\u0442\u0438\u043A\u0443\u043B": product.vendorCode,
384
+ // TODO: брать из обычных параметров
366
385
  ...getParams(product),
367
386
  ...getProperties(product),
368
387
  "\u0420\u0430\u0437\u043C\u0435\u0440\u043D\u0430\u044F \u0441\u0435\u0442\u043A\u0430": JSON.stringify(product.sizes),
@@ -733,8 +752,7 @@ class WooCommerceFormatter {
733
752
  };
734
753
  const productParams = attributes.params.get(product.variantId) ?? {};
735
754
  if (!imagesByParentId.has(row.Parent)) {
736
- const parentImage = images?.split(",")[0];
737
- imagesByParentId.set(row.Parent, parentImage);
755
+ imagesByParentId.set(row.Parent, images);
738
756
  }
739
757
  if (!sizesByParentId.has(row.Parent)) {
740
758
  sizesByParentId.set(
@@ -815,7 +833,7 @@ class YMLFormatter {
815
833
  format: true,
816
834
  indentBy: " "
817
835
  });
818
- const date = (/* @__PURE__ */ new Date()).toISOString().replace(/.\d+Z/, "");
836
+ const date = getRFC3339Date(/* @__PURE__ */ new Date());
819
837
  result.write('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n');
820
838
  result.write('<yml_catalog date="' + date + '">\n');
821
839
  result.write("<shop>\n");
@@ -848,6 +866,7 @@ class YMLFormatter {
848
866
  const offerWriter = writeWithDrain(offerStream);
849
867
  offerStream.pipe(result, { end: false });
850
868
  for (const product of products) {
869
+ if (product.price === 0) continue;
851
870
  const offer = builder.build({ offer: this.getOffer(product) });
852
871
  await offerWriter(offer + "\n");
853
872
  }
@@ -872,7 +891,7 @@ class YMLFormatter {
872
891
  return categories.map((cat) => ({
873
892
  "@_id": cat.id,
874
893
  "@_parentId": cat.parentId ?? "",
875
- "#text": cat.name
894
+ "#text": cat.name || `\u041A\u0430\u0442\u0435\u0433\u043E\u0440\u0438\u044F #${cat.id}`
876
895
  }));
877
896
  }
878
897
  getOffer(product) {
@@ -938,13 +957,13 @@ class YMLFormatter {
938
957
  dimensions: product.dimensions,
939
958
  boxCount: product.boxCount,
940
959
  disabled: product.disabled,
941
- age: product.age != null && {
960
+ age: product.age ? {
942
961
  "@_unit": product.age.unit,
943
962
  "#text": product.age.value
944
- },
945
- "tn-ved-codes": product.codesTN?.length != null && {
963
+ } : void 0,
964
+ "tn-ved-codes": product.codesTN?.length ? {
946
965
  "tn-ved-code": product.codesTN
947
- },
966
+ } : void 0,
948
967
  relatedProduct: product.relatedProducts,
949
968
  gender: product.gender
950
969
  };
@@ -1053,6 +1072,7 @@ exports.GoodsExporter = GoodsExporter;
1053
1072
  exports.Vat = Vat;
1054
1073
  exports.buildCategoryPaths = buildCategoryPaths;
1055
1074
  exports.delay = delay;
1075
+ exports.getRFC3339Date = getRFC3339Date;
1056
1076
  exports.urlQueryEncode = urlQueryEncode;
1057
1077
  exports.writeWithDrain = writeWithDrain;
1058
1078
  //# sourceMappingURL=index.cjs.map