@pisell/pisellos 2.2.246 → 2.2.248

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.
@@ -91,6 +91,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
91
91
  _defineProperty(_assertThisInitialized(_this), "giftSelectResolver", null);
92
92
  /** applyPromotion 递归保护 flag(写路径同步调 applyPromotion,禁止重入) */
93
93
  _defineProperty(_assertThisInitialized(_this), "isApplyingPromotion", false);
94
+ /** 商品曾应用过客户券卡,客户变更剥离后需强制跑一次 calcDiscount 复位价格 */
95
+ _defineProperty(_assertThisInitialized(_this), "hasActiveCustomerBoundDiscount", false);
94
96
  /** 最近一次 applyPromotion 的未满足促销提示 */
95
97
  _defineProperty(_assertThisInitialized(_this), "lastUnfulfilledPromotions", []);
96
98
  /** 最近一次 applyPromotion 的赠品操作 diff(debug / SDK 读取使用) */
@@ -443,7 +445,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
443
445
  value: function () {
444
446
  var _loadDiscountConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
445
447
  var _this$store$tempOrder, _this$store$discount, _this$store$tempOrder2;
446
- var orderId, discountList, _this$store$discount2, _this$store$discount3, _this$store$discount4, currentEditDiscounts, currentEditDiscountIds, mergedDiscountList;
448
+ var orderId, discountList, _this$store$discount2, _this$store$discount3, _this$store$discount4, currentEditDiscounts, runtimeDiscountIds, runtimeDiscounts, mergedDiscountList;
447
449
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
448
450
  while (1) switch (_context3.prev = _context3.next) {
449
451
  case 0:
@@ -462,29 +464,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
462
464
  case 3:
463
465
  discountList = _context3.sent;
464
466
  if (!discountList) {
465
- _context3.next = 12;
467
+ _context3.next = 13;
466
468
  break;
467
469
  }
468
470
  currentEditDiscounts = (((_this$store$discount2 = this.store.discount) === null || _this$store$discount2 === void 0 ? void 0 : _this$store$discount2.getDiscountList()) || []).filter(function (discount) {
469
471
  return discount === null || discount === void 0 ? void 0 : discount.isEditMode;
470
472
  });
471
- currentEditDiscountIds = new Set(currentEditDiscounts.map(function (discount) {
472
- return discount === null || discount === void 0 ? void 0 : discount.id;
473
- }));
474
- mergedDiscountList = [].concat(_toConsumableArray(currentEditDiscounts), _toConsumableArray(discountList.filter(function (discount) {
475
- return !currentEditDiscountIds.has(discount === null || discount === void 0 ? void 0 : discount.id);
476
- })));
477
- _context3.next = 10;
473
+ runtimeDiscountIds = new Set();
474
+ runtimeDiscounts = discountList.filter(function (discount) {
475
+ if (runtimeDiscountIds.has(discount === null || discount === void 0 ? void 0 : discount.id)) return false;
476
+ runtimeDiscountIds.add(discount === null || discount === void 0 ? void 0 : discount.id);
477
+ return true;
478
+ });
479
+ mergedDiscountList = [].concat(_toConsumableArray(currentEditDiscounts), _toConsumableArray(runtimeDiscounts));
480
+ _context3.next = 11;
478
481
  return (_this$store$discount3 = this.store.discount) === null || _this$store$discount3 === void 0 ? void 0 : _this$store$discount3.setOriginalDiscountList(mergedDiscountList);
479
- case 10:
480
- _context3.next = 12;
482
+ case 11:
483
+ _context3.next = 13;
481
484
  return (_this$store$discount4 = this.store.discount) === null || _this$store$discount4 === void 0 ? void 0 : _this$store$discount4.setDiscountList(mergedDiscountList);
482
- case 12:
485
+ case 13:
483
486
  if (params.apply !== false && (_this$store$tempOrder2 = this.store.tempOrder) !== null && _this$store$tempOrder2 !== void 0 && (_this$store$tempOrder2 = _this$store$tempOrder2.products) !== null && _this$store$tempOrder2 !== void 0 && _this$store$tempOrder2.length) {
484
487
  this.applyDiscount();
485
488
  }
486
489
  return _context3.abrupt("return", this.getDiscountList());
487
- case 14:
490
+ case 15:
488
491
  case "end":
489
492
  return _context3.stop();
490
493
  }
@@ -660,13 +663,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
660
663
  }, {
661
664
  key: "applyDiscount",
662
665
  value: function applyDiscount() {
663
- var _this$store$discount9, _tempOrder$holder3, _tempOrder$holder4, _this$store$summary2;
666
+ var _this$store$discount9,
667
+ _tempOrder$holder3,
668
+ _tempOrder$holder4,
669
+ _this$store$summary2,
670
+ _this2 = this;
664
671
  var tempOrder = this.store.tempOrder;
665
672
  // 任意 products CRUD 后都应当重算 discount 状态;即使 products 为空,
666
673
  // 也需要让 Rules.calcDiscount 把 DiscountModule 的 isSelected / isAvailable /
667
674
  // appliedProductDetails / savedAmount 复位。
668
675
  if (!tempOrder) return;
669
676
  delete tempOrder.discount_list;
677
+ if (this.shouldSkipDiscountCalculation(tempOrder)) return;
670
678
  var rulesModule = this.store.rules;
671
679
  if (!rulesModule) return;
672
680
  var discountList = ((_this$store$discount9 = this.store.discount) === null || _this$store$discount9 === void 0 ? void 0 : _this$store$discount9.getDiscountList()) || [];
@@ -700,6 +708,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
700
708
  OrderModule.populateSavedAmounts(result.productList || tempOrder.products, result.discountList);
701
709
  (_this$store$discount10 = this.store.discount) === null || _this$store$discount10 === void 0 || _this$store$discount10.setDiscountList(result.discountList);
702
710
  }
711
+ this.hasActiveCustomerBoundDiscount = (tempOrder.products || []).some(function (product) {
712
+ return _this2.productHasCustomerBoundDiscount(product);
713
+ });
703
714
  }
704
715
 
705
716
  // ─── 促销/赠品 ──────────────────────────────────────
@@ -758,8 +769,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
758
769
  key: "applyPromotion",
