@pisell/pisellos 0.10.7 → 0.10.9

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 (124) hide show
  1. package/dist/core/index.js +0 -1
  2. package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +18 -2
  3. package/dist/model/strategy/adapter/dataVariant/evaluator.js +287 -101
  4. package/dist/model/strategy/adapter/dataVariant/type.d.ts +25 -0
  5. package/dist/model/strategy/adapter/walletPass/evaluator.js +0 -2
  6. package/dist/model/strategy/adapter/walletPass/type.d.ts +5 -0
  7. package/dist/model/strategy/adapter/walletPass/utils.js +57 -26
  8. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +18 -12
  9. package/dist/modules/BookingContext/utils/productExtend.js +5 -9
  10. package/dist/modules/BookingContext/utils/timeSlices.js +24 -3
  11. package/dist/modules/Customer/index.d.ts +4 -0
  12. package/dist/modules/Customer/index.js +91 -59
  13. package/dist/modules/Customer/types.d.ts +2 -0
  14. package/dist/modules/Discount/index.d.ts +2 -0
  15. package/dist/modules/Discount/index.js +38 -5
  16. package/dist/modules/Discount/types.d.ts +11 -0
  17. package/dist/modules/Order/index.d.ts +32 -6
  18. package/dist/modules/Order/index.js +1165 -819
  19. package/dist/modules/Order/types.d.ts +32 -4
  20. package/dist/modules/Order/types.js +11 -0
  21. package/dist/modules/Order/utils/discountProductLineIdentity.d.ts +45 -0
  22. package/dist/modules/Order/utils/discountProductLineIdentity.js +227 -0
  23. package/dist/modules/Order/utils/virtualSettlement.d.ts +56 -0
  24. package/dist/modules/Order/utils/virtualSettlement.js +271 -0
  25. package/dist/modules/Order/utils.js +89 -48
  26. package/dist/modules/Payment/types.d.ts +2 -0
  27. package/dist/modules/Payment/utils.js +4 -1
  28. package/dist/modules/Payment/walletpass.d.ts +11 -0
  29. package/dist/modules/Payment/walletpass.js +235 -60
  30. package/dist/modules/Product/types.d.ts +23 -0
  31. package/dist/modules/ProductList/index.d.ts +15 -2
  32. package/dist/modules/ProductList/index.js +92 -13
  33. package/dist/modules/Rules/index.js +125 -52
  34. package/dist/modules/SalesSummary/index.d.ts +1 -0
  35. package/dist/modules/SalesSummary/index.js +4 -3
  36. package/dist/modules/SalesSummary/types.d.ts +1 -0
  37. package/dist/modules/SalesSummary/utils.d.ts +1 -0
  38. package/dist/modules/SalesSummary/utils.js +28 -2
  39. package/dist/server/index.d.ts +15 -0
  40. package/dist/server/index.js +894 -781
  41. package/dist/server/modules/order/index.d.ts +2 -0
  42. package/dist/server/modules/order/index.js +261 -96
  43. package/dist/server/modules/order/types.d.ts +1 -1
  44. package/dist/server/utils/small-ticket.js +2 -1
  45. package/dist/solution/BaseSales/index.d.ts +41 -7
  46. package/dist/solution/BaseSales/index.js +1405 -974
  47. package/dist/solution/BaseSales/utils/cartPromotion.js +26 -3
  48. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -0
  49. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +79 -13
  50. package/dist/solution/BaseSales/utils.js +31 -20
  51. package/dist/solution/BookingByStep/index.d.ts +3 -3
  52. package/dist/solution/BookingTicket/index.d.ts +5 -1
  53. package/dist/solution/BookingTicket/index.js +221 -162
  54. package/dist/solution/BookingTicket/types.d.ts +3 -0
  55. package/dist/solution/BookingTicket/utils/addProductDecision.js +2 -1
  56. package/dist/solution/BookingTicket/utils/cartView.js +44 -32
  57. package/dist/solution/Sales/index.d.ts +1 -0
  58. package/dist/solution/Sales/index.js +16 -2
  59. package/dist/solution/ScanOrder/index.js +25 -64
  60. package/dist/solution/ScanOrder/utils.js +31 -20
  61. package/dist/solution/UnifiedBookingSales/index.d.ts +5 -4
  62. package/dist/solution/UnifiedBookingSales/index.js +51 -39
  63. package/lib/core/index.js +0 -1
  64. package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +18 -2
  65. package/lib/model/strategy/adapter/dataVariant/evaluator.js +170 -7
  66. package/lib/model/strategy/adapter/dataVariant/type.d.ts +25 -0
  67. package/lib/model/strategy/adapter/walletPass/evaluator.js +0 -2
  68. package/lib/model/strategy/adapter/walletPass/type.d.ts +5 -0
  69. package/lib/model/strategy/adapter/walletPass/utils.js +62 -11
  70. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +6 -1
  71. package/lib/modules/BookingContext/utils/productExtend.js +4 -3
  72. package/lib/modules/BookingContext/utils/timeSlices.js +18 -3
  73. package/lib/modules/Customer/index.d.ts +4 -0
  74. package/lib/modules/Customer/index.js +11 -0
  75. package/lib/modules/Customer/types.d.ts +2 -0
  76. package/lib/modules/Discount/index.d.ts +2 -0
  77. package/lib/modules/Discount/index.js +37 -3
  78. package/lib/modules/Discount/types.d.ts +11 -0
  79. package/lib/modules/Order/index.d.ts +32 -6
  80. package/lib/modules/Order/index.js +518 -148
  81. package/lib/modules/Order/types.d.ts +32 -4
  82. package/lib/modules/Order/utils/discountProductLineIdentity.d.ts +45 -0
  83. package/lib/modules/Order/utils/discountProductLineIdentity.js +170 -0
  84. package/lib/modules/Order/utils/virtualSettlement.d.ts +56 -0
  85. package/lib/modules/Order/utils/virtualSettlement.js +300 -0
  86. package/lib/modules/Order/utils.js +65 -21
  87. package/lib/modules/Payment/types.d.ts +2 -0
  88. package/lib/modules/Payment/utils.js +5 -1
  89. package/lib/modules/Payment/walletpass.d.ts +11 -0
  90. package/lib/modules/Payment/walletpass.js +198 -17
  91. package/lib/modules/Product/types.d.ts +23 -0
  92. package/lib/modules/ProductList/index.d.ts +15 -2
  93. package/lib/modules/ProductList/index.js +85 -3
  94. package/lib/modules/Rules/index.js +100 -20
  95. package/lib/modules/SalesSummary/index.d.ts +1 -0
  96. package/lib/modules/SalesSummary/index.js +10 -2
  97. package/lib/modules/SalesSummary/types.d.ts +1 -0
  98. package/lib/modules/SalesSummary/utils.d.ts +1 -0
  99. package/lib/modules/SalesSummary/utils.js +30 -2
  100. package/lib/server/index.d.ts +15 -0
  101. package/lib/server/index.js +105 -14
  102. package/lib/server/modules/order/index.d.ts +2 -0
  103. package/lib/server/modules/order/index.js +75 -5
  104. package/lib/server/modules/order/types.d.ts +1 -1
  105. package/lib/server/utils/small-ticket.js +1 -1
  106. package/lib/solution/BaseSales/index.d.ts +41 -7
  107. package/lib/solution/BaseSales/index.js +325 -39
  108. package/lib/solution/BaseSales/utils/cartPromotion.js +26 -2
  109. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -0
  110. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +62 -12
  111. package/lib/solution/BaseSales/utils.js +29 -18
  112. package/lib/solution/BookingByStep/index.d.ts +3 -3
  113. package/lib/solution/BookingTicket/index.d.ts +5 -1
  114. package/lib/solution/BookingTicket/index.js +31 -6
  115. package/lib/solution/BookingTicket/types.d.ts +3 -0
  116. package/lib/solution/BookingTicket/utils/addProductDecision.js +2 -1
  117. package/lib/solution/BookingTicket/utils/cartView.js +43 -30
  118. package/lib/solution/Sales/index.d.ts +1 -0
  119. package/lib/solution/Sales/index.js +15 -3
  120. package/lib/solution/ScanOrder/index.js +17 -54
  121. package/lib/solution/ScanOrder/utils.js +29 -18
  122. package/lib/solution/UnifiedBookingSales/index.d.ts +5 -4
  123. package/lib/solution/UnifiedBookingSales/index.js +35 -26
  124. package/package.json +1 -1
@@ -44,6 +44,8 @@ var import_utils3 = require("../../solution/ScanOrder/utils");
44
44
  var import_manualProductDiscount = require("./utils/manualProductDiscount");
45
45
  var import_bundleDiscountHydration = require("./utils/bundleDiscountHydration");
46
46
  var import_orderCollectionIdentity = require("./utils/orderCollectionIdentity");
47
+ var import_discountProductLineIdentity = require("./utils/discountProductLineIdentity");
48
+ var import_virtualSettlement = require("./utils/virtualSettlement");
47
49
  var import_Discount = require("../Discount");
48
50
  var import_Rules = require("../Rules");
49
51
  var import_types2 = require("../Rules/types");
@@ -65,8 +67,7 @@ function isSameDiscountList(left, right) {
65
67
  );
66
68
  }
