@pisell/pisellos 2.2.258 → 2.2.260

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.
Files changed (90) hide show
  1. package/dist/model/strategy/adapter/dataVariant/adapter.d.ts +49 -0
  2. package/dist/model/strategy/adapter/dataVariant/adapter.js +152 -0
  3. package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +87 -0
  4. package/dist/model/strategy/adapter/dataVariant/evaluator.js +755 -0
  5. package/dist/model/strategy/adapter/dataVariant/examples.d.ts +39 -0
  6. package/dist/model/strategy/adapter/dataVariant/examples.js +282 -0
  7. package/dist/model/strategy/adapter/dataVariant/index.d.ts +4 -0
  8. package/dist/model/strategy/adapter/dataVariant/index.js +4 -0
  9. package/dist/model/strategy/adapter/dataVariant/type.d.ts +146 -0
  10. package/dist/model/strategy/adapter/dataVariant/type.js +54 -0
  11. package/dist/model/strategy/adapter/index.d.ts +4 -0
  12. package/dist/model/strategy/adapter/index.js +5 -1
  13. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +13 -17
  14. package/dist/modules/Order/index.d.ts +2 -30
  15. package/dist/modules/Order/index.js +241 -508
  16. package/dist/modules/Order/types.d.ts +2 -20
  17. package/dist/modules/Order/utils.d.ts +0 -4
  18. package/dist/modules/Order/utils.js +28 -114
  19. package/dist/modules/Product/index.d.ts +1 -1
  20. package/dist/modules/Product/types.d.ts +22 -0
  21. package/dist/modules/ProductList/index.d.ts +1 -1
  22. package/dist/modules/ProductList/index.js +4 -2
  23. package/dist/modules/ProductList/types.d.ts +2 -0
  24. package/dist/modules/Rules/index.d.ts +3 -3
  25. package/dist/modules/Rules/index.js +3 -8
  26. package/dist/modules/Rules/types.d.ts +1 -2
  27. package/dist/server/index.d.ts +50 -3
  28. package/dist/server/index.js +958 -1000
  29. package/dist/server/modules/order/index.d.ts +3 -22
  30. package/dist/server/modules/order/index.js +314 -397
  31. package/dist/server/modules/products/index.d.ts +26 -7
  32. package/dist/server/modules/products/index.js +166 -76
  33. package/dist/server/modules/products/types.d.ts +14 -0
  34. package/dist/solution/BaseSales/index.d.ts +2 -16
  35. package/dist/solution/BaseSales/index.js +314 -484
  36. package/dist/solution/BaseSales/types.d.ts +0 -1
  37. package/dist/solution/BaseSales/types.js +1 -2
  38. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +2 -4
  39. package/dist/solution/BookingByStep/index.d.ts +1 -1
  40. package/dist/solution/BookingTicket/index.d.ts +1 -9
  41. package/dist/solution/BookingTicket/index.js +6 -162
  42. package/dist/solution/BookingTicket/types.d.ts +2 -0
  43. package/lib/model/strategy/adapter/dataVariant/adapter.d.ts +49 -0
  44. package/lib/model/strategy/adapter/dataVariant/adapter.js +139 -0
  45. package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +87 -0
  46. package/lib/model/strategy/adapter/dataVariant/evaluator.js +564 -0
  47. package/lib/model/strategy/adapter/dataVariant/examples.d.ts +39 -0
  48. package/lib/model/strategy/adapter/dataVariant/examples.js +295 -0
  49. package/lib/model/strategy/adapter/dataVariant/index.d.ts +4 -0
  50. package/lib/model/strategy/adapter/dataVariant/index.js +38 -0
  51. package/lib/model/strategy/adapter/dataVariant/type.d.ts +146 -0
  52. package/lib/model/strategy/adapter/dataVariant/type.js +31 -0
  53. package/lib/model/strategy/adapter/index.d.ts +4 -0
  54. package/lib/model/strategy/adapter/index.js +13 -2
  55. package/lib/model/strategy/adapter/promotion/index.js +49 -0
  56. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +1 -11
  57. package/lib/modules/Order/index.d.ts +2 -30
  58. package/lib/modules/Order/index.js +57 -340
  59. package/lib/modules/Order/types.d.ts +2 -20
  60. package/lib/modules/Order/utils.d.ts +0 -4
  61. package/lib/modules/Order/utils.js +2 -84
  62. package/lib/modules/Product/index.d.ts +1 -1
  63. package/lib/modules/Product/types.d.ts +22 -0
  64. package/lib/modules/ProductList/index.d.ts +1 -1
  65. package/lib/modules/ProductList/index.js +4 -2
  66. package/lib/modules/ProductList/types.d.ts +2 -0
  67. package/lib/modules/Rules/index.d.ts +3 -3
  68. package/lib/modules/Rules/index.js +3 -4
  69. package/lib/modules/Rules/types.d.ts +1 -2
  70. package/lib/server/index.d.ts +50 -3
  71. package/lib/server/index.js +215 -230
  72. package/lib/server/modules/order/index.d.ts +3 -22
  73. package/lib/server/modules/order/index.js +51 -102
  74. package/lib/server/modules/products/index.d.ts +26 -7
  75. package/lib/server/modules/products/index.js +113 -35
  76. package/lib/server/modules/products/types.d.ts +14 -0
  77. package/lib/solution/BaseSales/index.d.ts +2 -16
  78. package/lib/solution/BaseSales/index.js +31 -143
  79. package/lib/solution/BaseSales/types.d.ts +0 -1
  80. package/lib/solution/BaseSales/types.js +1 -2
  81. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +5 -4
  82. package/lib/solution/BookingByStep/index.d.ts +1 -1
  83. package/lib/solution/BookingTicket/index.d.ts +1 -9
  84. package/lib/solution/BookingTicket/index.js +0 -112
  85. package/lib/solution/BookingTicket/types.d.ts +2 -0
  86. package/package.json +1 -1
  87. package/dist/modules/Order/utils/bundleDiscountHydration.d.ts +0 -5
  88. package/dist/modules/Order/utils/bundleDiscountHydration.js +0 -144
  89. package/lib/modules/Order/utils/bundleDiscountHydration.d.ts +0 -5
  90. package/lib/modules/Order/utils/bundleDiscountHydration.js +0 -139