759
770
  value: (function () {
760
771
  var _applyPromotion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
761
- var _this2 = this;
762
- var tempOrder, result, removeSet, _iterator3, _step3, reduce, _iterator6, _step6, _loop2, _iterator4, _step4, _loop, payload;
772
+ var _this$promotionEvalua,
773
+ _this$promotionEvalua2,
774
+ _this3 = this;
775
+ var tempOrder, strategyConfigs, result, removeSet, _iterator3, _step3, reduce, _iterator6, _step6, _loop2, _iterator4, _step4, _loop, payload;
763
776
  return _regeneratorRuntime().wrap(function _callee6$(_context8) {
764
777
  while (1) switch (_context8.prev = _context8.next) {
765
778
  case 0:
@@ -782,8 +795,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
782
795
  }
783
796
  return _context8.abrupt("return");
784
797
  case 7:
798
+ strategyConfigs = (_this$promotionEvalua = (_this$promotionEvalua2 = this.promotionEvaluator).getStrategyConfigs) === null || _this$promotionEvalua === void 0 ? void 0 : _this$promotionEvalua.call(_this$promotionEvalua2);
799
+ if (!(Array.isArray(strategyConfigs) && strategyConfigs.length === 0)) {
800
+ _context8.next = 10;
801
+ break;
802
+ }
803
+ return _context8.abrupt("return");
804
+ case 10:
785
805
  this.isApplyingPromotion = true;
786
- _context8.prev = 8;
806
+ _context8.prev = 11;
787
807
  result = processCartPromotion(tempOrder.products, this.promotionEvaluator); // step 1: toRemove —— 直接过滤
788
808
  if (result.giftActions.toRemove.length > 0) {
789
809
  removeSet = new Set(result.giftActions.toRemove.map(String));
@@ -795,16 +815,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
795
815
 
796
816
  // step 2: toReduce —— 调整数量
797
817
  _iterator3 = _createForOfIteratorHelper(result.giftActions.toReduce);
798
- _context8.prev = 12;
818
+ _context8.prev = 15;
799
819
  _iterator3.s();
800
- case 14:
820
+ case 17:
801
821
  if ((_step3 = _iterator3.n()).done) {
802
- _context8.next = 34;
822
+ _context8.next = 37;
803
823
  break;
804
824
  }
805
825
  reduce = _step3.value;
806
826
  _iterator6 = _createForOfIteratorHelper(reduce.items);
807
- _context8.prev = 17;
827
+ _context8.prev = 20;
808
828
  _loop2 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop2() {
809
829
  var item, product;
810
830
  return _regeneratorRuntime().wrap(function _loop2$(_context7) {
@@ -824,47 +844,47 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
824
844
  }, _loop2);
825
845
  });
826
846
  _iterator6.s();
827
- case 20:
847
+ case 23:
828
848
  if ((_step6 = _iterator6.n()).done) {
829
- _context8.next = 24;
849
+ _context8.next = 27;
830
850
  break;
831
851
  }
832
- return _context8.delegateYield(_loop2(), "t0", 22);
833
- case 22:
834
- _context8.next = 20;
852
+ return _context8.delegateYield(_loop2(), "t0", 25);
853
+ case 25:
854
+ _context8.next = 23;
835
855
  break;
836
- case 24:
837
- _context8.next = 29;
856
+ case 27:
857
+ _context8.next = 32;
838
858
  break;
839
- case 26:
840
- _context8.prev = 26;
841
- _context8.t1 = _context8["catch"](17);
842
- _iterator6.e(_context8.t1);
843
859
  case 29:
844
860
  _context8.prev = 29;
845
- _iterator6.f();
846
- return _context8.finish(29);
861
+ _context8.t1 = _context8["catch"](20);
862
+ _iterator6.e(_context8.t1);
847
863
  case 32:
848
- _context8.next = 14;
864
+ _context8.prev = 32;
865
+ _iterator6.f();
866
+ return _context8.finish(32);
867
+ case 35:
868
+ _context8.next = 17;
849
869
  break;
850
- case 34:
851
- _context8.next = 39;
870
+ case 37:
871
+ _context8.next = 42;
852
872
  break;
853
- case 36:
854
- _context8.prev = 36;
855
- _context8.t2 = _context8["catch"](12);
856
- _iterator3.e(_context8.t2);
857
873
  case 39:
858
874
  _context8.prev = 39;
859
- _iterator3.f();
860
- return _context8.finish(39);
875
+ _context8.t2 = _context8["catch"](15);
876
+ _iterator3.e(_context8.t2);
861
877
  case 42:
878
+ _context8.prev = 42;
879
+ _iterator3.f();
880
+ return _context8.finish(42);
881
+ case 45:
862
882
  if (!(result.giftActions.toAdd.length > 0)) {
863
- _context8.next = 65;
883
+ _context8.next = 68;
864
884
  break;
865
885
  }
866
886
  if (this.giftSelectResolver) {
867
- _context8.next = 47;
887
+ _context8.next = 50;
868
888
  break;
869
889
  }
870
890
  if (result.giftActions.toAdd.some(function (g) {
@@ -875,11 +895,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
875
895
  } else {
876
896
  console.warn('[OrderModule] giftSelectResolver not set, skip applying single-option gifts', result.giftActions.toAdd);
877
897
  }
878
- _context8.next = 65;
898
+ _context8.next = 68;
879
899
  break;
880
- case 47:
900
+ case 50:
881
901
  _iterator4 = _createForOfIteratorHelper(result.giftActions.toAdd);
882
- _context8.prev = 48;
902
+ _context8.prev = 51;
883
903
  _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
884
904
  var addAction, _sameStrategy$metadat, sameStrategy, giftResult, giftProducts, giftBookings, _iterator5, _step5, _step5$value, index, gp, booking, linked;
885
905
  return _regeneratorRuntime().wrap(function _loop$(_context6) {
@@ -903,7 +923,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
903
923
  case 6:
904
924
  _context6.prev = 6;
905
925
  _context6.next = 9;
906
- return _this2.giftSelectResolver({
926
+ return _this3.giftSelectResolver({
907
927
  strategyId: addAction.strategyId,
908
928
  strategyName: addAction.strategyName,
909
929
  giftCount: addAction.giftCount,
@@ -938,7 +958,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
938
958
  _context6.next = 26;
939
959
  break;
940
960
  }
941
- linked = _this2.createLinkedProductAndBooking({
961
+ linked = _this3.createLinkedProductAndBooking({
942
962
  product: gp,
943
963
  booking: booking
944
964
  });
@@ -977,33 +997,33 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
977
997
  }, _loop, null, [[6, 39], [14, 31, 34, 37]]);
978
998
  });
979
999
  _iterator4.s();
980
- case 51:
1000
+ case 54:
981
1001
  if ((_step4 = _iterator4.n()).done) {
982
- _context8.next = 57;
1002
+ _context8.next = 60;
983
1003
  break;
984
1004
  }
985
- return _context8.delegateYield(_loop(), "t3", 53);
986
- case 53:
1005
+ return _context8.delegateYield(_loop(), "t3", 56);
1006
+ case 56:
987
1007
  if (!_context8.t3) {
988
- _context8.next = 55;
1008
+ _context8.next = 58;
989
1009
  break;
990
1010
  }
991
- return _context8.abrupt("continue", 55);
992
- case 55:
993
- _context8.next = 51;
1011
+ return _context8.abrupt("continue", 58);
1012
+ case 58:
1013
+ _context8.next = 54;
994
1014
  break;
995
- case 57:
996
- _context8.next = 62;
1015
+ case 60:
1016
+ _context8.next = 65;
997
1017
  break;
998
- case 59:
999
- _context8.prev = 59;
1000
- _context8.t4 = _context8["catch"](48);
1001
- _iterator4.e(_context8.t4);
1002
1018
  case 62:
1003
1019
  _context8.prev = 62;
1004
- _iterator4.f();
1005
- return _context8.finish(62);
1020
+ _context8.t4 = _context8["catch"](51);
1021
+ _iterator4.e(_context8.t4);
1006
1022
  case 65:
1023
+ _context8.prev = 65;
1024
+ _iterator4.f();
1025
+ return _context8.finish(65);
1026
+ case 68:
1007
1027
  tempOrder.products = result.products;
1008
1028
  this.lastUnfulfilledPromotions = result.unfulfilledPromotions;
1009
1029
  this.lastGiftActions = result.giftActions;
@@ -1021,21 +1041,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1021
1041
  products: tempOrder.products
1022
1042
  };
1023
1043
  this.effectsEmit('onPromotionApplied', payload);
1024
- _context8.next = 75;
1044
+ _context8.next = 78;
1025
1045
  break;
1026
- case 72:
1027
- _context8.prev = 72;
1028
- _context8.t5 = _context8["catch"](8);
1029
- console.error('[OrderModule] applyPromotion failed', _context8.t5);
1030
1046
  case 75:
1031
1047
  _context8.prev = 75;
1032
- this.isApplyingPromotion = false;
1033
- return _context8.finish(75);
1048
+ _context8.t5 = _context8["catch"](11);
1049
+ console.error('[OrderModule] applyPromotion failed', _context8.t5);
1034
1050
  case 78:
1051
+ _context8.prev = 78;
1052
+ this.isApplyingPromotion = false;
1053
+ return _context8.finish(78);
1054
+ case 81:
1035
1055
  case "end":
1036
1056
  return _context8.stop();
1037
1057
  }
1038
- }, _callee6, this, [[8, 72, 75, 78], [12, 36, 39, 42], [17, 26, 29, 32], [48, 59, 62, 65]]);
1058
+ }, _callee6, this, [[11, 75, 78, 81], [15, 39, 42, 45], [20, 29, 32, 35], [51, 62, 65, 68]]);
1039
1059
  }));