67
69
  function isManualProductDiscountProduct(product) {
68
- var _a, _b;
69
- return ((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.is_manual_discount) === true || ((_b = product == null ? void 0 : product.metadata) == null ? void 0 : _b.is_manual_discount) === 1 || ((product == null ? void 0 : product.discount_list) || []).some((item) => (item == null ? void 0 : item.type) === "product");
70
+ return (0, import_manualProductDiscount.hasManualProductDiscountFlag)(product == null ? void 0 : product.metadata) || ((product == null ? void 0 : product.discount_list) || []).some((item) => (item == null ? void 0 : item.type) === "product");
70
71
  }
71
72
  var ORDER_PAYMENT_STATUS_PAID = "paid";
72
73
  var ORDER_PAYMENT_STATUS_PENDING = "payment_pending";
@@ -136,7 +137,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
136
137
  this.draftPersistEnabled = true;
137
138
  }
138
139
  collectHydratedEditDiscounts(products) {
139
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
140
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
140
141
  const discountMap = /* @__PURE__ */ new Map();
141
142
  for (const product of (0, import_bundleDiscountHydration.expandHydratedProductsForDiscountCollection)(products)) {
142
143
  for (const item of (product == null ? void 0 : product.discount_list) || []) {
@@ -151,16 +152,18 @@ var OrderModule = class extends import_BaseModule.BaseModule {
151
152
  const key = Number.isFinite(id) ? id : String(resourceId);
152
153
  const title = ((_b = item == null ? void 0 : item.discount) == null ? void 0 : _b.title) ?? {};
153
154
  const amount = Number((item == null ? void 0 : item.amount) || 0);
155
+ const discountCardType = (_c = item == null ? void 0 : item.discount) == null ? void 0 : _c.discount_card_type;
156
+ const parValue = isDiscountCard ? discountCardType === "fixed_amount" ? ((_d = item == null ? void 0 : item.discount) == null ? void 0 : _d.fixed_amount) ?? (item == null ? void 0 : item.amount) : (_e = item == null ? void 0 : item.discount) == null ? void 0 : _e.percent : "0";
154
157
  const detail = {
155
158
  amount: String((item == null ? void 0 : item.amount) ?? "0"),
156
159
  type,
157
160
  resource_id: key,
158
161
  title,
159
- original_amount: String(((_c = item == null ? void 0 : item.discount) == null ? void 0 : _c.original_amount) ?? (item == null ? void 0 : item.amount) ?? "0"),
160
- num: Number(((_d = item == null ? void 0 : item.metadata) == null ? void 0 : _d.num) ?? (product == null ? void 0 : product.num) ?? (product == null ? void 0 : product.product_quantity) ?? 1) || 1,
162
+ original_amount: String(((_f = item == null ? void 0 : item.discount) == null ? void 0 : _f.original_amount) ?? (item == null ? void 0 : item.amount) ?? "0"),
163
+ num: Number(((_g = item == null ? void 0 : item.metadata) == null ? void 0 : _g.num) ?? (product == null ? void 0 : product.num) ?? (product == null ? void 0 : product.product_quantity) ?? 1) || 1,
161
164
  metadata: item == null ? void 0 : item.metadata,
162
165
  discount: item == null ? void 0 : item.discount,
163
- _num: Number(((_e = item == null ? void 0 : item.metadata) == null ? void 0 : _e.num) ?? (product == null ? void 0 : product.num) ?? (product == null ? void 0 : product.product_quantity) ?? 1) || 1
166
+ _num: Number(((_h = item == null ? void 0 : item.metadata) == null ? void 0 : _h.num) ?? (product == null ? void 0 : product.num) ?? (product == null ? void 0 : product.product_quantity) ?? 1) || 1
164
167
  };
165
168
  const existed = discountMap.get(key);
166
169
  if (existed) {
@@ -169,7 +172,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
169
172
  if (!isDiscountCard) {
170
173
  existed.balance = String(Number(existed.balance || 0) + amount);
171
174
  }
172
- const productIds = Array.isArray((_f = existed.limited_relation_product_data) == null ? void 0 : _f.product_ids) ? existed.limited_relation_product_data.product_ids : [];
175
+ const productIds = Array.isArray((_i = existed.limited_relation_product_data) == null ? void 0 : _i.product_ids) ? existed.limited_relation_product_data.product_ids : [];
173
176
  if ((product == null ? void 0 : product.product_id) !== void 0 && (product == null ? void 0 : product.product_id) !== null && !productIds.includes(product.product_id)) {
174
177
  existed.limited_relation_product_data = {
175
178
  ...existed.limited_relation_product_data || {},
@@ -192,9 +195,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
192
195
  encoded: "",
193
196
  code: "",
194
197
  tag: type,
195
- product_id: ((_g = item == null ? void 0 : item.discount) == null ? void 0 : _g.discount_product_id) ?? (product == null ? void 0 : product.product_id) ?? 0,
198
+ product_id: ((_j = item == null ? void 0 : item.discount) == null ? void 0 : _j.discount_product_id) ?? (product == null ? void 0 : product.product_id) ?? 0,
196
199
  relation_type: "",
197
- par_value: String(((_h = item == null ? void 0 : item.discount) == null ? void 0 : _h.original_amount) ?? (item == null ? void 0 : item.amount) ?? "0"),
200
+ par_value: String(parValue ?? "0"),
198
201
  used_par_value: String((item == null ? void 0 : item.amount) ?? "0"),
199
202
  limit_status: "enable",
200
203
  limited_relation_product_data: {
@@ -224,8 +227,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
224
227
  discount: {
225
228
  ...(item == null ? void 0 : item.discount) || {},
226
229
  resource_id: key,
227
- discount_product_id: ((_i = item == null ? void 0 : item.discount) == null ? void 0 : _i.discount_product_id) ?? (product == null ? void 0 : product.product_id) ?? 0,
228
- discount_calculation_mode: ((_j = item == null ? void 0 : item.discount) == null ? void 0 : _j.discount_calculation_mode) ?? "item_level"
230
+ discount_product_id: ((_k = item == null ? void 0 : item.discount) == null ? void 0 : _k.discount_product_id) ?? (product == null ? void 0 : product.product_id) ?? 0,
231
+ discount_calculation_mode: ((_l = item == null ? void 0 : item.discount) == null ? void 0 : _l.discount_calculation_mode) ?? "item_level"
229
232
  },
230
233
  applicableProductDetails: [detail],
231
234
  appliedProductDetails: [detail]
@@ -277,7 +280,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
277
280
  const isPersistedBundleProduct = isPersistedProduct || Boolean(
278
281
  (bundle == null ? void 0 : bundle.order_detail_id) || (bundle == null ? void 0 : bundle.orderDetailId) || (bundle == null ? void 0 : bundle.booking_id)
279
282
  );
280
- const bundleQty = new import_decimal.default(Number(qty) || 1).times(Number((bundle == null ? void 0 : bundle.num) ?? (bundle == null ? void 0 : bundle.quantity) ?? 1) || 1).toNumber();
283
+ const bundleQty = Number(qty) || 1;
281
284
  for (const pd of (bundle == null ? void 0 : bundle.discount_list) || []) {
282
285
  addProductDiscountAmount(pd, bundleQty, isPersistedBundleProduct);
283
286
  }
@@ -352,6 +355,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
352
355
  this.store.tempOrder = null;
353
356
  this.store.summary = (0, import_utils.createEmptySummary)();
354
357
  this.store.availableWalletIds = [];
358
+ this.store.virtualCurrencyList = [];
355
359
  this.store.lastOrderInfo = void 0;
356
360
  this.store.syncState = void 0;
357
361
  this.store.discountList = [];
@@ -364,6 +368,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
364
368
  if (!Array.isArray(this.store.availableWalletIds)) {
365
369
  this.store.availableWalletIds = [];
366
370
  }
371
+ if (!Array.isArray(this.store.virtualCurrencyList)) {
372
+ this.store.virtualCurrencyList = [];
373
+ }
367
374
  this.request = this.core.getPlugin("request");
368
375
  const appPlugin = this.core.getPlugin("app");
369
376
  if (!appPlugin) {
@@ -499,11 +506,13 @@ var OrderModule = class extends import_BaseModule.BaseModule {
499
506
  with_wallet_pass_holder: 1,
500
507
  with_available_wallet_flag: 1,
501
508
  with_available_wallet_pass_flag: 1,
509
+ with_virtual_currency: 1,
502
510
  request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
503
511
  ...orderId ? { order_id: orderId } : {}
504
512
  }));
505
513
  const discountList = prepareConfigResult == null ? void 0 : prepareConfigResult.discountList;
506
514
  this.store.availableWalletIds = (prepareConfigResult == null ? void 0 : prepareConfigResult.availableWalletIds) || [];
515
+ this.store.virtualCurrencyList = (prepareConfigResult == null ? void 0 : prepareConfigResult.virtualCurrencyList) || [];
507
516
  if (discountList) {
508
517
  const currentDiscountList = ((_c = this.store.discount) == null ? void 0 : _c.getDiscountList()) || [];
509
518
  const currentEditDiscounts = currentDiscountList.filter((discount) => discount == null ? void 0 : discount.isEditMode);
@@ -540,6 +549,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
540
549
  getAvailableWalletIds() {
541
550
  return Array.isArray(this.store.availableWalletIds) ? [...this.store.availableWalletIds] : [];
542
551
  }
552
+ getVirtualCurrencyList() {
553
+ return (0, import_lodash_es.cloneDeep)(this.store.virtualCurrencyList || []);
554
+ }
543
555
  async syncScannedDiscountsToOriginalDiscountList(discountList) {
544
556
  var _a, _b, _c, _d;
545
557
  const scanDiscounts = (discountList || []).filter((discount) => discount == null ? void 0 : discount.isScan);
@@ -574,6 +586,16 @@ var OrderModule = class extends import_BaseModule.BaseModule {
574
586
  }
575
587
  async scanCode(code, customerId) {
576
588
  var _a, _b, _c, _d, _e;
589
+ if (this.isActiveVirtualSettlementOrder(this.store.tempOrder)) {
590
+ return {
591
+ type: "clientCalc",
592
+ isAvailable: false,
593
+ isAccepted: false,
594
+ discountList: [],
595
+ scannedDiscountList: [],
596
+ unavailableReason: import_types2.UnavailableReason.ProductNotApplicable
597
+ };
598
+ }
577
599
  const resultDiscountWithReason = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code, { customerId })) || { discountList: [], unavailableReasonKey: null };
578
600
  const { discountList: resultDiscountList, unavailableReasonKey } = resultDiscountWithReason;
579
601
  const rulesModule = this.store.rules;
@@ -651,13 +673,21 @@ var OrderModule = class extends import_BaseModule.BaseModule {
651
673
  };
652
674
  }
653
675
  applyDiscount(options) {
654
- var _a, _b, _c;
676
+ var _a, _b, _c, _d, _e;
655
677
  const tempOrder = this.store.tempOrder;
656
678
  if (!tempOrder)
657
679
  return;
680
+ if (this.isActiveVirtualSettlementOrder(tempOrder)) {
681
+ tempOrder.products = (0, import_virtualSettlement.normalizeVirtualSettlementProducts)(tempOrder.products);
682
+ tempOrder.discount_list = [];
683
+ tempOrder.shop_discount = "0.00";
684
+ void ((_a = this.store.discount) == null ? void 0 : _a.setDiscountList([]));
685
+ void ((_b = this.store.discount) == null ? void 0 : _b.setOriginalDiscountList([]));
686
+ return;
687
+ }
658
688
  this.syncLinkedBookingHoldersToProducts(tempOrder);
659
689
  delete tempOrder.discount_list;
660
- const discountList = ((_a = this.store.discount) == null ? void 0 : _a.getDiscountList()) || [];
690
+ const discountList = ((_c = this.store.discount) == null ? void 0 : _c.getDiscountList()) || [];
661
691
  const shouldSkipDiscountCalculation = this.shouldSkipDiscountCalculation(tempOrder);
662
692
  if (shouldSkipDiscountCalculation)
663
693
  return;
@@ -669,7 +699,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
669
699
  discountList,
670
700
  holders: [],
671
701
  isFormSubject: (product) => (0, import_utils.resolveIsFormSubject)(tempOrder, product),
672
- orderTotalAmount: Number(((_b = this.store.summary) == null ? void 0 : _b.total_amount) || 0)
702
+ orderTotalAmount: Number(((_d = this.store.summary) == null ? void 0 : _d.total_amount) || 0)
673
703
  }, {
674
704
  reapplyBookingDiscountProductUids: options == null ? void 0 : options.reapplyBookingDiscountProductUids
675
705
  });
@@ -694,14 +724,15 @@ var OrderModule = class extends import_BaseModule.BaseModule {
694
724
  };
695
725
  })
696
726
  );
697
- this.repairDuplicateProductLineIdentities(tempOrder);
727
+ (0, import_discountProductLineIdentity.ensureUniqueProductLineUids)(tempOrder);
728
+ (0, import_discountProductLineIdentity.consolidateDiscountFreeProductLines)(tempOrder);
698
729
  }
699
730
  if (result == null ? void 0 : result.discountList) {
700
731
  OrderModule.populateSavedAmounts(
701
732
  result.productList || tempOrder.products,
702
733
  result.discountList
703
734
  );
704
- (_c = this.store.discount) == null ? void 0 : _c.setDiscountList(result.discountList);
735
+ (_e = this.store.discount) == null ? void 0 : _e.setDiscountList(result.discountList);
705
736
  }
706
737
  this.hasActiveCustomerBoundDiscount = (tempOrder.products || []).some(
707
738
  (product) => this.productHasCustomerBoundDiscount(product)
@@ -761,6 +792,10 @@ var OrderModule = class extends import_BaseModule.BaseModule {
761
792
  if (!tempOrder) {
762
793
  return;
763
794
  }
795
+ if (this.isActiveVirtualSettlementOrder(tempOrder)) {
796
+ tempOrder.products = (0, import_virtualSettlement.normalizeVirtualSettlementProducts)(tempOrder.products);
797
+ return;
798
+ }
764
799
  const strategyConfigs = (_b = (_a = this.promotionEvaluator).getStrategyConfigs) == null ? void 0 : _b.call(_a);
765
800
  if (Array.isArray(strategyConfigs) && strategyConfigs.length === 0) {
766
801
  return;
@@ -917,6 +952,52 @@ var OrderModule = class extends import_BaseModule.BaseModule {
917
952
  cacheKey: ["tempOrder"]
918
953
  });
919
954
  }
955
+ /**
956
+ * 终止当前模块实例的 sessionStorage 订单恢复会话。
957
+ *
958
+ * 支付跳转等终态场景需要同时删除当前 cacheId 的 tempOrder 快照,并关闭
959
+ * 本实例后续异步任务的再次写入;新模块实例初始化时会按 otherParams 重新启用。
960
+ */
961
+ clearSessionStoragePersistedTempOrder() {
962
+ var _a;
963
+ this.sessionStorageRestoreRecord = null;
964
+ if (!this.sessionStoragePersistEnabled)
965
+ return;
966
+ this.sessionStoragePersistEnabled = false;
967
+ if (!this.cacheId || !this.fatherModule || !((_a = this.window) == null ? void 0 : _a.sessionStorage)) {
968
+ return;
969
+ }
970
+ const sessionStorage = this.window.sessionStorage;
971
+ const rawCacheData = sessionStorage.getItem(this.fatherModule);
972
+ if (!rawCacheData)
973
+ return;
974
+ let parsedCacheData;
975
+ try {
976
+ parsedCacheData = JSON.parse(rawCacheData);
977
+ } catch {
978
+ return;
979
+ }
980
+ if (!parsedCacheData || typeof parsedCacheData !== "object" || Array.isArray(parsedCacheData)) {
981
+ return;
982
+ }
983
+ const cacheRoot = parsedCacheData;
984
+ const cacheBucket = cacheRoot[this.cacheId];
985
+ if (!cacheBucket || typeof cacheBucket !== "object" || Array.isArray(cacheBucket)) {
986
+ return;
987
+ }
988
+ const moduleBucket = cacheBucket[this.name];
989
+ if (!moduleBucket || typeof moduleBucket !== "object" || Array.isArray(moduleBucket)) {
990
+ return;
991
+ }
992
+ delete moduleBucket.tempOrder;
993
+ if (Object.keys(moduleBucket).length === 0) {
994
+ delete cacheBucket[this.name];
995
+ }
996
+ if (Object.keys(cacheBucket).length === 0) {
997
+ delete cacheRoot[this.cacheId];
998
+ }
999
+ sessionStorage.setItem(this.fatherModule, JSON.stringify(cacheRoot));
1000
+ }
920
1001
  consumeSessionStorageRestore() {
921
1002
  const record = this.sessionStorageRestoreRecord;
922
1003
  this.sessionStorageRestoreRecord = null;
@@ -1121,7 +1202,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1121
1202
  paidAmount: netPaidAmount
1122
1203
  });
1123
1204
  const isOrderFullyPaid = orderExpectedAmount.lte(0) ? true : netPaidAmount.gte(orderExpectedAmount);
1124
- const paymentStage = this.isDepositOrder(tempOrder, depositAmount) && !isDepositFullyPaid ? "deposit" : "normal";
1205
+ const paymentStage = this.isDepositOrder(tempOrder, depositAmount) && !isDepositFullyPaid && !this.hasPaidNormalPayment(paymentList) ? "deposit" : "normal";
1125
1206
  return {
1126
1207
  isFullyPaid: isOrderFullyPaid,
1127
1208
  isOrderFullyPaid,
@@ -1142,12 +1223,22 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1142
1223
  return sum.plus(this.calculatePaymentGapAmount(paymentRecord));
1143
1224
  }, new import_decimal.default(0));
1144
1225
  }
