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.
@@ -38,6 +38,21 @@ const writeWithDrain = (stream) => {
38
38
 
39
39
  const delay = async (ms) => await new Promise((resolve) => setTimeout(resolve, ms));
40
40
 
41
+ function getRFC3339Date(date) {
42
+ const pad = (n) => n.toString().padStart(2, "0");
43
+ const year = date.getFullYear();
44
+ const month = pad(date.getMonth() + 1);
45
+ const day = pad(date.getDate());
46
+ const hour = pad(date.getHours());
47
+ const min = pad(date.getMinutes());
48
+ const tzOffset = -date.getTimezoneOffset();
49
+ const sign = tzOffset >= 0 ? "+" : "-";
50
+ const absOffset = Math.abs(tzOffset);
51
+ const offsetHour = pad(Math.floor(absOffset / 60));
52
+ const offsetMin = pad(absOffset % 60);
53
+ return `${year}-${month}-${day}T${hour}:${min}${sign}${offsetHour}:${offsetMin}`;
54
+ }
55
+
41
56
  const urlQueryEncode = (inputUrl) => {
42
57
  try {
43
58
  const url = new URL(inputUrl);
@@ -318,6 +333,7 @@ class InsalesFormatter {
318
333
  "\u0418\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u044F \u0432\u0430\u0440\u0438\u0430\u043D\u0442\u0430",
319
334
  "\u0418\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u044F",
320
335
  "\u0421\u0441\u044B\u043B\u043A\u0430 \u043D\u0430 \u0432\u0438\u0434\u0435\u043E",
336
+ "\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440: \u0410\u0440\u0442\u0438\u043A\u0443\u043B",
321
337
  "\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u044B",
322
338
  "\u0421\u0432\u043E\u0439\u0441\u0442\u0432\u0430",
323
339
  "\u0420\u0430\u0437\u043C\u0435\u0440\u043D\u0430\u044F \u0441\u0435\u0442\u043A\u0430",
@@ -341,7 +357,8 @@ class InsalesFormatter {
341
357
  const row = {
342
358
  "\u0412\u043D\u0435\u0448\u043D\u0438\u0439 ID": externalId,
343
359
  "\u0421\u0441\u044B\u043B\u043A\u0430 \u043D\u0430 \u0442\u043E\u0432\u0430\u0440": product.url,
344
- \u0410\u0440\u0442\u0438\u043A\u0443\u043B: product.vendorCode,
360
+ \u0410\u0440\u0442\u0438\u043A\u0443\u043B: externalId,
361
+ // TODO: product.vendorCode,
345
362
  "\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,
346
363
  "\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,
347
364
  "\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,
@@ -361,6 +378,8 @@ class InsalesFormatter {
361
378
  "\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,
362
379
  \u0418\u0437\u043E\u0431\u0440\u0430\u0436\u0435\u043D\u0438\u044F: product.parentId === void 0 ? void 0 : product.images?.join(" "),
363
380
  "\u0421\u0441\u044B\u043B\u043A\u0430 \u043D\u0430 \u0432\u0438\u0434\u0435\u043E": product.videos ? product.videos[0] : void 0,
381
+ "\u041F\u0430\u0440\u0430\u043C\u0435\u0442\u0440: \u0410\u0440\u0442\u0438\u043A\u0443\u043B": product.vendorCode,
382
+ // TODO: брать из обычных параметров
364
383
  ...getParams(product),
365
384
  ...getProperties(product),
366
385
  "\u0420\u0430\u0437\u043C\u0435\u0440\u043D\u0430\u044F \u0441\u0435\u0442\u043A\u0430": JSON.stringify(product.sizes),
@@ -731,8 +750,7 @@ class WooCommerceFormatter {
731
750
  };
732
751
  const productParams = attributes.params.get(product.variantId) ?? {};
733
752
  if (!imagesByParentId.has(row.Parent)) {
734
- const parentImage = images?.split(",")[0];
735
- imagesByParentId.set(row.Parent, parentImage);
753
+ imagesByParentId.set(row.Parent, images);
736
754
  }
737
755
  if (!sizesByParentId.has(row.Parent)) {
738
756
  sizesByParentId.set(
@@ -813,7 +831,7 @@ class YMLFormatter {
813
831
  format: true,
814
832
  indentBy: " "
815
833
  });
816
- const date = (/* @__PURE__ */ new Date()).toISOString().replace(/.\d+Z/, "");
834
+ const date = getRFC3339Date(/* @__PURE__ */ new Date());
817
835
  result.write('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n');
818
836
  result.write('<yml_catalog date="' + date + '">\n');
819
837
  result.write("<shop>\n");
@@ -846,6 +864,7 @@ class YMLFormatter {
846
864
  const offerWriter = writeWithDrain(offerStream);
847
865
  offerStream.pipe(result, { end: false });
848
866
  for (const product of products) {
867
+ if (product.price === 0) continue;
849
868
  const offer = builder.build({ offer: this.getOffer(product) });
850
869
  await offerWriter(offer + "\n");
851
870
  }
@@ -870,7 +889,7 @@ class YMLFormatter {
870
889
  return categories.map((cat) => ({
871
890
  "@_id": cat.id,
872
891
  "@_parentId": cat.parentId ?? "",
873
- "#text": cat.name
892
+ "#text": cat.name || `\u041A\u0430\u0442\u0435\u0433\u043E\u0440\u0438\u044F #${cat.id}`
874
893
  }));
875
894
  }
876
895
  getOffer(product) {
@@ -936,13 +955,13 @@ class YMLFormatter {
936
955
  dimensions: product.dimensions,
937
956
  boxCount: product.boxCount,
938
957
  disabled: product.disabled,
939
- age: product.age != null && {
958
+ age: product.age ? {
940
959
  "@_unit": product.age.unit,
941
960
  "#text": product.age.value
942
- },
943
- "tn-ved-codes": product.codesTN?.length != null && {
961
+ } : void 0,
962
+ "tn-ved-codes": product.codesTN?.length ? {
944
963
  "tn-ved-code": product.codesTN
945
- },
964
+ } : void 0,
946
965
  relatedProduct: product.relatedProducts,
947
966
  gender: product.gender
948
967
  };
@@ -1043,5 +1062,5 @@ var Currency = /* @__PURE__ */ ((Currency2) => {
1043
1062
  return Currency2;
1044
1063
  })(Currency || {});
1045
1064
 
1046
- export { Currency, Extension, FormatterAbstract, Formatters, GoodsExporter, Vat, buildCategoryPaths, delay, urlQueryEncode, writeWithDrain };
1065
+ export { Currency, Extension, FormatterAbstract, Formatters, GoodsExporter, Vat, buildCategoryPaths, delay, getRFC3339Date, urlQueryEncode, writeWithDrain };
1047
1066
  //# sourceMappingURL=index.mjs.map