1040
1060
  function applyPromotion() {
1041
1061
  return _applyPromotion.apply(this, arguments);
@@ -1211,11 +1231,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1211
1231
  }, {
1212
1232
  key: "calculatePaymentTotal",
1213
1233
  value: function calculatePaymentTotal(payments) {
1214
- var _this3 = this;
1234
+ var _this4 = this;
1215
1235
  return mapPaymentItemsToOrderPayments(payments, {
1216
1236
  includeVoided: false
1217
1237
  }).reduce(function (sum, payment) {
1218
- return sum.plus(_this3.calculatePaymentEffectiveAmount(payment));
1238
+ return sum.plus(_this4.calculatePaymentEffectiveAmount(payment));
1219
1239
  }, new Decimal(0));
1220
1240
  }
1221
1241
  }, {
@@ -1267,14 +1287,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1267
1287
  }, {
1268
1288
  key: "calculateDepositPaidAmount",
1269
1289
  value: function calculateDepositPaidAmount(payments) {
1270
- var _this4 = this;
1290
+ var _this5 = this;
1271
1291
  return (payments || []).reduce(function (sum, payment) {
1272
1292
  var paymentRecord = payment;
1273
1293
  if ((paymentRecord === null || paymentRecord === void 0 ? void 0 : paymentRecord.status) !== 'paid') return sum;
1274
1294
  var isDepositPayment = paymentRecord.type === 'deposit' || paymentRecord.order_payment_type === 'deposit';
1275
1295
  if (!isDepositPayment) return sum;
1276
1296
  if (paymentRecord.origin_amount !== undefined && paymentRecord.origin_amount !== null && paymentRecord.origin_amount !== '') {
1277
- return sum.plus(_this4.calculatePaymentGapAmount(paymentRecord));
1297
+ return sum.plus(_this5.calculatePaymentGapAmount(paymentRecord));
1278
1298
  }
1279
1299
  var rounding = new Decimal(paymentRecord.rounding_amount || 0);
1280
1300
  return sum.plus(new Decimal(paymentRecord.amount || 0).minus(rounding));
@@ -1419,16 +1439,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1419
1439
  }, {
1420
1440
  key: "calculatePaidPaymentSummary",
1421
1441
  value: function calculatePaidPaymentSummary(payments) {
1422
- var _this5 = this;
1442
+ var _this6 = this;
1423
1443
  return (payments || []).reduce(function (summary, payment) {
1424
1444
  var paymentRecord = payment;
1425
1445
  if ((paymentRecord === null || paymentRecord === void 0 ? void 0 : paymentRecord.status) !== 'paid') return summary;
1426
1446
  return {
1427
1447
  customerPaidAmount: summary.customerPaidAmount.plus(paymentRecord.amount || 0),
1428
1448
  orderPaidAmount: summary.orderPaidAmount.plus(paymentRecord.origin_amount || 0),
1429
- gapPaidAmount: summary.gapPaidAmount.plus(_this5.calculatePaymentGapAmount(paymentRecord)),
1430
- payServiceChargeAmount: summary.payServiceChargeAmount.plus(_this5.calculatePaymentServiceFee(paymentRecord)),
1431
- roundingAmount: summary.roundingAmount.plus(_this5.calculatePaymentRoundingAmount(paymentRecord))
1449
+ gapPaidAmount: summary.gapPaidAmount.plus(_this6.calculatePaymentGapAmount(paymentRecord)),
1450
+ payServiceChargeAmount: summary.payServiceChargeAmount.plus(_this6.calculatePaymentServiceFee(paymentRecord)),
1451
+ roundingAmount: summary.roundingAmount.plus(_this6.calculatePaymentRoundingAmount(paymentRecord))
1432
1452
  };
1433
1453
  }, {
1434
1454
  customerPaidAmount: new Decimal(0),
@@ -1613,15 +1633,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1613
1633
  }, {
1614
1634
  key: "normalizeFingerprintValue",
1615
1635
  value: function normalizeFingerprintValue(value) {
1616
- var _this6 = this;
1636
+ var _this7 = this;
1617
1637
  if (Array.isArray(value)) {
1618
1638
  return value.map(function (item) {
1619
- return _this6.normalizeFingerprintValue(item);
1639
+ return _this7.normalizeFingerprintValue(item);
1620
1640
  });
1621
1641
  }
1622
1642
  if (!value || _typeof(value) !== 'object') return value !== null && value !== void 0 ? value : '';
1623
1643
  return Object.keys(value).sort().reduce(function (result, key) {
1624
- result[key] = _this6.normalizeFingerprintValue(value[key]);
1644
+ result[key] = _this7.normalizeFingerprintValue(value[key]);
1625
1645
  return result;
1626
1646
  }, {});
1627
1647
  }
@@ -1636,7 +1656,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1636
1656
  _sku$barcode,
1637
1657
  _ref18,
1638
1658
  _sku$variant_id,
1639
- _this7 = this;
1659
+ _this8 = this;
1640
1660
  var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
1641
1661
  var metadata = (product === null || product === void 0 ? void 0 : product.metadata) || {};
1642
1662
  var discountTypes = ((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
@@ -1670,7 +1690,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1670
1690
  option_group_id: (_option$option_group_ = option === null || option === void 0 ? void 0 : option.option_group_id) !== null && _option$option_group_ !== void 0 ? _option$option_group_ : null,
1671
1691
  option_group_item_id: (_ref20 = (_option$option_group_2 = option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _option$option_group_2 !== void 0 ? _option$option_group_2 : option === null || option === void 0 ? void 0 : option.id) !== null && _ref20 !== void 0 ? _ref20 : null,
1672
1692
  num: Number((_option$num = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num !== void 0 ? _option$num : 1) || 1,
1673
- add_price: _this7.normalizeFingerprintMoney((_option$add_price = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price !== void 0 ? _option$add_price : option === null || option === void 0 ? void 0 : option.price)
1693
+ add_price: _this8.normalizeFingerprintMoney((_option$add_price = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price !== void 0 ? _option$add_price : option === null || option === void 0 ? void 0 : option.price)
1674
1694
  };
1675
1695
  })
1676
1696
  }),
@@ -1680,8 +1700,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1680
1700
  bundle_product_id: (_ref21 = (_ref22 = (_bundle$bundle_produc = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle === null || bundle === void 0 ? void 0 : bundle._bundle_product_id) !== null && _ref22 !== void 0 ? _ref22 : bundle === null || bundle === void 0 ? void 0 : bundle.product_id) !== null && _ref21 !== void 0 ? _ref21 : null,
1681
1701
  bundle_variant_id: (_ref23 = (_bundle$bundle_varian = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_variant_id) !== null && _bundle$bundle_varian !== void 0 ? _bundle$bundle_varian : bundle === null || bundle === void 0 ? void 0 : bundle.product_variant_id) !== null && _ref23 !== void 0 ? _ref23 : 0,
1682
1702
  num: getSafeProductNum((_bundle$num = bundle === null || bundle === void 0 ? void 0 : bundle.num) !== null && _bundle$num !== void 0 ? _bundle$num : bundle === null || bundle === void 0 ? void 0 : bundle.quantity),
1683
- price: _this7.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.price),
1684
- bundle_selling_price: _this7.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.bundle_selling_price),
1703
+ price: _this8.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.price),
1704
+ bundle_selling_price: _this8.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.bundle_selling_price),
1685
1705
  price_type: (_bundle$price_type = bundle === null || bundle === void 0 ? void 0 : bundle.price_type) !== null && _bundle$price_type !== void 0 ? _bundle$price_type : '',
1686
1706
  price_type_ext: (_bundle$price_type_ex = bundle === null || bundle === void 0 ? void 0 : bundle.price_type_ext) !== null && _bundle$price_type_ex !== void 0 ? _bundle$price_type_ex : ''
1687
1707
  };
@@ -1691,7 +1711,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1691
1711
  return {
1692
1712
  type: (_ref24 = (_discount$type2 = discount === null || discount === void 0 ? void 0 : discount.type) !== null && _discount$type2 !== void 0 ? _discount$type2 : discount === null || discount === void 0 ? void 0 : discount.tag) !== null && _ref24 !== void 0 ? _ref24 : '',
1693
1713
  discount_id: (_ref25 = (_ref26 = (_discount$discount_id = discount === null || discount === void 0 ? void 0 : discount.discount_id) !== null && _discount$discount_id !== void 0 ? _discount$discount_id : discount === null || discount === void 0 ? void 0 : discount.order_discount_id) !== null && _ref26 !== void 0 ? _ref26 : discount === null || discount === void 0 || (_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) !== null && _ref25 !== void 0 ? _ref25 : null,
1694
- amount: _this7.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
1714
+ amount: _this8.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
1695
1715
  };
1696
1716
  }))
1697
1717
  };
@@ -1699,9 +1719,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1699
1719
  }, {
1700
1720
  key: "buildOrderProductsFingerprint",
1701
1721
  value: function buildOrderProductsFingerprint(products) {
1702
- var _this8 = this;
1722
+ var _this9 = this;
1703
1723
  var items = (products || []).map(function (product) {
1704
- return _this8.buildProductFingerprintItem(product);
1724
+ return _this9.buildProductFingerprintItem(product);
1705
1725
  });
1706
1726
  items.sort(function (left, right) {
1707
1727
  return JSON.stringify(left).localeCompare(JSON.stringify(right));
@@ -1723,7 +1743,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1723
1743
  _sku$barcode2,
1724
1744
  _ref28,
1725
1745
  _sku$variant_id2,
1726
- _this9 = this;
1746
+ _this10 = this;
1727
1747
  var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
1728
1748
  var metadata = (product === null || product === void 0 ? void 0 : product.metadata) || {};
1729
1749
  var discountTypes = ((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
@@ -1754,7 +1774,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1754
1774
  option_group_id: (_option$option_group_3 = option === null || option === void 0 ? void 0 : option.option_group_id) !== null && _option$option_group_3 !== void 0 ? _option$option_group_3 : null,
1755
1775
  option_group_item_id: (_ref30 = (_option$option_group_4 = option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _option$option_group_4 !== void 0 ? _option$option_group_4 : option === null || option === void 0 ? void 0 : option.id) !== null && _ref30 !== void 0 ? _ref30 : null,
1756
1776
  num: Number((_option$num2 = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num2 !== void 0 ? _option$num2 : 1) || 1,
1757
- add_price: _this9.normalizeFingerprintMoney((_option$add_price2 = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price2 !== void 0 ? _option$add_price2 : option === null || option === void 0 ? void 0 : option.price)
1777
+ add_price: _this10.normalizeFingerprintMoney((_option$add_price2 = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price2 !== void 0 ? _option$add_price2 : option === null || option === void 0 ? void 0 : option.price)
1758
1778
  };
1759
1779
  })
1760
1780
  }),
@@ -1768,14 +1788,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1768
1788
  num: getSafeProductNum((_bundle$num2 = bundle === null || bundle === void 0 ? void 0 : bundle.num) !== null && _bundle$num2 !== void 0 ? _bundle$num2 : bundle === null || bundle === void 0 ? void 0 : bundle.quantity),
1769
1789
  price_type: (_bundle$price_type2 = bundle === null || bundle === void 0 ? void 0 : bundle.price_type) !== null && _bundle$price_type2 !== void 0 ? _bundle$price_type2 : '',
1770
1790
  price_type_ext: (_bundle$price_type_ex2 = bundle === null || bundle === void 0 ? void 0 : bundle.price_type_ext) !== null && _bundle$price_type_ex2 !== void 0 ? _bundle$price_type_ex2 : '',
1771
- option: _this9.normalizeFingerprintValue(((bundle === null || bundle === void 0 ? void 0 : bundle.option) || []).map(function (option) {
1791
+ option: _this10.normalizeFingerprintValue(((bundle === null || bundle === void 0 ? void 0 : bundle.option) || []).map(function (option) {
1772
1792
  var _ref36, _option$id3, _option$option_group_5, _ref37, _option$option_group_6, _option$num3, _option$add_price3;
1773
1793
  return {
1774
1794
  id: (_ref36 = (_option$id3 = option === null || option === void 0 ? void 0 : option.id) !== null && _option$id3 !== void 0 ? _option$id3 : option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _ref36 !== void 0 ? _ref36 : null,
1775
1795
  option_group_id: (_option$option_group_5 = option === null || option === void 0 ? void 0 : option.option_group_id) !== null && _option$option_group_5 !== void 0 ? _option$option_group_5 : null,
1776
1796
  option_group_item_id: (_ref37 = (_option$option_group_6 = option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _option$option_group_6 !== void 0 ? _option$option_group_6 : option === null || option === void 0 ? void 0 : option.id) !== null && _ref37 !== void 0 ? _ref37 : null,
1777
1797
  num: Number((_option$num3 = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num3 !== void 0 ? _option$num3 : 1) || 1,
1778
- add_price: _this9.normalizeFingerprintMoney((_option$add_price3 = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price3 !== void 0 ? _option$add_price3 : option === null || option === void 0 ? void 0 : option.price)
1798
+ add_price: _this10.normalizeFingerprintMoney((_option$add_price3 = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price3 !== void 0 ? _option$add_price3 : option === null || option === void 0 ? void 0 : option.price)
1779
1799
  };
1780
1800
  }))
1781
1801
  };
@@ -1785,7 +1805,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1785
1805
  return {
1786
1806
  type: (_ref38 = (_discount$type4 = discount === null || discount === void 0 ? void 0 : discount.type) !== null && _discount$type4 !== void 0 ? _discount$type4 : discount === null || discount === void 0 ? void 0 : discount.tag) !== null && _ref38 !== void 0 ? _ref38 : '',
1787
1807
  discount_id: (_ref39 = (_ref40 = (_discount$discount_id2 = discount === null || discount === void 0 ? void 0 : discount.discount_id) !== null && _discount$discount_id2 !== void 0 ? _discount$discount_id2 : discount === null || discount === void 0 ? void 0 : discount.order_discount_id) !== null && _ref40 !== void 0 ? _ref40 : discount === null || discount === void 0 || (_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.resource_id) !== null && _ref39 !== void 0 ? _ref39 : null,
1788
- amount: _this9.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
1808
+ amount: _this10.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
1789
1809
  };
1790
1810
  }))
1791
1811
  };
@@ -1793,9 +1813,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1793
1813
  }, {
1794
1814
  key: "buildOrderProductsStructuralFingerprint",
1795
1815
  value: function buildOrderProductsStructuralFingerprint(products) {
1796
- var _this10 = this;
1816
+ var _this11 = this;
1797
1817
  var items = (products || []).map(function (product) {
1798
- return _this10.buildProductStructuralFingerprintItem(product);
1818
+ return _this11.buildProductStructuralFingerprintItem(product);
1799
1819
  });
1800
1820
  items.sort(function (left, right) {
1801
1821
  return JSON.stringify(left).localeCompare(JSON.stringify(right));
@@ -2200,9 +2220,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2200
2220
  }, {
2201
2221
  key: "sanitizeTempOrderProducts",
2202
2222
  value: function sanitizeTempOrderProducts(tempOrder) {
2203
- var _this11 = this;
2223
+ var _this12 = this;
2204
2224
  tempOrder.products = (tempOrder.products || []).map(function (product) {
2205
- return _this11.sanitizeOrderProductForTempOrder(product);
2225
+ return _this12.sanitizeOrderProductForTempOrder(product);
2206
2226
  });
2207
2227
  }
2208
2228
  }, {
@@ -2415,9 +2435,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2415
2435
  }, {
2416
2436
  key: "findBookingIndexByUniqueIdentificationNumber",
2417
2437
  value: function findBookingIndexByUniqueIdentificationNumber(tempOrder, uniqueIdentificationNumber) {
2418
- var _this12 = this;
2438
+ var _this13 = this;
2419
2439
  return (tempOrder.bookings || []).findIndex(function (booking) {
2420
- return _this12.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
2440
+ return _this13.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
2421
2441
  });
2422
2442
  }
2423
2443
  }, {
@@ -2425,12 +2445,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2425
2445
  value: function removeLinkedBookingsForProduct(tempOrder, product) {
2426
2446
  var _product$metadata5,
2427
2447
  _product$metadata6,
2428
- _this13 = this;
2448
+ _this14 = this;
2429
2449
  var productUid = (product === null || product === void 0 || (_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
2430
2450
  var bookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.booking_uid);
2431
2451
  if (!productUid && !bookingUid) return;
2432
2452
  tempOrder.bookings = (tempOrder.bookings || []).filter(function (booking) {
2433
- var currentBookingUid = _this13.getBookingUniqueIdentificationNumber(booking);
2453
+ var currentBookingUid = _this14.getBookingUniqueIdentificationNumber(booking);
2434
2454
  if (bookingUid && currentBookingUid === String(bookingUid)) return false;
2435
2455
  if (productUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) return false;
2436
2456
  return true;
@@ -2749,18 +2769,49 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2749
2769
  var type = (_discount$type5 = discount === null || discount === void 0 ? void 0 : discount.type) !== null && _discount$type5 !== void 0 ? _discount$type5 : discount === null || discount === void 0 ? void 0 : discount.tag;
2750
2770
  return type === 'good_pass' || type === 'discount_card' || type === 'product_discount_card';
2751
2771
  }
2772
+ }, {
2773
+ key: "productHasCustomerBoundDiscount",
2774
+ value: function productHasCustomerBoundDiscount(product) {
2775
+ var _this15 = this;
2776
+ if (((product === null || product === void 0 ? void 0 : product.discount_list) || []).some(function (discount) {
2777
+ return _this15.isCustomerBoundDiscount(discount);
2778
+ })) {
2779
+ return true;
2780
+ }
2781
+ return ((product === null || product === void 0 ? void 0 : product.product_bundle) || []).some(function (bundle) {
2782
+ return ((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []).some(function (discount) {
2783
+ return _this15.isCustomerBoundDiscount(discount);
2784
+ });
2785
+ });
2786
+ }
2787
+ }, {
2788
+ key: "shouldSkipDiscountCalculation",
2789
+ value: function shouldSkipDiscountCalculation(tempOrder) {
2790
+ var _this$store$discount13,
2791
+ _this$store$discount14,
2792
+ _this16 = this;
2793
+ if (this.hasActiveCustomerBoundDiscount) return false;
2794
+ var discountList = ((_this$store$discount13 = this.store.discount) === null || _this$store$discount13 === void 0 || (_this$store$discount14 = _this$store$discount13.getDiscountList) === null || _this$store$discount14 === void 0 ? void 0 : _this$store$discount14.call(_this$store$discount13)) || [];
2795
+ if (discountList.length > 0) return false;
2796
+ return !(tempOrder.products || []).some(function (product) {
2797
+ return _this16.productHasCustomerBoundDiscount(product);
2798
+ });
2799
+ }
2752
2800
  }, {
2753
2801
  key: "clearCustomerBoundDiscounts",
2754
2802
  value: function clearCustomerBoundDiscounts(tempOrder) {
2755
- var _this14 = this,
2803
+ var _this17 = this,
2756
2804
  _discountModule$getDi,
2757
2805
  _discountModule$getOr,
2758
2806
  _discountModule$setDi,
2759
2807
  _discountModule$setOr;
2808
+ var didRemoveCustomerBoundDiscount = false;
2760
2809
  var filterDiscountList = function filterDiscountList(discountList) {
2761
2810
  if (!Array.isArray(discountList)) return [];
2762
2811
  return discountList.filter(function (discount) {
2763
- return !_this14.isCustomerBoundDiscount(discount);
2812
+ var shouldRemove = _this17.isCustomerBoundDiscount(discount);
2813
+ if (shouldRemove) didRemoveCustomerBoundDiscount = true;
2814
+ return !shouldRemove;
2764
2815
  });
2765
2816
  };
2766
2817
  tempOrder.products = (tempOrder.products || []).map(function (product) {
@@ -2777,17 +2828,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2777
2828
  return nextProduct;
2778
2829
  });
2779
2830
  delete tempOrder.discount_list;
2831
+ if (didRemoveCustomerBoundDiscount) {
2832
+ this.hasActiveCustomerBoundDiscount = true;
2833
+ }
2780
2834
  var discountModule = this.store.discount;
2781
2835
  if (!discountModule) return;
2782
2836
  var currentDiscounts = ((_discountModule$getDi = discountModule.getDiscountList) === null || _discountModule$getDi === void 0 ? void 0 : _discountModule$getDi.call(discountModule)) || [];
2783
2837
  var currentOriginalDiscounts = ((_discountModule$getOr = discountModule.getOriginalDiscountList) === null || _discountModule$getOr === void 0 ? void 0 : _discountModule$getOr.call(discountModule)) || [];
2784
2838
  var nextDiscounts = currentDiscounts.filter(function (discount) {
2785
2839
  if (discount !== null && discount !== void 0 && discount.isEditMode) return true;
2786
- return !_this14.isCustomerBoundDiscount(discount);
2840
+ return !_this17.isCustomerBoundDiscount(discount);
2787
2841
  });
2788
2842
  var nextOriginalDiscounts = currentOriginalDiscounts.filter(function (discount) {
2789
2843
  if (discount !== null && discount !== void 0 && discount.isEditMode) return true;
2790
- return !_this14.isCustomerBoundDiscount(discount);
2844
+ return !_this17.isCustomerBoundDiscount(discount);
2791
2845
  });
2792
2846
  void ((_discountModule$setDi = discountModule.setDiscountList) === null || _discountModule$setDi === void 0 ? void 0 : _discountModule$setDi.call(discountModule, nextDiscounts));
2793
2847
  void ((_discountModule$setOr = discountModule.setOriginalDiscountList) === null || _discountModule$setOr === void 0 ? void 0 : _discountModule$setOr.call(discountModule, nextOriginalDiscounts));
@@ -2954,7 +3008,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2954
3008
  }, {
2955
3009
  key: "addOrderPayment",
2956
3010
  value: function addOrderPayment(payment) {
2957
- var _this15 = this;
3011
+ var _this18 = this;
2958
3012
  this.logInfo('addOrderPayment', {
2959
3013
  payment: payment
2960
3014
  });
@@ -2971,7 +3025,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2971
3025
  void this.recalculateSummary({
2972
3026
  createIfMissing: true
2973
3027
  }).catch(function (error) {
2974
- _this15.logError('recalculate summary after addOrderPayment failed', {
3028
+ _this18.logError('recalculate summary after addOrderPayment failed', {
2975
3029
  error: error instanceof Error ? error.message : String(error)
2976
3030
  });
2977
3031
  });
@@ -3036,7 +3090,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3036
3090
  }, {
3037
3091
  key: "updateVoucherOrderPayments",
3038
3092
  value: function updateVoucherOrderPayments(payments) {
3039
- var _this16 = this;
3093
+ var _this19 = this;
3040
3094
  var tempOrder = this.ensureTempOrder();
3041
3095
  var isVoucherPayment = function isVoucherPayment(payment) {
3042
3096
  return payment.voucher_id !== undefined && Number(payment.voucher_id) !== 0;
@@ -3057,7 +3111,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3057
3111
  // return paymentRecord
3058
3112
  // };
3059
3113
  var mappedVouchers = mapPaymentItemsToOrderPayments(payments.map(function (payment) {
3060
- return _this16.normalizePaymentSource(payment, {
3114
+ return _this19.normalizePaymentSource(payment, {
3061
3115
  defaultPaid: true
3062
3116
  });
3063
3117
  })).filter(function (payment) {
@@ -3086,7 +3140,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3086
3140
  void this.recalculateSummary({
3087
3141
  createIfMissing: true
3088
3142
  }).catch(function (error) {
3089
- _this16.logError('recalculate summary after updateVoucherOrderPayments failed', {
3143
+ _this19.logError('recalculate summary after updateVoucherOrderPayments failed', {
3090
3144
  error: error instanceof Error ? error.message : String(error)
3091
3145
  });
3092
3146
  });
@@ -3222,7 +3276,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3222
3276
  var _appendProductLineToTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(tempOrder, product, booking) {
3223
3277
  var _booking_uid,
3224
3278
  _metadata,
3225
- _this17 = this;
3279
+ _this20 = this;
3226
3280
  var linked, productToAdd, incomingFingerprint, normalizedIncoming, incomingBookingUid, hasIncomingGoodPass, hasIncomingProductNote, hasIncomingBookingUid, shouldForceNewLine, matchedIndex, matchedProduct, existedFingerprint, shouldMerge, _targetProduct$metada, targetProduct, targetUid, normalizedProduct, nextNum, targetIsManualProductDiscount, nextDiscountList;
3227
3281
  return _regeneratorRuntime().wrap(function _callee16$(_context18) {
3228
3282
  while (1) switch (_context18.prev = _context18.next) {
@@ -3247,8 +3301,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3247
3301
  hasIncomingBookingUid = this.hasLinkedBookingUid(productToAdd) || this.hasLinkedBookingUid(normalizedIncoming);
3248
3302
  shouldForceNewLine = !!booking || hasIncomingProductNote || hasIncomingBookingUid;
3249
3303
  matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex(function (item) {
3250
- if (_this17.hasGoodPassDiscount(item)) return false;
3251
- if (_this17.hasOrderProductLineNote(item)) return false;
3304
+ if (_this20.hasGoodPassDiscount(item)) return false;
3305
+ if (_this20.hasOrderProductLineNote(item)) return false;
3252
3306
  if (item.order_detail_id !== undefined && item.order_detail_id !== null) return false;
3253
3307
  if (item.product_id !== productToAdd.product_id) return false;
3254
3308
  if (item.product_variant_id !== productToAdd.product_variant_id) return false;
@@ -3538,17 +3592,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3538
3592
  }, {
3539
3593
  key: "preservePersistedBundlePriceFields",
3540
3594
  value: function preservePersistedBundlePriceFields(previousBundles, nextBundles) {
3541
- var _this18 = this;
3595
+ var _this21 = this;
3542
3596
  if (!Array.isArray(nextBundles)) return nextBundles;
3543
3597
  if (!Array.isArray(previousBundles) || previousBundles.length === 0) return nextBundles;
3544
3598
  var previousByIdentity = new Map();
3545
3599
  previousBundles.forEach(function (bundle) {
3546
- var identity = _this18.getBundleRuntimeIdentity(bundle);
3600
+ var identity = _this21.getBundleRuntimeIdentity(bundle);
3547
3601
  if (identity) previousByIdentity.set(identity, bundle);
3548
3602
  });
3549
3603
  return nextBundles.map(function (bundle, index) {
3550
3604
  if (!bundle || _typeof(bundle) !== 'object') return bundle;
3551
- var previous = previousByIdentity.get(_this18.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
3605
+ var previous = previousByIdentity.get(_this21.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
3552
3606
  if (!previous || _typeof(previous) !== 'object') return bundle;
3553
3607
  return _objectSpread(_objectSpread({}, bundle), {}, {
3554
3608
  price: previous.price,
@@ -3864,7 +3918,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3864
3918
  key: "removeProductsFromOrder",
3865
3919
  value: (function () {
3866
3920
  var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(identities) {
3867
- var _this19 = this;
3921
+ var _this22 = this;
3868
3922
  var tempOrder, productsBeforeRemove, bookingsBeforeRemove, matchedProducts, removedProducts, _i2, _removedProducts, product, linkedBookingUidsToRemove, _iterator21, _step21, _loop3;
3869
3923
  return _regeneratorRuntime().wrap(function _callee22$(_context25) {
3870
3924
  while (1) switch (_context25.prev = _context25.next) {
@@ -3919,7 +3973,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3919
3973
  }
3920
3974
  if (productUid !== undefined && productUid !== null && productUid !== '') {
3921
3975
  bookingsBeforeRemove.forEach(function (booking) {
3922
- var bookingUid = _this19.getBookingUniqueIdentificationNumber(booking);
3976
+ var bookingUid = _this22.getBookingUniqueIdentificationNumber(booking);
3923
3977
  if (bookingUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) {
3924
3978
  linkedBookingUidsToRemove.add(bookingUid);
3925
3979
  }
@@ -4375,10 +4429,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4375
4429
  value: function extractSubmitErrorResponse(error) {
4376
4430
  var _error$response,
4377
4431
  _error$response2,
4378
- _this20 = this;
4432
+ _this23 = this;
4379
4433
  var candidates = [error === null || error === void 0 || (_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.data, error === null || error === void 0 ? void 0 : error.data, error === null || error === void 0 || (_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.body, error === null || error === void 0 ? void 0 : error.body];
4380
4434
  return candidates.find(function (candidate) {
4381
- return _this20.isSubmitErrorResponse(candidate);
4435
+ return _this23.isSubmitErrorResponse(candidate);
4382
4436
  }) || null;
4383
4437
  }
4384
4438
  }, {
@@ -4944,8 +4998,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4944
4998
  key: "hydrateTempOrderFromRecord",
4945
4999
  value: (function () {
4946
5000
  var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(record, options) {
4947
- var _this$store$discount13;
4948
- var raw, nextTempOrder, rawSummary, summarySurcharges, hydratedEditDiscounts, currentDiscounts, shouldSkipEmptyDiscountSync, _this$store$discount14, _this$store$discount15;
5001
+ var _this$store$discount15;
5002
+ var raw, nextTempOrder, rawSummary, summarySurcharges, hydratedEditDiscounts, currentDiscounts, shouldSkipEmptyDiscountSync, _this$store$discount16, _this$store$discount17;
4949
5003
  return _regeneratorRuntime().wrap(function _callee38$(_context41) {
4950
5004
  while (1) switch (_context41.prev = _context41.next) {
4951
5005
  case 0:
@@ -4970,17 +5024,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4970
5024
  });
4971
5025
  this.store.lastOrderInfo = raw.lastOrderInfo || raw;
4972
5026
  hydratedEditDiscounts = this.collectHydratedEditDiscounts(nextTempOrder.products);
4973
- currentDiscounts = typeof ((_this$store$discount13 = this.store.discount) === null || _this$store$discount13 === void 0 ? void 0 : _this$store$discount13.getDiscountList) === 'function' ? this.store.discount.getDiscountList() || [] : [];
5027
+ currentDiscounts = typeof ((_this$store$discount15 = this.store.discount) === null || _this$store$discount15 === void 0 ? void 0 : _this$store$discount15.getDiscountList) === 'function' ? this.store.discount.getDiscountList() || [] : [];
4974
5028
  shouldSkipEmptyDiscountSync = hydratedEditDiscounts.length === 0 && currentDiscounts.length === 0;
4975
5029
  if (shouldSkipEmptyDiscountSync) {
4976
5030
  _context41.next = 16;
4977
5031
  break;
4978
5032
  }
4979
5033
  _context41.next = 14;
4980
- return (_this$store$discount14 = this.store.discount) === null || _this$store$discount14 === void 0 ? void 0 : _this$store$discount14.setOriginalDiscountList(hydratedEditDiscounts);
5034
+ return (_this$store$discount16 = this.store.discount) === null || _this$store$discount16 === void 0 ? void 0 : _this$store$discount16.setOriginalDiscountList(hydratedEditDiscounts);
4981
5035
  case 14:
4982
5036
  _context41.next = 16;
4983
- return (_this$store$discount15 = this.store.discount) === null || _this$store$discount15 === void 0 ? void 0 : _this$store$discount15.setDiscountList(hydratedEditDiscounts);
5037
+ return (_this$store$discount17 = this.store.discount) === null || _this$store$discount17 === void 0 ? void 0 : _this$store$discount17.setDiscountList(hydratedEditDiscounts);
4984
5038
  case 16:
4985
5039
  if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
4986
5040
  _context41.next = 19;
@@ -5007,7 +5061,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5007
5061
  }, {
5008
5062
  key: "normalizeTempOrderForRuntime",
5009
5063
  value: function normalizeTempOrderForRuntime(raw, options) {
5010
- var _this21 = this;
5064
+ var _this24 = this;
5011
5065
  var nextTempOrder = _objectSpread(_objectSpread({}, this.createDefaultTempOrderInstance()), raw || {});
5012
5066
  delete nextTempOrder.summary;
5013
5067
  delete nextTempOrder.lastOrderInfo;
@@ -5026,7 +5080,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5026
5080
  nextTempOrder.holder = raw.holder && _typeof(raw.holder) === 'object' ? _objectSpread({}, raw.holder) : null;
5027
5081
  var rawProducts = Array.isArray(raw.products) ? raw.products : [];
5028
5082
  nextTempOrder.products = rawProducts.length > 0 ? rawProducts.map(function (p) {
5029
- return _this21.normalizeHydratedOrderProduct(p);
5083
+ return _this24.normalizeHydratedOrderProduct(p);
5030
5084
  }) : [];
5031
5085
  nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map(function (b) {
5032
5086
  return _objectSpread(_objectSpread({}, b || {}), {}, {
@@ -5087,12 +5141,54 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5087
5141
  _iterator22.f();
5088
5142
  }
5089
5143
  tempOrderExtend.productsByUid = productsByUid;
5144
+ this.hydrateLinkedBookingIdentity(nextTempOrder);
5090
5145
  if ((options === null || options === void 0 ? void 0 : options.ensureIdentity) !== false) {
5091
5146
  this.ensureExternalSaleNumber(nextTempOrder);
5092
5147
  }
5093
5148
  nextTempOrder.vouchers = raw.vouchers || [];
5094
5149
  return nextTempOrder;
5095
5150
  }
5151
+ }, {
5152
+ key: "hydrateLinkedBookingIdentity",
5153
+ value: function hydrateLinkedBookingIdentity(tempOrder) {
5154
+ var bookingUidByProductUid = new Map();
5155
+ var productByUid = new Map();
5156
+ (tempOrder.products || []).forEach(function (product) {
5157
+ var _product$metadata9;
5158
+ var productUid = (product === null || product === void 0 || (_product$metadata9 = product.metadata) === null || _product$metadata9 === void 0 ? void 0 : _product$metadata9.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
5159
+ if (productUid !== undefined && productUid !== null && String(productUid) !== '') {
5160
+ productByUid.set(String(productUid), product);
5161
+ }
5162
+ });
5163
+ (tempOrder.bookings || []).forEach(function (booking) {
5164
+ var _matchedProduct$metad;
5165
+ if (!booking || _typeof(booking) !== 'object') return;
5166
+ if (!booking.metadata || _typeof(booking.metadata) !== 'object') {
5167
+ booking.metadata = {};
5168
+ }
5169
+ var productUid = booking.product_uid || booking.metadata.product_uid;
5170
+ if (productUid === undefined || productUid === null || String(productUid) === '') return;
5171
+ var matchedProduct = productByUid.get(String(productUid));
5172
+ var existedProductBookingUid = (matchedProduct === null || matchedProduct === void 0 ? void 0 : matchedProduct.booking_uid) || (matchedProduct === null || matchedProduct === void 0 || (_matchedProduct$metad = matchedProduct.metadata) === null || _matchedProduct$metad === void 0 ? void 0 : _matchedProduct$metad.booking_uid);
5173
+ // 客户端订单详情可能缺少 booking 自身 uid,这里补齐后才能反写到商品行。
5174
+ var bookingUid = String(booking.metadata.unique_identification_number || existedProductBookingUid || createUuidV4());
5175
+ booking.metadata.unique_identification_number = bookingUid;
5176
+ bookingUidByProductUid.set(String(productUid), bookingUid);
5177
+ });
5178
+ (tempOrder.products || []).forEach(function (product) {
5179
+ var _product$metadata10;
5180
+ var productUid = (product === null || product === void 0 || (_product$metadata10 = product.metadata) === null || _product$metadata10 === void 0 ? void 0 : _product$metadata10.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
5181
+ if (productUid === undefined || productUid === null || String(productUid) === '') return;
5182
+ var bookingUid = bookingUidByProductUid.get(String(productUid));
5183
+ if (!bookingUid) return;
5184
+ if (!product.metadata || _typeof(product.metadata) !== 'object') {
5185
+ product.metadata = {};
5186
+ }
5187
+ var linkedBookingUid = String(product.booking_uid || product.metadata.booking_uid || bookingUid);
5188
+ product.booking_uid = linkedBookingUid;
5189
+ product.metadata.booking_uid = linkedBookingUid;
5190
+ });
5191
+ }
5096
5192
  }, {
5097
5193
  key: "pickHydratedDisplayText",
5098
5194
  value: function pickHydratedDisplayText(value) {
@@ -5154,7 +5250,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5154
5250
  }, {
5155
5251
  key: "normalizeHydratedOrderProduct",
5156
5252
  value: function normalizeHydratedOrderProduct(product) {
5157
- var _this22 = this;
5253
+ var _this25 = this;
5158
5254
  var row = _objectSpread({}, product || {});
5159
5255
  if (row.num === undefined && row.product_quantity !== undefined) {
5160
5256
  row.num = row.product_quantity;
@@ -5162,7 +5258,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5162
5258
  var productSku = ensureProductSku(row);
5163
5259
  row.product_sku = _objectSpread(_objectSpread({}, productSku), {}, {
5164
5260
  option: normalizeProductSkuOptions(productSku.option.map(function (optionItem) {
5165
- return _this22.normalizeHydratedProductOptionItem(optionItem || {});
5261
+ return _this25.normalizeHydratedProductOptionItem(optionItem || {});
5166
5262
  }))
5167
5263
  });
5168
5264
  delete row["product_".concat('option', "_item")];
@@ -5220,13 +5316,26 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5220
5316
  key: "populateSavedAmounts",
5221
5317
  value: function populateSavedAmounts(productList, discountList) {
5222
5318
  var savedMap = new Map();
5223
- var addDiscountAmount = function addDiscountAmount(discount, quantity) {
5319
+ var editModeSavedMap = new Map();
5320
+ var runtimeSavedMap = new Map();
5321
+ var editModeDiscountKeys = new Set((discountList || []).filter(function (discount) {
5322
+ return discount === null || discount === void 0 ? void 0 : discount.isEditMode;
5323
+ }).map(function (discount) {
5324
+ return discount === null || discount === void 0 ? void 0 : discount.id;
5325
+ }).filter(function (id) {
5326
+ return id !== undefined && id !== null;
5327
+ }));
5328
+ var addDiscountAmount = function addDiscountAmount(targetMap, discountKey, amount) {
5329
+ targetMap.set(discountKey, (targetMap.get(discountKey) || new Decimal(0)).plus(amount));
5330
+ };
5331
+ var addProductDiscountAmount = function addProductDiscountAmount(discount, quantity, isPersistedProduct) {
5224
5332
  var _discount$discount3, _discount$metadata;
5225
5333
  var discountKey = ((_discount$discount3 = discount.discount) === null || _discount$discount3 === void 0 ? void 0 : _discount$discount3.resource_id) || discount.id;
5226
5334
  if (discountKey == null) return;
5227
5335
  var qty = Number(quantity) || 1;
5228
5336
  var amount = new Decimal(discount.amount || 0).times(qty).plus(((_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata.product_discount_difference) || 0);
5229
- savedMap.set(discountKey, (savedMap.get(discountKey) || new Decimal(0)).plus(amount));
5337
+ addDiscountAmount(savedMap, discountKey, amount);
5338
+ addDiscountAmount(isPersistedProduct || discount.order_discount_id != null ? editModeSavedMap : runtimeSavedMap, discountKey, amount);
5230
5339
  };
5231
5340
  var _iterator24 = _createForOfIteratorHelper(productList),
5232
5341
  _step24;
@@ -5234,12 +5343,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5234
5343
  for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
5235
5344
  var product = _step24.value;
5236
5345
  var qty = product.num || 1;
5346
+ var isPersistedProduct = Boolean(product.order_detail_id || product.orderDetailId || product.booking_id);
5237
5347
  var _iterator26 = _createForOfIteratorHelper(product.discount_list || []),
5238
5348
  _step26;
5239
5349
  try {
5240
5350
  for (_iterator26.s(); !(_step26 = _iterator26.n()).done;) {
5241
5351
  var pd = _step26.value;
5242
- addDiscountAmount(pd, qty);
5352
+ addProductDiscountAmount(pd, qty, isPersistedProduct);
5243
5353
  }
5244
5354
  } catch (err) {
5245
5355
  _iterator26.e(err);
@@ -5252,13 +5362,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5252
5362
  for (_iterator27.s(); !(_step27 = _iterator27.n()).done;) {
5253
5363
  var _ref75, _bundle$num3;
5254
5364
  var bundle = _step27.value;
5365
+ var isPersistedBundleProduct = isPersistedProduct || Boolean((bundle === null || bundle === void 0 ? void 0 : bundle.order_detail_id) || (bundle === null || bundle === void 0 ? void 0 : bundle.orderDetailId) || (bundle === null || bundle === void 0 ? void 0 : bundle.booking_id));
5255
5366
  var bundleQty = new Decimal(Number(qty) || 1).times(Number((_ref75 = (_bundle$num3 = bundle === null || bundle === void 0 ? void 0 : bundle.num) !== null && _bundle$num3 !== void 0 ? _bundle$num3 : bundle === null || bundle === void 0 ? void 0 : bundle.quantity) !== null && _ref75 !== void 0 ? _ref75 : 1) || 1).toNumber();
5256
5367
  var _iterator28 = _createForOfIteratorHelper((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []),
5257
5368
  _step28;
5258
5369
  try {
5259
5370
  for (_iterator28.s(); !(_step28 = _iterator28.n()).done;) {
5260
5371
  var _pd = _step28.value;
5261
- addDiscountAmount(_pd, bundleQty);
5372
+ addProductDiscountAmount(_pd, bundleQty, isPersistedBundleProduct);
5262
5373
  }
5263
5374
  } catch (err) {
5264
5375
  _iterator28.e(err);
@@ -5283,7 +5394,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5283
5394
  for (_iterator25.s(); !(_step25 = _iterator25.n()).done;) {
5284
5395
  var d = _step25.value;
5285
5396
  var key = d.id;
5286
- d.savedAmount = d.isSelected && key != null && savedMap.has(key) ? savedMap.get(key).toNumber() : 0;
5397
+ var sourceMap = d.isEditMode ? editModeSavedMap : editModeDiscountKeys.has(key) ? runtimeSavedMap : savedMap;
5398
+ d.savedAmount = d.isSelected && key != null && sourceMap.has(key) ? sourceMap.get(key).toNumber() : 0;
5287
5399
  }
5288
5400
  } catch (err) {
5289
5401
  _iterator25.e(err);