1226
+ hasPaidNormalPayment(payments) {
1227
+ return (payments || []).some((payment) => {
1228
+ const paymentRecord = payment;
1229
+ if (!isPaidPaymentRecord(paymentRecord))
1230
+ return false;
1231
+ return paymentRecord.order_payment_type !== "deposit" && paymentRecord.type !== "deposit";
1232
+ });
1233
+ }
1145
1234
  resolveNextOrderPaymentType(tempOrder) {
1146
1235
  const depositAmount = new import_decimal.default(tempOrder.deposit_amount || "0.00");
1147
1236
  if (!this.isDepositOrder(tempOrder, depositAmount))
1148
1237
  return "normal";
1149
1238
  if (depositAmount.lte(0))
1150
1239
  return "normal";
1240
+ if (this.hasPaidNormalPayment(tempOrder.payments || []))
1241
+ return "normal";
1151
1242
  const depositPaidAmount = this.calculateDepositPaidAmount(tempOrder.payments || []);
1152
1243
  return depositPaidAmount.lt(depositAmount) ? "deposit" : "normal";
1153
1244
  }
@@ -1445,24 +1536,28 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1445
1536
  }
1446
1537
  }
1447
1538
  calculateSummaryAmountGap(params) {
1448
- const { tempOrder, summary, orderPaidAmount } = params;
1539
+ const { tempOrder, summary, orderPaidAmount, payments } = params;
1449
1540
  const refundAmount = this.getSummaryRefundAmount(summary);
1450
1541
  const netOrderPaidAmount = import_decimal.default.max(orderPaidAmount.minus(refundAmount), 0);
1451
1542
  const targetAmount = this.calculatePaymentTargetAmount(
1452
1543
  tempOrder,
1453
1544
  summary,
1454
- netOrderPaidAmount
1545
+ netOrderPaidAmount,
1546
+ payments
1455
1547
  );
1456
1548
  return targetAmount.minus(netOrderPaidAmount).toFixed(2);
1457
1549
  }