@@ -1,144 +0,0 @@
1
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
2
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
3
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
5
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
6
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
7
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
8
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
9
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
10
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
12
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
13
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
14
- var BUNDLE_MAP_ID_KEY = 'custom_product_bundle_map_id';
15
- function getBundleMapId(bundle) {
16
- var _bundle$metadata;
17
- var metadataMapId = bundle === null || bundle === void 0 || (_bundle$metadata = bundle.metadata) === null || _bundle$metadata === void 0 ? void 0 : _bundle$metadata[BUNDLE_MAP_ID_KEY];
18
- if (metadataMapId !== undefined && metadataMapId !== null && metadataMapId !== '') {
19
- return String(metadataMapId);
20
- }
21
- if ((bundle === null || bundle === void 0 ? void 0 : bundle._id) !== undefined && bundle._id !== null && bundle._id !== '') {
22
- return String(bundle._id);
23
- }
24
- return null;
25
- }
26
- function getDiscountBundleMapId(discount) {
27
- var _discount$metadata;
28
- var mapId = discount === null || discount === void 0 || (_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata[BUNDLE_MAP_ID_KEY];
29
- if (mapId === undefined || mapId === null || mapId === '') return null;
30
- return String(mapId);
31
- }
32
- function hasSameBundleDiscount(discountList, discount) {
33
- var _ref, _discount$discount$re, _discount$discount;
34
- var targetOrderDiscountId = discount.order_discount_id;
35
- if (targetOrderDiscountId !== undefined && targetOrderDiscountId !== null) {
36
- return discountList.some(function (item) {
37
- return (item === null || item === void 0 ? void 0 : item.order_discount_id) === targetOrderDiscountId;
38
- });
39
- }
40
- var targetResourceId = (_ref = (_discount$discount$re = discount === null || discount === void 0 || (_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) !== null && _discount$discount$re !== void 0 ? _discount$discount$re : discount === null || discount === void 0 ? void 0 : discount.resource_id) !== null && _ref !== void 0 ? _ref : discount === null || discount === void 0 ? void 0 : discount.discount_id;
41
- var targetMapId = getDiscountBundleMapId(discount);
42
- return discountList.some(function (item) {
43
- var _ref2, _item$discount$resour, _item$discount, _item$amount, _discount$amount;
44
- var resourceId = (_ref2 = (_item$discount$resour = item === null || item === void 0 || (_item$discount = item.discount) === null || _item$discount === void 0 ? void 0 : _item$discount.resource_id) !== null && _item$discount$resour !== void 0 ? _item$discount$resour : item === null || item === void 0 ? void 0 : item.resource_id) !== null && _ref2 !== void 0 ? _ref2 : item === null || item === void 0 ? void 0 : item.discount_id;
45
- return resourceId === targetResourceId && String((_item$amount = item === null || item === void 0 ? void 0 : item.amount) !== null && _item$amount !== void 0 ? _item$amount : '') === String((_discount$amount = discount === null || discount === void 0 ? void 0 : discount.amount) !== null && _discount$amount !== void 0 ? _discount$amount : '') && getDiscountBundleMapId(item) === targetMapId;
46
- });
47
- }
48
- export function restoreHydratedBundleDiscounts(product, normalizeDiscountList) {
49
- if (!Array.isArray(product.product_bundle) || !Array.isArray(product.discount_list)) {
50
- return product;
51
- }
52
- var bundleByMapId = new Map();
53
- product.product_bundle.forEach(function (bundle) {
54
- if (!bundle || _typeof(bundle) !== 'object') return;
55
- var mapId = getBundleMapId(bundle);
56
- if (mapId) bundleByMapId.set(mapId, bundle);
57
- });
58
- if (!bundleByMapId.size) return product;
59
- var mainDiscountList = [];
60
- var bundleDiscounts = [];
61
- product.discount_list.forEach(function (discount) {
62
- var mapId = getDiscountBundleMapId(discount);
63
- if (mapId && bundleByMapId.has(mapId)) {
64
- bundleDiscounts.push({
65
- mapId: mapId,
66
- discount: discount
67
- });
68
- } else {
69
- mainDiscountList.push(discount);
70
- }
71
- });
72
- if (!bundleDiscounts.length) return product;
73
- return _objectSpread(_objectSpread({}, product), {}, {
74
- discount_list: normalizeDiscountList(mainDiscountList),
75
- product_bundle: product.product_bundle.map(function (bundle) {
76
- if (!bundle || _typeof(bundle) !== 'object') return bundle;
77
- var mapId = getBundleMapId(bundle);
78
- if (!mapId) return bundle;
79
- var matchedDiscounts = bundleDiscounts.filter(function (item) {
80
- return item.mapId === mapId;
81
- }).map(function (item) {
82
- return item.discount;
83
- });
84
- if (!matchedDiscounts.length) return bundle;
85
- var currentDiscountList = Array.isArray(bundle.discount_list) ? _toConsumableArray(bundle.discount_list) : [];
86
- var _iterator = _createForOfIteratorHelper(matchedDiscounts),
87
- _step;
88
- try {
89
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
90
- var discount = _step.value;
91
- if (!hasSameBundleDiscount(currentDiscountList, discount)) {
92
- currentDiscountList.push(discount);
93
- }
94
- }
95
- } catch (err) {
96
- _iterator.e(err);
97
- } finally {
98
- _iterator.f();
99
- }
100
- return _objectSpread(_objectSpread({}, bundle), {}, {
101
- discount_list: normalizeDiscountList(currentDiscountList),
102
- metadata: _objectSpread(_objectSpread({}, bundle.metadata || {}), {}, _defineProperty({}, BUNDLE_MAP_ID_KEY, mapId))
103
- });
104
- })
105
- });
106
- }
107
- export function expandHydratedProductsForDiscountCollection(products) {
108
- var expanded = [];
109
- var _iterator2 = _createForOfIteratorHelper(products || []),
110
- _step2;
111
- try {
112
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
113
- var product = _step2.value;
114
- expanded.push(product);
115
- var _iterator3 = _createForOfIteratorHelper((product === null || product === void 0 ? void 0 : product.product_bundle) || []),
116
- _step3;
117
- try {
118
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
119
- var _ref3, _ref4, _bundle$bundle_produc, _ref5, _bundle$num, _ref6, _bundle$quantity, _ref7, _bundle$original_pric, _bundle$bundle_sellin, _bundle$is_charge_tax;
120
- var bundle = _step3.value;
121
- if (!Array.isArray(bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || bundle.discount_list.length === 0) continue;
122
- expanded.push(_objectSpread(_objectSpread({}, product), {}, {
123
- product_id: (_ref3 = (_ref4 = (_bundle$bundle_produc = bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle._bundle_product_id) !== null && _ref4 !== void 0 ? _ref4 : bundle.product_id) !== null && _ref3 !== void 0 ? _ref3 : product === null || product === void 0 ? void 0 : product.product_id,
124
- num: (_ref5 = (_bundle$num = bundle.num) !== null && _bundle$num !== void 0 ? _bundle$num : bundle.quantity) !== null && _ref5 !== void 0 ? _ref5 : product === null || product === void 0 ? void 0 : product.num,
125
- product_quantity: (_ref6 = (_bundle$quantity = bundle.quantity) !== null && _bundle$quantity !== void 0 ? _bundle$quantity : bundle.num) !== null && _ref6 !== void 0 ? _ref6 : product === null || product === void 0 ? void 0 : product.product_quantity,
126
- original_price: (_ref7 = (_bundle$original_pric = bundle.original_price) !== null && _bundle$original_pric !== void 0 ? _bundle$original_pric : bundle.product_price) !== null && _ref7 !== void 0 ? _ref7 : bundle.price,
127
- selling_price: (_bundle$bundle_sellin = bundle.bundle_selling_price) !== null && _bundle$bundle_sellin !== void 0 ? _bundle$bundle_sellin : bundle.price,
128
- is_charge_tax: (_bundle$is_charge_tax = bundle.is_charge_tax) !== null && _bundle$is_charge_tax !== void 0 ? _bundle$is_charge_tax : product === null || product === void 0 ? void 0 : product.is_charge_tax,
129
- discount_list: bundle.discount_list
130
- }));
131
- }
132
- } catch (err) {
133
- _iterator3.e(err);
134
- } finally {
135
- _iterator3.f();
136
- }
137
- }
138
- } catch (err) {
139
- _iterator2.e(err);
140
- } finally {
141
- _iterator2.f();
142
- }
143
- return expanded;
144
- }
@@ -1,5 +0,0 @@
1
- import type { OrderProductDiscountItem } from '../types';
2
- type NormalizeDiscountList = (discountList?: unknown[] | null) => OrderProductDiscountItem[];
3
- export declare function restoreHydratedBundleDiscounts<T extends Record<string, any>>(product: T, normalizeDiscountList: NormalizeDiscountList): T;
4
- export declare function expandHydratedProductsForDiscountCollection(products: any[] | undefined | null): any[];
5
- export {};
@@ -1,139 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // src/modules/Order/utils/bundleDiscountHydration.ts
20
- var bundleDiscountHydration_exports = {};
21
- __export(bundleDiscountHydration_exports, {
22
- expandHydratedProductsForDiscountCollection: () => expandHydratedProductsForDiscountCollection,
23
- restoreHydratedBundleDiscounts: () => restoreHydratedBundleDiscounts
24
- });
25
- module.exports = __toCommonJS(bundleDiscountHydration_exports);
26
- var BUNDLE_MAP_ID_KEY = "custom_product_bundle_map_id";
27
- function getBundleMapId(bundle) {
28
- var _a;
29
- const metadataMapId = (_a = bundle == null ? void 0 : bundle.metadata) == null ? void 0 : _a[BUNDLE_MAP_ID_KEY];
30
- if (metadataMapId !== void 0 && metadataMapId !== null && metadataMapId !== "") {
31
- return String(metadataMapId);
32
- }
33
- if ((bundle == null ? void 0 : bundle._id) !== void 0 && bundle._id !== null && bundle._id !== "") {
34
- return String(bundle._id);
35
- }
36
- return null;
37
- }
38
- function getDiscountBundleMapId(discount) {
39
- var _a;
40
- const mapId = (_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a[BUNDLE_MAP_ID_KEY];
41
- if (mapId === void 0 || mapId === null || mapId === "")
42
- return null;
43
- return String(mapId);
44
- }
45
- function hasSameBundleDiscount(discountList, discount) {
46
- var _a;
47
- const targetOrderDiscountId = discount.order_discount_id;
48
- if (targetOrderDiscountId !== void 0 && targetOrderDiscountId !== null) {
49
- return discountList.some((item) => (item == null ? void 0 : item.order_discount_id) === targetOrderDiscountId);
50
- }
51
- const targetResourceId = ((_a = discount == null ? void 0 : discount.discount) == null ? void 0 : _a.resource_id) ?? (discount == null ? void 0 : discount.resource_id) ?? (discount == null ? void 0 : discount.discount_id);
52
- const targetMapId = getDiscountBundleMapId(discount);
53
- return discountList.some((item) => {
54
- var _a2;
55
- const resourceId = ((_a2 = item == null ? void 0 : item.discount) == null ? void 0 : _a2.resource_id) ?? (item == null ? void 0 : item.resource_id) ?? (item == null ? void 0 : item.discount_id);
56
- return resourceId === targetResourceId && String((item == null ? void 0 : item.amount) ?? "") === String((discount == null ? void 0 : discount.amount) ?? "") && getDiscountBundleMapId(item) === targetMapId;
57
- });
58
- }
59
- function restoreHydratedBundleDiscounts(product, normalizeDiscountList) {
60
- if (!Array.isArray(product.product_bundle) || !Array.isArray(product.discount_list)) {
61
- return product;
62
- }
63
- const bundleByMapId = /* @__PURE__ */ new Map();
64
- product.product_bundle.forEach((bundle) => {
65
- if (!bundle || typeof bundle !== "object")
66
- return;
67
- const mapId = getBundleMapId(bundle);
68
- if (mapId)
69
- bundleByMapId.set(mapId, bundle);
70
- });
71
- if (!bundleByMapId.size)
72
- return product;
73
- const mainDiscountList = [];
74
- const bundleDiscounts = [];
75
- product.discount_list.forEach((discount) => {
76
- const mapId = getDiscountBundleMapId(discount);
77
- if (mapId && bundleByMapId.has(mapId)) {
78
- bundleDiscounts.push({ mapId, discount });
79
- } else {
80
- mainDiscountList.push(discount);
81
- }
82
- });
83
- if (!bundleDiscounts.length)
84
- return product;
85
- return {
86
- ...product,
87
- discount_list: normalizeDiscountList(mainDiscountList),
88
- product_bundle: product.product_bundle.map((bundle) => {
89
- if (!bundle || typeof bundle !== "object")
90
- return bundle;
91
- const mapId = getBundleMapId(bundle);
92
- if (!mapId)
93
- return bundle;
94
- const matchedDiscounts = bundleDiscounts.filter((item) => item.mapId === mapId).map((item) => item.discount);
95
- if (!matchedDiscounts.length)
96
- return bundle;
97
- const currentDiscountList = Array.isArray(bundle.discount_list) ? [...bundle.discount_list] : [];
98
- for (const discount of matchedDiscounts) {
99
- if (!hasSameBundleDiscount(currentDiscountList, discount)) {
100
- currentDiscountList.push(discount);
101
- }
102
- }
103
- return {
104
- ...bundle,
105
- discount_list: normalizeDiscountList(currentDiscountList),
106
- metadata: {
107
- ...bundle.metadata || {},
108
- [BUNDLE_MAP_ID_KEY]: mapId
109
- }
110
- };
111
- })
112
- };
113
- }
114
- function expandHydratedProductsForDiscountCollection(products) {
115
- const expanded = [];
116
- for (const product of products || []) {
117
- expanded.push(product);
118
- for (const bundle of (product == null ? void 0 : product.product_bundle) || []) {
119
- if (!Array.isArray(bundle == null ? void 0 : bundle.discount_list) || bundle.discount_list.length === 0)
120
- continue;
121
- expanded.push({
122
- ...product,
123
- product_id: bundle.bundle_product_id ?? bundle._bundle_product_id ?? bundle.product_id ?? (product == null ? void 0 : product.product_id),
124
- num: bundle.num ?? bundle.quantity ?? (product == null ? void 0 : product.num),
125
- product_quantity: bundle.quantity ?? bundle.num ?? (product == null ? void 0 : product.product_quantity),
126
- original_price: bundle.original_price ?? bundle.product_price ?? bundle.price,
127
- selling_price: bundle.bundle_selling_price ?? bundle.price,
128
- is_charge_tax: bundle.is_charge_tax ?? (product == null ? void 0 : product.is_charge_tax),
129
- discount_list: bundle.discount_list
130
- });
131
- }
132
- }
133
- return expanded;
134
- }
135
- // Annotate the CommonJS export names for ESM import in node:
136
- 0 && (module.exports = {
137
- expandHydratedProductsForDiscountCollection,
138
- restoreHydratedBundleDiscounts
139
- });