1458
1550
  getSummaryRefundAmount(summary) {
1459
1551
  return import_decimal.default.max(new import_decimal.default((summary == null ? void 0 : summary.total_refund_amount) || 0), 0);
1460
1552
  }
1461
- calculatePaymentTargetAmount(tempOrder, summary, paidAmount = new import_decimal.default(0)) {
1553
+ calculatePaymentTargetAmount(tempOrder, summary, paidAmount = new import_decimal.default(0), payments = tempOrder.payments || []) {
1462
1554
  const depositAmount = this.getDepositAmount(tempOrder, summary);
1463
1555
  if (!this.isDepositOrder(tempOrder, depositAmount)) {
1464
1556
  return this.getOrderExpectedAmount(summary);
1465
1557
  }
1558
+ if (this.hasPaidNormalPayment(payments)) {
1559
+ return this.getOrderExpectedAmount(summary);
1560
+ }
1466
1561
  if (this.isDepositCovered({ tempOrder, summary, paidAmount })) {
1467
1562
  return this.getOrderExpectedAmount(summary);
1468
1563
  }
@@ -1642,19 +1737,21 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1642
1737
  return snapshot;
1643
1738
  }
1644
1739
  isSnapshotPayableAmountUnchanged(tempOrder, snapshot, snapshotSummary) {
1645
- const currentPaidPaymentSummary = this.calculatePaidPaymentSummary(tempOrder.payments || []);
1740
+ const currentPayments = tempOrder.payments || [];
1741
+ const currentPaidPaymentSummary = this.calculatePaidPaymentSummary(currentPayments);
1646
1742
  const currentAmountGap = this.calculateSummaryAmountGap({
1647
1743
  tempOrder,
1648
1744
  summary: snapshotSummary,
1649
- orderPaidAmount: currentPaidPaymentSummary.gapPaidAmount
1745
+ orderPaidAmount: currentPaidPaymentSummary.gapPaidAmount,
1746
+ payments: currentPayments
1650
1747
  });
1651
- const snapshotPaidPaymentSummary = this.calculatePaidPaymentSummary(
1652
- Array.isArray(snapshot.payments) ? snapshot.payments : []
1653
- );
1748
+ const snapshotPayments = Array.isArray(snapshot.payments) ? snapshot.payments : [];
1749
+ const snapshotPaidPaymentSummary = this.calculatePaidPaymentSummary(snapshotPayments);
1654
1750
  const snapshotAmountGap = this.calculateSummaryAmountGap({
1655
1751
  tempOrder,
1656
1752
  summary: snapshotSummary,
1657
- orderPaidAmount: snapshotPaidPaymentSummary.gapPaidAmount
1753
+ orderPaidAmount: snapshotPaidPaymentSummary.gapPaidAmount,
1754
+ payments: snapshotPayments
1658
1755
  });
1659
1756
  return currentAmountGap === snapshotAmountGap;
1660
1757
  }
@@ -1696,6 +1793,12 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1696
1793
  const isPayableAmountUnchanged = this.isSnapshotPayableAmountUnchanged(tempOrder, snapshot, summary);
1697
1794
  if (!isPayableAmountUnchanged)
1698
1795
  return null;
1796
+ const currentPaidPaymentSummary = this.calculatePaidPaymentSummary(tempOrder.payments || []);
1797
+ summary.amount_gap = this.calculateSummaryAmountGap({
1798
+ tempOrder,
1799
+ summary,
1800
+ orderPaidAmount: currentPaidPaymentSummary.gapPaidAmount
1801
+ });
1699
1802
  if (Array.isArray(snapshot.products)) {
1700
1803
  tempOrder.products = (0, import_lodash_es.cloneDeep)(snapshot.products);
1701
1804
  }
@@ -1920,8 +2023,12 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1920
2023
  }
1921
2024
  sanitizeTempOrderProducts(tempOrder) {
1922
2025
  tempOrder.products = (tempOrder.products || []).map(
1923
- (product) => this.sanitizeOrderProductForTempOrder(product)
2026
+ (product) => this.sanitizeOrderProductForTempOrder(
2027
+ this.normalizeVirtualSettlementProductIfEnabled(product)
2028
+ )
1924
2029
  );
2030
+ this.syncTempOrderSettlementState(tempOrder);
2031
+ (0, import_discountProductLineIdentity.ensureUniqueProductLineUids)(tempOrder);
1925
2032
  }
1926
2033
  ensureExtend(tempOrder) {
1927
2034
  if (!tempOrder._extend || typeof tempOrder._extend !== "object") {
@@ -2264,6 +2371,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2264
2371
  products: summaryProducts,
2265
2372
  isPriceIncludeTax: tempOrder.is_price_include_tax,
2266
2373
  shopDiscount: tempOrder.shop_discount,
2374
+ virtualSettlementMode: this.shouldUseVirtualSettlementSummary(tempOrder),
2267
2375
  ...((_a = this.otherParams) == null ? void 0 : _a.channel) ? { channel: this.otherParams.channel } : {}
2268
2376
  });
2269
2377
  if (shouldFullRecalculateFromSnapshot) {
@@ -2553,6 +2661,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2553
2661
  const nextCustomerId = tempOrder.customer_id ?? null;
2554
2662
  if (String(previousCustomerId ?? "") !== String(nextCustomerId ?? "")) {
2555
2663
  this.store.availableWalletIds = [];
2664
+ this.store.virtualCurrencyList = [];
2556
2665
  (0, import_utils.clearTempOrderHolderAssignments)(tempOrder);
2557
2666
  this.clearCustomerBoundDiscounts(tempOrder);
2558
2667
  this.applyDiscount();
@@ -2593,7 +2702,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2593
2702
  if (tempOrder._extend)
2594
2703
  delete tempOrder._extend.customerSnapshot;
2595
2704
  this.store.availableWalletIds = [];
2705
+ this.store.virtualCurrencyList = [];
2596
2706
  this.clearCustomerBoundDiscounts(tempOrder);
2707
+ this.applyDiscount();
2597
2708
  this.persistTempOrder();
2598
2709
  this.saveDraftInBackground();
2599
2710
  this.core.effects.emit(import_types.OrderHooks.OnOrderCustomerChange, null);
@@ -2899,21 +3010,29 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2899
3010
  devicePrefix
2900
3011
  });
2901
3012
  }
2902
- async shouldMergeProductToOrder(params) {
3013
+ normalizeShouldMergeProductResult(result) {
3014
+ if (typeof result === "boolean")
3015
+ return result;
3016
+ if (result && typeof result === "object" && typeof result.shouldMerge === "boolean") {
3017
+ return result.shouldMerge;
3018
+ }
3019
+ return true;
3020
+ }
3021
+ shouldMergeProductToOrder(params) {
2903
3022
  var _a;
2904
3023
  const onBeforeMergeProductToOrder = (_a = this.orderHooks) == null ? void 0 : _a.onBeforeMergeProductToOrder;
2905
3024
  if (!onBeforeMergeProductToOrder)
2906
3025
  return true;
2907
- const result = await onBeforeMergeProductToOrder({
3026
+ const result = onBeforeMergeProductToOrder({
2908
3027
  ...params,
2909
3028
  defaultShouldMerge: true
2910
3029
  });
2911
- if (typeof result === "boolean")
2912
- return result;
2913
- if (result && typeof result === "object" && typeof result.shouldMerge === "boolean") {
2914
- return result.shouldMerge;
3030
+ if (result && typeof result === "object" && typeof result.then === "function") {
3031
+ return Promise.resolve(result).then(
3032
+ (resolved) => this.normalizeShouldMergeProductResult(resolved)
3033
+ );
2915
3034
  }
2916
- return true;
3035
+ return this.normalizeShouldMergeProductResult(result);
2917
3036
  }
2918
3037
  hasOrderProductLineNote(product) {
2919
3038
  return typeof (product == null ? void 0 : product.note) === "string" && product.note.trim().length > 0;
@@ -2929,6 +3048,101 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2929
3048
  const bookingUid = (product == null ? void 0 : product.booking_uid) ?? ((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.booking_uid);
2930
3049
  return bookingUid !== void 0 && bookingUid !== null && String(bookingUid) !== "";
2931
3050
  }
3051
+ isMultiCurrencySettlementEnabled() {
3052
+ var _a;
3053
+ return ((_a = this.otherParams) == null ? void 0 : _a.enableMultiCurrencySettlement) === true;
3054
+ }
3055
+ isActiveVirtualSettlementOrder(tempOrder) {
3056
+ return this.isMultiCurrencySettlementEnabled() && (0, import_virtualSettlement.isVirtualSettlementOrder)(tempOrder);
3057
+ }
3058
+ shouldUseVirtualSettlementSummary(tempOrder) {
3059
+ var _a, _b;
3060
+ return this.isActiveVirtualSettlementOrder(tempOrder) || ((_b = (_a = tempOrder == null ? void 0 : tempOrder.metadata) == null ? void 0 : _a.currency_settlement_config) == null ? void 0 : _b.settlement_type) === "virtual_currency";
3061
+ }
3062
+ normalizeVirtualSettlementProductIfEnabled(product) {
3063
+ return this.isMultiCurrencySettlementEnabled() ? (0, import_virtualSettlement.normalizeVirtualSettlementOrderProduct)(product) : product;
3064
+ }
3065
+ assertAndLockProductSettlement(tempOrder, product) {
3066
+ if (!this.isMultiCurrencySettlementEnabled())
3067
+ return;
3068
+ const currentKey = (0, import_virtualSettlement.getTempOrderSettlementKey)(tempOrder);
3069
+ const incomingKey = (0, import_virtualSettlement.getSettlementKey)(
3070
+ (0, import_virtualSettlement.getSelectedSettlementSnapshot)(product)
3071
+ ) || "legal_currency";
3072
+ if (currentKey && currentKey !== incomingKey) {
3073
+ throw new import_virtualSettlement.OrderSettlementConflictError(currentKey, incomingKey);
3074
+ }
3075
+ const snapshot = (0, import_virtualSettlement.getSelectedSettlementSnapshot)(product);
3076
+ if ((snapshot == null ? void 0 : snapshot.settlement_type) === "virtual_currency" && tempOrder.customer_id && Number(tempOrder.customer_id) !== 1) {
3077
+ const currencyProductId = Number(snapshot.currency_product_id);
3078
+ const asset = (this.store.virtualCurrencyList || []).find(
3079
+ (item) => Number(item == null ? void 0 : item.product_id) === currencyProductId
3080
+ );
3081
+ if (!asset) {
3082
+ throw new import_virtualSettlement.VirtualCurrencyAssetNotFoundError(currencyProductId);
3083
+ }
3084
+ const existedAmount = tempOrder.products.reduce(
3085
+ (sum, item) => sum.plus(
3086
+ new import_decimal.default(item.selling_price || 0).times(item.num || 1)
3087
+ ),
3088
+ new import_decimal.default(0)
3089
+ );
3090
+ const requiredAmount = existedAmount.plus(
3091
+ new import_decimal.default(snapshot.price || 0).times(product.num || 1)
3092
+ );
3093
+ const balance = new import_decimal.default(asset.balance || 0);
3094
+ if (balance.lt(requiredAmount)) {
3095
+ throw new import_virtualSettlement.VirtualCurrencyBalanceError(
3096
+ balance.toFixed(2),
3097
+ requiredAmount.toFixed(2)
3098
+ );
3099
+ }
3100
+ }
3101
+ (0, import_virtualSettlement.applyTempOrderSettlementState)(
3102
+ tempOrder,
3103
+ snapshot || {
3104
+ settlement_type: "legal_currency",
3105
+ price: product.selling_price ?? product.original_price ?? product.payment_price ?? 0,
3106
+ unit_label: tempOrder.currency_code,
3107
+ symbol: tempOrder.currency_symbol,
3108
+ amount_format: tempOrder.currency_format
3109
+ }
3110
+ );
3111
+ }
3112
+ syncTempOrderSettlementState(tempOrder) {
3113
+ if (!this.isMultiCurrencySettlementEnabled())
3114
+ return;
3115
+ tempOrder.metadata = tempOrder.metadata || {};
3116
+ if (!tempOrder.products.length) {
3117
+ (0, import_virtualSettlement.releaseTempOrderSettlementState)(tempOrder);
3118
+ return;
3119
+ }
3120
+ const snapshot = (0, import_virtualSettlement.getTempOrderSettlementSnapshot)(tempOrder);
3121
+ if (snapshot) {
3122
+ (0, import_virtualSettlement.applyTempOrderSettlementState)(tempOrder, snapshot);
3123
+ return;
3124
+ }
3125
+ tempOrder.metadata.cart_settlement_key = "legal_currency";
3126
+ }
3127
+ prepareVirtualSettlementTempOrder(tempOrder) {
3128
+ if (!this.isMultiCurrencySettlementEnabled())
3129
+ return;
3130
+ this.syncTempOrderSettlementState(tempOrder);
3131
+ if (!this.isActiveVirtualSettlementOrder(tempOrder))
3132
+ return;
3133
+ tempOrder.products = (0, import_virtualSettlement.normalizeVirtualSettlementProducts)(tempOrder.products);
3134
+ tempOrder.discount_list = [];
3135
+ tempOrder.shop_discount = "0.00";
3136
+ tempOrder.surcharge_fee = "0.00";
3137
+ tempOrder.surcharges = [];
3138
+ const virtualOrder = tempOrder;
3139
+ virtualOrder.discount_amount = "0.00";
3140
+ virtualOrder.product_tax_fee = "0.00";
3141
+ virtualOrder.tax_fee = "0.00";
3142
+ virtualOrder.shipping_fee = "0.00";
3143
+ virtualOrder.shipping_tax_fee = "0.00";
3144
+ virtualOrder.tip_fee = "0.00";
3145
+ }
2932
3146
  // ─── TempOrder: 商品 CRUD ───
2933
3147
  /**
2934
3148
  * 预约商品加车后的统一收尾:促销、折扣、summary 重算与持久化(批量拆行时只调用一次)。
@@ -2938,13 +3152,15 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2938
3152
  */
2939
3153
  async finalizeProductOrderMutation(tempOrder, options) {
2940
3154
  this.syncTempOrderHolderFromBookings(tempOrder);
2941
- if (!(options == null ? void 0 : options.skipEditDiscountConfigRefresh)) {
3155
+ this.prepareVirtualSettlementTempOrder(tempOrder);
3156
+ const isVirtualSettlement = this.isActiveVirtualSettlementOrder(tempOrder);
3157
+ if (!(options == null ? void 0 : options.skipEditDiscountConfigRefresh) && !isVirtualSettlement) {
2942
3158
  await this.ensureEditDiscountConfigForProductChange(tempOrder);
2943
3159
  }
2944
- if (!(options == null ? void 0 : options.skipDiscountRecalculation)) {
3160
+ if (!(options == null ? void 0 : options.skipDiscountRecalculation) && !isVirtualSettlement) {
2945
3161
  await this.applyPromotion();
2946
3162
  }
2947
- if (!(options == null ? void 0 : options.skipDiscountRecalculation)) {
3163
+ if (!(options == null ? void 0 : options.skipDiscountRecalculation) && !isVirtualSettlement) {
2948
3164
  this.applyDiscount();
2949
3165
  }
2950
3166
  this.sanitizeTempOrderProducts(tempOrder);
@@ -2956,21 +3172,34 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2956
3172
  * 带 booking 且 num>1 时由 `addProductToOrder` 拆成多次本方法调用(每次 num=1)。
2957
3173
  *
2958
3174
  * @example
2959
- * await this.appendProductLineToTempOrder(tempOrder, { product_id: 1, num: 1 }, booking);
3175
+ * const pending = this.appendProductLineToTempOrder(
3176
+ * tempOrder,
3177
+ * { product_id: 1, num: 1 },
3178
+ * booking,
3179
+ * );
3180
+ * if (pending) await pending;
2960
3181
  */
2961
- async appendProductLineToTempOrder(tempOrder, product, booking) {
2962
- var _a, _b;
3182
+ appendProductLineToTempOrder(tempOrder, product, booking, options) {
3183
+ var _a, _b, _c, _d, _e, _f;
2963
3184
  const linked = booking ? this.createLinkedProductAndBooking({ product, booking }) : null;
2964
3185
  const productToAdd = (linked == null ? void 0 : linked.product) || product;
3186
+ this.assertAndLockProductSettlement(tempOrder, productToAdd);
2965
3187
  const incomingFingerprint = (0, import_utils3.buildProductLineFingerprint)(
2966
3188
  (0, import_utils.getProductSkuOptions)(productToAdd),
2967
3189
  productToAdd.product_bundle
2968
3190
  );
2969
- const normalizedIncoming = (0, import_utils.mergeOrderProductDisplayFields)(
2970
- productToAdd,
2971
- (0, import_utils3.normalizeOrderProduct)(productToAdd)
3191
+ const normalizedIncoming = this.normalizeVirtualSettlementProductIfEnabled(
3192
+ (0, import_utils.mergeOrderProductDisplayFields)(
3193
+ productToAdd,
3194
+ (0, import_utils3.normalizeOrderProduct)(productToAdd)
3195
+ )
2972
3196
  );
2973
- const incomingBookingUid = productToAdd.booking_uid ?? ((_a = productToAdd.metadata) == null ? void 0 : _a.booking_uid);
3197
+ const isWeighingProduct = Number(((_a = normalizedIncoming.product_sku) == null ? void 0 : _a.open_sold_weight) || 0) === 1;
3198
+ const netWeight = Number((_b = normalizedIncoming.product_sku) == null ? void 0 : _b.net_weight);
3199
+ if (isWeighingProduct && (!Number.isFinite(netWeight) || netWeight <= 0)) {
3200
+ throw new Error("[Order] 称重商品净重必须大于 0");
3201
+ }
3202
+ const incomingBookingUid = productToAdd.booking_uid ?? ((_c = productToAdd.metadata) == null ? void 0 : _c.booking_uid);
2974
3203
  if (incomingBookingUid !== void 0 && incomingBookingUid !== null && String(incomingBookingUid) !== "") {
2975
3204
  normalizedIncoming.booking_uid = String(incomingBookingUid);
2976
3205
  normalizedIncoming.metadata = {
@@ -2985,14 +3214,18 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2985
3214
  normalizedIncoming
2986
3215
  );
2987
3216
  const hasIncomingProductNote = this.hasOrderProductLineNote(normalizedIncoming);
3217
+ const hasIncomingManualProductDiscount = isManualProductDiscountProduct(normalizedIncoming);
2988
3218
  const hasIncomingBookingUid = this.hasLinkedBookingUid(productToAdd) || this.hasLinkedBookingUid(normalizedIncoming);
2989
- const shouldForceNewLine = !!booking || hasIncomingProductNote || hasIncomingBookingUid;
3219
+ const isIncomingCustomItem = ((_e = (_d = productToAdd.metadata) == null ? void 0 : _d.origin) == null ? void 0 : _e.isCustomItem) === true || ((_f = productToAdd._origin) == null ? void 0 : _f.isCustomItem) === true;
3220
+ const shouldForceNewLine = !!booking || hasIncomingProductNote || hasIncomingManualProductDiscount || hasIncomingBookingUid || isIncomingCustomItem || isWeighingProduct;
2990
3221
  const matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex((item) => {
2991
3222
  var _a2;
2992
3223
  if (this.hasGoodPassDiscount(item))
2993
3224
  return false;
2994
3225
  if (this.hasOrderProductLineNote(item))
2995
3226
  return false;
3227
+ if (isManualProductDiscountProduct(item))
3228
+ return false;
2996
3229
  if (item.order_detail_id !== void 0 && item.order_detail_id !== null)
2997
3230
  return false;
2998
3231
  if ((_a2 = item.metadata) == null ? void 0 : _a2.is_edit_for_runtime)
@@ -3012,7 +3245,92 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3012
3245
  (0, import_utils.getProductSkuOptions)(matchedProduct),
3013
3246
  matchedProduct.product_bundle
3014
3247
  ) : "";
3015
- const shouldMerge = matchedProduct ? await this.shouldMergeProductToOrder({
3248
+ const commitProductLine = (shouldMerge2) => {
3249
+ var _a2;
3250
+ if (matchedIndex === -1 || !matchedProduct || !shouldMerge2) {
3251
+ this.captureProductRuntime(
3252
+ tempOrder,
3253
+ productToAdd,
3254
+ normalizedIncoming
3255
+ );
3256
+ if (linked) {
3257
+ normalizedIncoming.booking_uid = linked.bookingUid;
3258
+ normalizedIncoming.metadata = {
3259
+ ...normalizedIncoming.metadata || {},
3260
+ booking_uid: linked.bookingUid
3261
+ };
3262
+ }
3263
+ const insertAtIndex = options == null ? void 0 : options.insertAtIndex;
3264
+ if (Number.isInteger(insertAtIndex) && Number(insertAtIndex) >= 0 && Number(insertAtIndex) < tempOrder.products.length) {
3265
+ tempOrder.products = [
3266
+ ...tempOrder.products.slice(0, insertAtIndex),
3267
+ normalizedIncoming,
3268
+ ...tempOrder.products.slice(insertAtIndex)
3269
+ ];
3270
+ } else {
3271
+ tempOrder.products = [...tempOrder.products, normalizedIncoming];
3272
+ }
3273
+ } else {
3274
+ const targetProduct = matchedProduct;
3275
+ const targetUid = (_a2 = targetProduct.metadata) == null ? void 0 : _a2.unique_identification_number;
3276
+ const normalizedProduct = this.normalizeVirtualSettlementProductIfEnabled(
3277
+ (0, import_utils.mergeOrderProductDisplayFields)(
3278
+ targetProduct,
3279
+ (0, import_utils3.normalizeOrderProduct)({
3280
+ ...productToAdd,
3281
+ metadata: {
3282
+ ...productToAdd.metadata || {},
3283
+ unique_identification_number: targetUid
3284
+ }
3285
+ })
3286
+ )
3287
+ );
3288
+ normalizedProduct.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
3289
+ normalizedProduct.discount_list
3290
+ );
3291
+ const nextNum = (0, import_utils3.getSafeProductNum)(targetProduct.num + normalizedProduct.num);
3292
+ tempOrder.products[matchedIndex] = {
3293
+ ...targetProduct,
3294
+ ...normalizedProduct,
3295
+ discount_list: normalizedProduct.discount_list,
3296
+ metadata: {
3297
+ ...targetProduct.metadata || {},
3298
+ ...normalizedProduct.metadata || {},
3299
+ unique_identification_number: targetUid
3300
+ },
3301
+ product_sku: {
3302
+ ...targetProduct.product_sku || { option: [] },
3303
+ ...normalizedProduct.product_sku || { option: [] },
3304
+ option: (0, import_utils.getProductSkuOptions)(normalizedProduct)
3305
+ },
3306
+ note: targetProduct.note,
3307
+ order_detail_id: targetProduct.order_detail_id,
3308
+ num: nextNum
3309
+ };
3310
+ this.captureProductRuntime(
3311
+ tempOrder,
3312
+ productToAdd,
3313
+ tempOrder.products[matchedIndex],
3314
+ targetUid
3315
+ );
3316
+ if (matchedIndex !== tempOrder.products.length - 1) {
3317
+ const mergedProduct = tempOrder.products[matchedIndex];
3318
+ tempOrder.products = [
3319
+ ...tempOrder.products.slice(0, matchedIndex),
3320
+ ...tempOrder.products.slice(matchedIndex + 1),
3321
+ mergedProduct
3322
+ ];
3323
+ }
3324
+ }
3325
+ if (linked) {
3326
+ tempOrder.bookings = [...tempOrder.bookings || [], linked.booking];
3327
+ }
3328
+ };
3329
+ if (!matchedProduct) {
3330
+ commitProductLine(false);
3331
+ return;
3332
+ }
3333
+ const shouldMerge = this.shouldMergeProductToOrder({
3016
3334
  incomingProduct: productToAdd,
3017
3335
  normalizedIncoming,
3018
3336
  matchedProduct,
@@ -3021,83 +3339,11 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3021
3339
  existedFingerprint,
3022
3340
  tempOrder,
3023
3341
  booking
3024
- }) : false;
3025
- if (matchedIndex === -1 || !matchedProduct || !shouldMerge) {
3026
- this.captureProductRuntime(
3027
- tempOrder,
3028
- productToAdd,
3029
- normalizedIncoming
3030
- );
3031
- if (linked) {
3032
- normalizedIncoming.booking_uid = linked.bookingUid;
3033
- normalizedIncoming.metadata = {
3034
- ...normalizedIncoming.metadata || {},
3035
- booking_uid: linked.bookingUid
3036
- };
3037
- }
3038
- tempOrder.products = [...tempOrder.products, normalizedIncoming];
3039
- } else {
3040
- const targetProduct = matchedProduct;
3041
- const targetUid = (_b = targetProduct.metadata) == null ? void 0 : _b.unique_identification_number;
3042
- const normalizedProduct = (0, import_utils.mergeOrderProductDisplayFields)(
3043
- targetProduct,
3044
- (0, import_utils3.normalizeOrderProduct)({
3045
- ...productToAdd,
3046
- metadata: {
3047
- ...productToAdd.metadata || {},
3048
- unique_identification_number: targetUid
3049
- }
3050
- })
3051
- );
3052
- normalizedProduct.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
3053
- normalizedProduct.discount_list
3054
- );
3055
- const nextNum = (0, import_utils3.getSafeProductNum)(targetProduct.num + normalizedProduct.num);
3056
- const targetIsManualProductDiscount = isManualProductDiscountProduct(targetProduct);
3057
- const nextDiscountList = targetIsManualProductDiscount ? (0, import_utils.normalizeOrderProductDiscountList)(
3058
- (0, import_manualProductDiscount.syncManualProductDiscountProductNum)(
3059
- targetProduct.discount_list,
3060
- nextNum
3061
- )
3062
- ) : normalizedProduct.discount_list;
3063
- tempOrder.products[matchedIndex] = {
3064
- ...targetProduct,
3065
- ...normalizedProduct,
3066
- discount_list: nextDiscountList,
3067
- metadata: {
3068
- ...targetProduct.metadata || {},
3069
- ...normalizedProduct.metadata || {},
3070
- unique_identification_number: targetUid
3071
- },
3072
- product_sku: {
3073
- ...targetProduct.product_sku || { option: [] },
3074
- ...normalizedProduct.product_sku || { option: [] },
3075
- option: (0, import_utils.getProductSkuOptions)(normalizedProduct)
3076
- },
3077
- ...targetIsManualProductDiscount ? {
3078
- selling_price: targetProduct.selling_price,
3079
- original_price: targetProduct.original_price,
3080
- payment_price: targetProduct.payment_price,
3081
- metadata: {
3082
- ...normalizedProduct.metadata || {},
3083
- ...targetProduct.metadata || {},
3084
- unique_identification_number: targetUid
3085
- }
3086
- } : {},
3087
- note: targetProduct.note,
3088
- order_detail_id: targetProduct.order_detail_id,
3089
- num: nextNum
3090
- };
3091
- this.captureProductRuntime(
3092
- tempOrder,
3093
- productToAdd,
3094
- tempOrder.products[matchedIndex],
3095
- targetUid
3096
- );
3097
- }
3098
- if (linked) {
3099
- tempOrder.bookings = [...tempOrder.bookings || [], linked.booking];
3342
+ });
3343
+ if (shouldMerge && typeof shouldMerge === "object" && typeof shouldMerge.then === "function") {
3344
+ return Promise.resolve(shouldMerge).then(commitProductLine);
3100
3345
  }
3346
+ commitProductLine(shouldMerge);
3101
3347
  }
3102
3348
  /**
3103
3349
  * 添加商品行。带 booking 时强制独立行;num>1 时拆成多条 num=1 的 product+booking(对齐 BookingByStep / ticketBooking addService)。
@@ -3106,8 +3352,15 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3106
3352
  * await order.addProductToOrder({ product_id: 1, num: 3 }, { start_time: '10:00' });
3107
3353
  * // → tempOrder.products 新增 3 行,每行 num=1,bookings 3 条
3108
3354
  */
3109
- async addProductToOrder(product, booking) {
3355
+ async addProductToOrder(product, booking, options) {
3110
3356
  const tempOrder = this.ensureTempOrder();
3357
+ const insertAfterProductUid = options == null ? void 0 : options.insertAfterProductUid;
3358
+ const anchorIndex = booking && insertAfterProductUid ? tempOrder.products.findIndex((line) => {
3359
+ var _a;
3360
+ const uid = ((_a = line.metadata) == null ? void 0 : _a.unique_identification_number) || line.unique_identification_number;
3361
+ return uid !== void 0 && uid !== null && String(uid) === String(insertAfterProductUid);
3362
+ }) : -1;
3363
+ let insertAtIndex = anchorIndex >= 0 ? anchorIndex + 1 : void 0;
3111
3364
  if (booking) {
3112
3365
  const productRecord = product;
3113
3366
  const splitCount = (0, import_utils3.getSafeProductNum)(
@@ -3118,17 +3371,29 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3118
3371
  const singleLine = (0, import_lodash_es.cloneDeep)(productRecord);
3119
3372
  singleLine.num = 1;
3120
3373
  delete singleLine.product_quantity;
3121
- await this.appendProductLineToTempOrder(
3374
+ const appendResult2 = this.appendProductLineToTempOrder(
3122
3375
  tempOrder,
3123
3376
  singleLine,
3124
- (0, import_lodash_es.cloneDeep)(booking)
3377
+ (0, import_lodash_es.cloneDeep)(booking),
3378
+ { insertAtIndex }
3125
3379
  );
3380
+ if (appendResult2)
3381
+ await appendResult2;
3382
+ if (insertAtIndex !== void 0)
3383
+ insertAtIndex += 1;
3126
3384
  }
3127
3385
  await this.finalizeProductOrderMutation(tempOrder);
3128
3386
  return tempOrder.products;
3129
3387
  }
3130
3388
  }
3131
- await this.appendProductLineToTempOrder(tempOrder, product, booking);
3389
+ const appendResult = this.appendProductLineToTempOrder(
3390
+ tempOrder,
3391
+ product,
3392
+ booking,
3393
+ { insertAtIndex }
3394
+ );
3395
+ if (appendResult)
3396
+ await appendResult;
3132
3397
  await this.finalizeProductOrderMutation(tempOrder);
3133
3398
  this.logInfo("addProductToOrder success", {
3134
3399
  product_id: product.product_id,
@@ -3163,16 +3428,24 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3163
3428
  const singleLine = (0, import_lodash_es.cloneDeep)(productRecord);
3164
3429
  singleLine.num = 1;
3165
3430
  delete singleLine.product_quantity;
3166
- await this.appendProductLineToTempOrder(
3431
+ const appendResult2 = this.appendProductLineToTempOrder(
3167
3432
  tempOrder,
3168
3433
  singleLine,
3169
3434
  (0, import_lodash_es.cloneDeep)(booking)
3170
3435
  );
3436
+ if (appendResult2)
3437
+ await appendResult2;
3171
3438
  }
3172
3439
  continue;
3173
3440
  }
3174
3441
  }
3175
- await this.appendProductLineToTempOrder(tempOrder, product, booking);
3442
+ const appendResult = this.appendProductLineToTempOrder(
3443
+ tempOrder,
3444
+ product,
3445
+ booking
3446
+ );
3447
+ if (appendResult)
3448
+ await appendResult;
3176
3449
  }
3177
3450
  await this.finalizeProductOrderMutation(tempOrder, options);
3178
3451
  this.logInfo("addProductsToOrder success", {
@@ -3403,9 +3676,11 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3403
3676
  delete nextProduct.metadata.main_product_original_price;
3404
3677
  delete nextProduct.metadata.price_schema_version;
3405
3678
  }
3406
- let normalizedProduct = (0, import_utils.mergeOrderProductDisplayFields)(
3407
- nextProduct,
3408
- (0, import_utils3.normalizeOrderProduct)(nextProduct)
3679
+ let normalizedProduct = this.normalizeVirtualSettlementProductIfEnabled(
3680
+ (0, import_utils.mergeOrderProductDisplayFields)(
3681
+ nextProduct,
3682
+ (0, import_utils3.normalizeOrderProduct)(nextProduct)
3683
+ )
3409
3684
  );
3410
3685
  normalizedProduct.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
3411
3686
  normalizedProduct.discount_list
@@ -3536,20 +3811,49 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3536
3811
  throw new Error("[Order] 目标商品不存在,无法更新数量");
3537
3812
  }
3538
3813
  const targetProduct = tempOrder.products[productIndex];
3539
- const normalizedProduct = (0, import_utils3.normalizeOrderProduct)({
3540
- ...targetProduct,
3541
- num: (0, import_utils3.getSafeProductNum)(num),
3542
- metadata: {
3543
- ...targetProduct.metadata || {},
3544
- unique_identification_number: ((_a = targetProduct.metadata) == null ? void 0 : _a.unique_identification_number) || unique_identification_number
3545
- }
3546
- });
3814
+ const normalizedProduct = this.normalizeVirtualSettlementProductIfEnabled(
3815
+ (0, import_utils3.normalizeOrderProduct)({
3816
+ ...targetProduct,
3817
+ num: (0, import_utils3.getSafeProductNum)(num),
3818
+ metadata: {
3819
+ ...targetProduct.metadata || {},
3820
+ unique_identification_number: ((_a = targetProduct.metadata) == null ? void 0 : _a.unique_identification_number) || unique_identification_number
3821
+ }
3822
+ })
3823
+ );
3547
3824
  normalizedProduct.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
3548
3825
  normalizedProduct.discount_list
3549
3826
  );
3827
+ const settlementSnapshot = (0, import_virtualSettlement.getSelectedSettlementSnapshot)(normalizedProduct);
3828
+ if (this.isMultiCurrencySettlementEnabled() && (settlementSnapshot == null ? void 0 : settlementSnapshot.settlement_type) === "virtual_currency" && tempOrder.customer_id && Number(tempOrder.customer_id) !== 1) {
3829
+ const currencyProductId = Number(settlementSnapshot.currency_product_id);
3830
+ const asset = (this.store.virtualCurrencyList || []).find(
3831
+ (item) => Number(item == null ? void 0 : item.product_id) === currencyProductId
3832
+ );
3833
+ if (!asset) {
3834
+ throw new import_virtualSettlement.VirtualCurrencyAssetNotFoundError(currencyProductId);
3835
+ }
3836
+ const requiredAmount = tempOrder.products.reduce((sum, item, index) => {
3837
+ const current = index === productIndex ? normalizedProduct : item;
3838
+ const currentSnapshot = (0, import_virtualSettlement.getSelectedSettlementSnapshot)(current);
3839
+ return sum.plus(
3840
+ new import_decimal.default((currentSnapshot == null ? void 0 : currentSnapshot.price) || current.selling_price || 0).times(current.num || 1)
3841
+ );
3842
+ }, new import_decimal.default(0));
3843
+ const balance = new import_decimal.default(asset.balance || 0);
3844
+ if (balance.lt(requiredAmount)) {
3845
+ throw new import_virtualSettlement.VirtualCurrencyBalanceError(
3846
+ balance.toFixed(2),
3847
+ requiredAmount.toFixed(2)
3848
+ );
3849
+ }
3850
+ }
3550
3851
  tempOrder.products[productIndex] = normalizedProduct;
3551
- await this.applyPromotion();
3552
- this.applyDiscount();
3852
+ this.prepareVirtualSettlementTempOrder(tempOrder);
3853
+ if (!this.isActiveVirtualSettlementOrder(tempOrder)) {
3854
+ await this.applyPromotion();
3855
+ this.applyDiscount();
3856
+ }
3553
3857
  this.sanitizeTempOrderProducts(tempOrder);
3554
3858
  await this.recalculateSummary({ createIfMissing: true });
3555
3859
  this.persistTempOrder();
@@ -3610,7 +3914,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3610
3914
  * @example
3611
3915
  * await order.removeProductsFromOrder([identityA, identityB]);
3612
3916
  */
3613
- async removeProductsFromOrder(identities) {
3917
+ async removeProductsFromOrder(identities, options) {
3614
3918
  var _a, _b, _c, _d;
3615
3919
  const tempOrder = this.ensureTempOrder();
3616
3920
  this.repairDuplicateProductLineIdentities(tempOrder);
@@ -3619,6 +3923,13 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3619
3923
  }
3620
3924
  const productsBeforeRemove = tempOrder.products || [];
3621
3925
  const bookingsBeforeRemove = tempOrder.bookings || [];
3926
+ const preserveDisplayPosition = options == null ? void 0 : options.preserveDisplayPosition;
3927
+ const anchorIndex = preserveDisplayPosition ? productsBeforeRemove.findIndex((item) => {
3928
+ var _a2;
3929
+ const uid = ((_a2 = item.metadata) == null ? void 0 : _a2.unique_identification_number) || item.unique_identification_number;
3930
+ return uid !== void 0 && uid !== null && String(uid) === String(preserveDisplayPosition.anchorProductUid);
3931
+ }) : -1;
3932
+ const productsAfterAnchor = anchorIndex >= 0 ? productsBeforeRemove.slice(anchorIndex + 1) : [];
3622
3933
  const matchedProducts = productsBeforeRemove.filter((item) => {
3623
3934
  return identities.some((identity) => (0, import_utils3.isIdentityMatch)(item, identity));
3624
3935
  });
@@ -3659,14 +3970,37 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3659
3970
  return !(isAddTimeProduct && lineBookingUid !== void 0 && lineBookingUid !== null && linkedBookingUidsToRemove.has(String(lineBookingUid)));
3660
3971
  });
3661
3972
  }
3973
+ if (preserveDisplayPosition && anchorIndex >= 0) {
3974
+ const remainingProductIndex = tempOrder.products.findIndex((item) => {
3975
+ var _a2;
3976
+ const uid = ((_a2 = item.metadata) == null ? void 0 : _a2.unique_identification_number) || item.unique_identification_number;
3977
+ return uid !== void 0 && uid !== null && String(uid) === String(preserveDisplayPosition.remainingProductUid);
3978
+ });
3979
+ if (remainingProductIndex >= 0) {
3980
+ const remainingProduct = tempOrder.products[remainingProductIndex];
3981
+ const nextProduct = productsAfterAnchor.find(
3982
+ (item) => tempOrder.products.includes(item)
3983
+ );
3984
+ const productsWithoutRemaining = [
3985
+ ...tempOrder.products.slice(0, remainingProductIndex),
3986
+ ...tempOrder.products.slice(remainingProductIndex + 1)
3987
+ ];
3988
+ const nextProductIndex = nextProduct ? productsWithoutRemaining.indexOf(nextProduct) : -1;
3989
+ tempOrder.products = nextProductIndex >= 0 ? [
3990
+ ...productsWithoutRemaining.slice(0, nextProductIndex),
3991
+ remainingProduct,
3992
+ ...productsWithoutRemaining.slice(nextProductIndex)
3993
+ ] : [...productsWithoutRemaining, remainingProduct];
3994
+ }
3995
+ }
3662
3996
  await this.finalizeAfterProductsMutation(tempOrder);
3663
3997
  this.logInfo("removeProductsFromOrder success", {
3664
3998
  identities
3665
3999
  });
3666
4000
  return tempOrder.products;
3667
4001
  }
3668
- async removeProductFromOrder(identity) {
3669
- return this.removeProductsFromOrder([identity]);
4002
+ async removeProductFromOrder(identity, options) {
4003
+ return this.removeProductsFromOrder([identity], options);
3670
4004
  }
3671
4005
  /**
3672
4006
  * 仅清空购物车行(products / bookings),不重置整单。
@@ -3676,6 +4010,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3676
4010
  const tempOrder = this.ensureTempOrder();
3677
4011
  tempOrder.products = [];
3678
4012
  tempOrder.bookings = [];
4013
+ (0, import_virtualSettlement.releaseTempOrderSettlementState)(tempOrder);
3679
4014
  this.syncTempOrderHolderFromBookings(tempOrder);
3680
4015
  if (tempOrder._extend && typeof tempOrder._extend === "object") {
3681
4016
  tempOrder._extend = {
@@ -3691,6 +4026,37 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3691
4026
  this.logInfo("clearOrderCartLines success", {});
3692
4027
  return tempOrder;
3693
4028
  }
4029
+ /**
4030
+ * 切换购物车结算单位时清理所有会影响新币种的订单状态,但保留当前客户。
4031
+ */
4032
+ async clearOrderForSettlementSwitch() {
4033
+ var _a, _b;
4034
+ const tempOrder = this.ensureTempOrder();
4035
+ tempOrder.products = [];
4036
+ tempOrder.bookings = [];
4037
+ tempOrder.discount_list = [];
4038
+ tempOrder.payments = [];
4039
+ tempOrder.refunds = [];
4040
+ tempOrder.shop_discount = "0.00";
4041
+ tempOrder.surcharges = [];
4042
+ (0, import_virtualSettlement.releaseTempOrderSettlementState)(tempOrder);
4043
+ this.syncTempOrderHolderFromBookings(tempOrder);
4044
+ if (tempOrder._extend && typeof tempOrder._extend === "object") {
4045
+ tempOrder._extend = {
4046
+ ...tempOrder._extend,
4047
+ productsByUid: {}
4048
+ };
4049
+ }
4050
+ await ((_a = this.store.discount) == null ? void 0 : _a.setDiscountList([]));
4051
+ await ((_b = this.store.discount) == null ? void 0 : _b.setOriginalDiscountList([]));
4052
+ this.hasActiveCustomerBoundDiscount = false;
4053
+ this.lastUnfulfilledPromotions = [];
4054
+ this.lastGiftActions = null;
4055
+ await this.recalculateSummary({ createIfMissing: true });
4056
+ this.persistTempOrder();
4057
+ this.logInfo("clearOrderForSettlementSwitch success", {});
4058
+ return tempOrder;
4059
+ }
3694
4060
  // ─── TempOrder: 提交 ───
3695
4061
  buildCurrentSubmitPayloadForLocalPrint(params) {
3696
4062
  var _a, _b, _c;
@@ -3781,6 +4147,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3781
4147
  async runSubmitTempOrder(params) {
3782
4148
  var _a, _b, _c, _d, _e;
3783
4149
  const tempOrder = this.ensureTempOrder();
4150
+ this.prepareVirtualSettlementTempOrder(tempOrder);
3784
4151
  const shouldConfirmPendingVoucherPayments = (params == null ? void 0 : params.confirmPendingVoucherPayments) !== false;
3785
4152
  const hasPaymentOverride = (params == null ? void 0 : params.payments) !== void 0;
3786
4153
  const preparedPaymentOverride = hasPaymentOverride ? this.prepareVoucherPaymentsForSubmit(
@@ -4741,8 +5108,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4741
5108
  delete row[`product_${"option"}_item`];
4742
5109
  if (!Array.isArray(row.product_bundle))
4743
5110
  row.product_bundle = [];
4744
- if (!row.metadata || typeof row.metadata !== "object")
4745
- row.metadata = {};
5111
+ row.metadata = row.metadata && typeof row.metadata === "object" ? { ...row.metadata } : {};
5112
+ delete row.bundle_edit;
5113
+ delete row.metadata.bundle_edit;
4746
5114
  if (row.booking_uid && !row.metadata.booking_uid) {
4747
5115
  row.metadata.booking_uid = row.booking_uid;
4748
5116
  }
@@ -4770,7 +5138,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4770
5138
  if (result.metadata)
4771
5139
  delete result.metadata.price_schema_version;
4772
5140
  const restored = (0, import_bundleDiscountHydration.restoreHydratedBundleDiscounts)(result, import_utils.normalizeOrderProductDiscountList);
4773
- return this.sanitizeOrderProductForTempOrder(restored);
5141
+ return this.sanitizeOrderProductForTempOrder(
5142
+ this.normalizeVirtualSettlementProductIfEnabled(restored)
5143
+ );
4774
5144
  }
4775
5145
  getLastOrderInfo() {
4776
5146
  var _a;