@pisell/pisellos 2.2.308 → 2.2.310

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 (130) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  2. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  3. package/dist/model/strategy/adapter/walletPass/evaluator.js +4 -2
  4. package/dist/modules/BookingContext/index.js +4 -4
  5. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +58 -19
  6. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +24 -12
  7. package/dist/modules/Customer/index.js +6 -3
  8. package/dist/modules/Customer/types.d.ts +2 -0
  9. package/dist/modules/Discount/availability.d.ts +7 -0
  10. package/dist/modules/Discount/availability.js +49 -0
  11. package/dist/modules/Discount/entitlementPass.d.ts +34 -0
  12. package/dist/modules/Discount/entitlementPass.js +147 -0
  13. package/dist/modules/Discount/index.d.ts +2 -2
  14. package/dist/modules/Discount/index.js +37 -151
  15. package/dist/modules/Discount/types.d.ts +36 -5
  16. package/dist/modules/OpenData/index.d.ts +1 -1
  17. package/dist/modules/OpenData/index.js +21 -12
  18. package/dist/modules/Order/index.d.ts +33 -4
  19. package/dist/modules/Order/index.js +830 -411
  20. package/dist/modules/Order/types.d.ts +17 -0
  21. package/dist/modules/Order/utils/orderCollectionIdentity.js +16 -12
  22. package/dist/modules/Order/utils/weighedProduct.d.ts +12 -0
  23. package/dist/modules/Order/utils/weighedProduct.js +94 -0
  24. package/dist/modules/Order/utils.d.ts +14 -2
  25. package/dist/modules/Order/utils.js +280 -79
  26. package/dist/modules/Payment/index.d.ts +0 -5
  27. package/dist/modules/Payment/index.js +35 -85
  28. package/dist/modules/Payment/types.d.ts +21 -1
  29. package/dist/modules/Payment/types.js +2 -0
  30. package/dist/modules/Payment/walletpass.d.ts +1 -1
  31. package/dist/modules/Payment/walletpass.js +80 -47
  32. package/dist/modules/ProductList/index.js +18 -5
  33. package/dist/modules/Rules/index.d.ts +2 -2
  34. package/dist/modules/Rules/index.js +484 -188
  35. package/dist/modules/Rules/types.d.ts +6 -0
  36. package/dist/server/index.js +8 -5
  37. package/dist/server/modules/order/index.js +6 -0
  38. package/dist/server/modules/order/types.d.ts +12 -0
  39. package/dist/server/modules/payment/index.d.ts +25 -6
  40. package/dist/server/modules/payment/index.js +660 -133
  41. package/dist/server/utils/small-ticket.d.ts +8 -5
  42. package/dist/server/utils/small-ticket.js +1269 -199
  43. package/dist/solution/BaseSales/index.d.ts +11 -2
  44. package/dist/solution/BaseSales/index.js +1463 -1173
  45. package/dist/solution/BaseSales/types.d.ts +7 -3
  46. package/dist/solution/BaseSales/utils/cartPromotion.js +141 -126
  47. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +40 -25
  48. package/dist/solution/BaseSales/utils.js +3 -2
  49. package/dist/solution/BookingTicket/index.d.ts +11 -2
  50. package/dist/solution/BookingTicket/index.js +663 -542
  51. package/dist/solution/BookingTicket/types.d.ts +5 -1
  52. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +2 -0
  53. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +338 -147
  54. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +8 -4
  55. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +6 -0
  56. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +19 -6
  57. package/dist/solution/ScanOrder/utils.js +3 -2
  58. package/dist/solution/ShopDiscount/index.d.ts +2 -0
  59. package/dist/solution/ShopDiscount/index.js +99 -42
  60. package/dist/solution/ShopDiscount/utils.d.ts +4 -2
  61. package/dist/solution/ShopDiscount/utils.js +43 -23
  62. package/dist/solution/UnifiedBookingSales/index.d.ts +2 -2
  63. package/dist/solution/UnifiedBookingSales/index.js +5 -5
  64. package/dist/utils/os-private-payload.d.ts +5 -0
  65. package/dist/utils/os-private-payload.js +17 -0
  66. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  67. package/lib/model/strategy/adapter/walletPass/evaluator.js +2 -0
  68. package/lib/modules/BookingContext/index.js +3 -3
  69. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +35 -6
  70. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +13 -6
  71. package/lib/modules/Customer/index.js +5 -1
  72. package/lib/modules/Customer/types.d.ts +2 -0
  73. package/lib/modules/Discount/availability.d.ts +7 -0
  74. package/lib/modules/Discount/availability.js +43 -0
  75. package/lib/modules/Discount/entitlementPass.d.ts +34 -0
  76. package/lib/modules/Discount/entitlementPass.js +141 -0
  77. package/lib/modules/Discount/index.d.ts +2 -2
  78. package/lib/modules/Discount/index.js +23 -129
  79. package/lib/modules/Discount/types.d.ts +36 -5
  80. package/lib/modules/OpenData/index.d.ts +1 -1
  81. package/lib/modules/OpenData/index.js +11 -2
  82. package/lib/modules/Order/index.d.ts +33 -4
  83. package/lib/modules/Order/index.js +411 -81
  84. package/lib/modules/Order/types.d.ts +17 -0
  85. package/lib/modules/Order/utils/orderCollectionIdentity.js +14 -11
  86. package/lib/modules/Order/utils/weighedProduct.d.ts +12 -0
  87. package/lib/modules/Order/utils/weighedProduct.js +89 -0
  88. package/lib/modules/Order/utils.d.ts +14 -2
  89. package/lib/modules/Order/utils.js +189 -5
  90. package/lib/modules/Payment/index.d.ts +0 -5
  91. package/lib/modules/Payment/index.js +3 -28
  92. package/lib/modules/Payment/types.d.ts +21 -1
  93. package/lib/modules/Payment/types.js +1 -0
  94. package/lib/modules/Payment/walletpass.d.ts +1 -1
  95. package/lib/modules/Payment/walletpass.js +29 -9
  96. package/lib/modules/ProductList/index.js +14 -1
  97. package/lib/modules/Rules/index.d.ts +2 -2
  98. package/lib/modules/Rules/index.js +361 -112
  99. package/lib/modules/Rules/types.d.ts +6 -0
  100. package/lib/server/index.js +8 -5
  101. package/lib/server/modules/order/index.js +6 -0
  102. package/lib/server/modules/order/types.d.ts +12 -0
  103. package/lib/server/modules/payment/index.d.ts +25 -6
  104. package/lib/server/modules/payment/index.js +350 -78
  105. package/lib/server/utils/small-ticket.d.ts +8 -5
  106. package/lib/server/utils/small-ticket.js +1009 -121
  107. package/lib/solution/BaseSales/index.d.ts +11 -2
  108. package/lib/solution/BaseSales/index.js +164 -30
  109. package/lib/solution/BaseSales/types.d.ts +7 -3
  110. package/lib/solution/BaseSales/utils/cartPromotion.js +12 -4
  111. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +24 -9
  112. package/lib/solution/BaseSales/utils.js +2 -1
  113. package/lib/solution/BookingTicket/index.d.ts +11 -2
  114. package/lib/solution/BookingTicket/index.js +103 -41
  115. package/lib/solution/BookingTicket/types.d.ts +5 -1
  116. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +2 -0
  117. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +174 -42
  118. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +8 -4
  119. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +6 -0
  120. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +11 -3
  121. package/lib/solution/ScanOrder/utils.js +2 -1
  122. package/lib/solution/ShopDiscount/index.d.ts +2 -0
  123. package/lib/solution/ShopDiscount/index.js +55 -9
  124. package/lib/solution/ShopDiscount/utils.d.ts +4 -2
  125. package/lib/solution/ShopDiscount/utils.js +42 -25
  126. package/lib/solution/UnifiedBookingSales/index.d.ts +2 -2
  127. package/lib/solution/UnifiedBookingSales/index.js +5 -5
  128. package/lib/utils/os-private-payload.d.ts +5 -0
  129. package/lib/utils/os-private-payload.js +22 -0
  130. package/package.json +1 -1
@@ -6,13 +6,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
6
6
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
7
7
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
8
8
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
9
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
10
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
11
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
12
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
13
9
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
14
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
15
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
16
10
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
17
11
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
18
12
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
@@ -25,6 +19,12 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) ===
25
19
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
26
20
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
27
21
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
22
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
23
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
24
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
25
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
26
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
27
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
28
28
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
29
29
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
30
30
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
@@ -32,21 +32,25 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
32
32
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
33
33
  import { BaseModule } from "../BaseModule";
34
34
  import { OrderHooks } from "./types";
35
- import { composeLinePrice, generateDuration, getAllDiscountList, mergeRelationForms, ensureCartItemOriginHolder, buildSubmitPayload, createDefaultTempOrder, createDefaultOrderRulesHooks, createEmptySummary, createUuidV4, formatDateTime, isTempOrder, normalizeOrderMetaList, normalizeBookingIsAll, normalizeBookingSubType, mapPaymentItemsToOrderPayments, normalizeOrderProductDiscountList, resolveEffectivePerUnitDiscount, ensureProductSku, getProductSkuOptions, normalizeProductSkuOptions, sumOptionUnitPrice, clearTempOrderHolderAssignments, getOrderProductLineUid, indexOrderProductsByUid, calculateOrderProductsDeposit, buildPointCardSnapshotFromWalletPassList, mergeOrderProductDisplayFields, resolveIsFormSubject, isMarkdownBundle } from "./utils";
35
+ import { composeLinePrice, generateDuration, getAllDiscountList, mergeRelationForms, ensureCartItemOriginHolder, buildSubmitPayload, createDefaultTempOrder, createDefaultOrderRulesHooks, createEmptySummary, createUuidV4, formatDateTime, isTempOrder, normalizeOrderMetaList, normalizeBookingIsAll, normalizeBookingSubType, mapPaymentItemsToOrderPayments, normalizeOrderProductDiscountList, resolveEffectivePerUnitDiscount, ensureProductSku, getProductSkuOptions, normalizeProductSkuOptions, sumOptionUnitPrice, clearTempOrderHolderAssignments, getOrderProductLineUid, indexOrderProductsByUid, calculateOrderProductsDeposit, collectPointCardSnapshotCodeCandidates, mergePointCardSnapshotCodes as _mergePointCardSnapshotCodes, buildVirtualCurrencySnapshotFromList, mergeOrderProductDisplayFields, resolveIsFormSubject, isMarkdownBundle } from "./utils";
36
36
  import { isNormalProduct } from "../Product/utils";
37
+ import { getWeighedProductPriceFingerprint, resolveWeighedSourcePrice, withOriginalBundleOptionPrices } from "./utils/weighedProduct";
37
38
  import dayjs from 'dayjs';
39
+ import { getDiscountLifecycleReason } from "../Discount/availability";
40
+ import { stripOsPrivatePayloadFields } from "../../utils/os-private-payload";
38
41
  import { buildSalesNoteText, decodeSalesNotesSnapshot, getSalesNotePolicy } from "./salesNotes";
39
42
  import { ensureOrderPaymentNumber, mergeOrderPaymentRecord, resolveOrderPaymentIdentity } from "./payment-utils";
40
43
  import { resolvePaymentNumberDevicePrefix, resolvePaymentNumberDevicePrefixFromDeviceId } from "../../utils/payment-number";
41
44
  import { processCartPromotion, appendPromotionTags as _appendPromotionTags, getOrderProductUid as getPromotionUid, PRODUCT_LINE_MERGE_DISABLED_METADATA_KEY } from "../../solution/BaseSales/utils/cartPromotion";
42
45
  import { buildProductLineFingerprint, getProductIdentityIndex, getSafeProductNum, isIdentityMatch, normalizeOrderProduct } from "../../solution/ScanOrder/utils";
43
- import { hasManualProductDiscountFlag, syncManualProductDiscountProductNum } from "./utils/manualProductDiscount";
46
+ import { hasManualProductDiscountFlag, syncManualProductDiscountProductNum, buildManualProductDiscountItem, findManualProductDiscountItem, mergeManualProductDiscountIntoList } from "./utils/manualProductDiscount";
44
47
  import { expandHydratedProductsForDiscountCollection, restoreHydratedBundleDiscounts } from "./utils/bundleDiscountHydration";
45
48
  import { getOrderCollectionPersistentId, getOrderCollectionUid, normalizeOrderCollections, repairDuplicateProductLineIdentities as repairDuplicateOrderProductLineIdentities, setOrderCollectionUid } from "./utils/orderCollectionIdentity";
46
49
  import { consolidateDiscountFreeProductLines, ensureUniqueProductLineUids } from "./utils/discountProductLineIdentity";
47
50
  import { applyTempOrderSettlementState, getSelectedSettlementSnapshot, getSettlementKey, getTempOrderSettlementKey, getTempOrderSettlementSnapshot, isVirtualSettlementOrder, normalizeVirtualSettlementOrderProduct, normalizeVirtualSettlementProducts, OrderSettlementConflictError, releaseTempOrderSettlementState, VirtualCurrencyAssetNotFoundError, VirtualCurrencyBalanceError } from "./utils/virtualSettlement";
48
51
  import { DiscountModule } from "../Discount";
49
52
  import { RulesModule } from "../Rules";
53
+ import { isEntitlementPass, isFullCoveragePass } from "../Discount/entitlementPass";
50
54
  import { UnavailableReason } from "../Rules/types";
51
55
  import Decimal from 'decimal.js';
52
56
  import { cloneDeep } from 'lodash-es';
@@ -70,9 +74,26 @@ function isManualProductDiscountProduct(product) {
70
74
  return (item === null || item === void 0 ? void 0 : item.type) === 'product';
71
75
  });
72
76
  }
77
+ function syncReducedEntitlementPassUsageCount(discountList, previousQuantity, nextQuantity) {
78
+ if (!Array.isArray(discountList)) return discountList;
79
+ var previousCount = getSafeProductNum(previousQuantity);
80
+ var nextCount = getSafeProductNum(nextQuantity);
81
+ if (nextCount >= previousCount) return discountList;
82
+ return discountList.map(function (discount) {
83
+ var _discount$metadata$nu, _discount$metadata;
84
+ if (!isEntitlementPass(discount)) return discount;
85
+ var rawUsageCount = Number((_discount$metadata$nu = discount === null || discount === void 0 || (_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata.num) !== null && _discount$metadata$nu !== void 0 ? _discount$metadata$nu : previousCount);
86
+ var usageCount = Number.isFinite(rawUsageCount) ? Math.max(Math.floor(rawUsageCount), 0) : previousCount;
87
+ return _objectSpread(_objectSpread({}, discount), {}, {
88
+ metadata: _objectSpread(_objectSpread({}, (discount === null || discount === void 0 ? void 0 : discount.metadata) || {}), {}, {
89
+ num: Math.min(usageCount, nextCount)
90
+ })
91
+ });
92
+ });
93
+ }
73
94
  var ORDER_PAYMENT_STATUS_PAID = 'paid';
74
95
  var ORDER_PAYMENT_STATUS_PENDING = 'payment_pending';
75
- var CUSTOMER_PROMOTION_DISCOUNT_TAGS = new Set(['good_pass', 'product_discount_card', 'discount_card']);
96
+ var CUSTOMER_PROMOTION_DISCOUNT_TAGS = new Set(['entitlement_pass', 'good_pass', 'product_discount_card', 'discount_card']);
76
97
  function isCustomerPromotionDiscount(discount) {
77
98
  return CUSTOMER_PROMOTION_DISCOUNT_TAGS.has(String((discount === null || discount === void 0 ? void 0 : discount.tag) || (discount === null || discount === void 0 ? void 0 : discount.type) || '').toLowerCase());
78
99
  }
@@ -107,12 +128,26 @@ function getVoucherPaymentLifecycleKey(payment) {
107
128
  if (!isVoucherPaymentRecord(payment)) return null;
108
129
  return "".concat(String(payment.voucher_id), "::").concat(String(payment.status || ''));
109
130
  }
110
- function hasPersistedOrderId(orderId) {
111
- if (orderId === undefined || orderId === null || orderId === '') return false;
112
- if (typeof orderId === 'string' && orderId.startsWith('LOCAL_')) return false;
113
- var normalizedOrderId = Number(orderId);
114
- if (Number.isFinite(normalizedOrderId)) return normalizedOrderId > 0;
115
- return String(orderId).trim() !== '';
131
+ function getDiscountIdentityKey(discount) {
132
+ var id = discount === null || discount === void 0 ? void 0 : discount.id;
133
+ if (id === undefined || id === null || id === '') return null;
134
+ return String(id);
135
+ }
136
+ function mergeCommittedEntitlementWithRuntime(committed, runtime) {
137
+ var _committed$committedA, _runtime$id, _runtime$isDisabled, _runtime$isSelected;
138
+ var committedAppliedProductDetails = (_committed$committedA = committed.committedAppliedProductDetails) !== null && _committed$committedA !== void 0 && _committed$committedA.length ? committed.committedAppliedProductDetails : committed.appliedProductDetails || [];
139
+ return _objectSpread(_objectSpread(_objectSpread({}, committed), runtime), {}, {
140
+ id: (_runtime$id = runtime.id) !== null && _runtime$id !== void 0 ? _runtime$id : committed.id,
141
+ tag: runtime.tag || committed.tag,
142
+ type: runtime.type || committed.type,
143
+ isEditMode: false,
144
+ isDisabled: (_runtime$isDisabled = runtime.isDisabled) !== null && _runtime$isDisabled !== void 0 ? _runtime$isDisabled : false,
145
+ isSelected: (_runtime$isSelected = runtime.isSelected) !== null && _runtime$isSelected !== void 0 ? _runtime$isSelected : committed.isSelected,
146
+ isUsed: committed.isUsed || runtime.isUsed,
147
+ committedAppliedProductDetails: _toConsumableArray(committedAppliedProductDetails),
148
+ applicableProductDetails: [].concat(_toConsumableArray(committed.applicableProductDetails || []), _toConsumableArray(runtime.applicableProductDetails || [])),
149
+ appliedProductDetails: [].concat(_toConsumableArray(committedAppliedProductDetails), _toConsumableArray(runtime.appliedProductDetails || []))
150
+ });
116
151
  }
117
152
  export var OrderModule = /*#__PURE__*/function (_BaseModule) {
118
153
  _inherits(OrderModule, _BaseModule);
@@ -134,6 +169,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
134
169
  _defineProperty(_assertThisInitialized(_this), "openCache", false);
135
170
  _defineProperty(_assertThisInitialized(_this), "sessionStoragePersistEnabled", false);
136
171
  _defineProperty(_assertThisInitialized(_this), "sessionStorageRestoreRecord", null);
172
+ /** 只允许当前订单最新的 prepare/config 请求回写客户资产态。 */
173
+ _defineProperty(_assertThisInitialized(_this), "customerWalletPrepareConfigEpoch", 0);
174
+ /** Payment 可能早于 prepare/config 返回;先按实例 ID 暂存卡号等待 Snapshot。 */
175
+ _defineProperty(_assertThisInitialized(_this), "pointCardSnapshotCodeCandidates", new Map());
137
176
  _defineProperty(_assertThisInitialized(_this), "salesSummaryModuleName", void 0);
138
177
  _defineProperty(_assertThisInitialized(_this), "rulesHooksOverride", void 0);
139
178
  _defineProperty(_assertThisInitialized(_this), "moduleHooksOverride", void 0);
@@ -174,7 +213,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
174
213
  _step2;
175
214
  try {
176
215
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
177
- var _item$type2, _ref, _ref2, _item$discount$resour, _item$discount, _item$discount$title, _item$discount2, _item$discount3, _item$discount$fixed_, _item$discount4, _item$discount5, _item$amount, _ref3, _item$discount$origin, _item$discount6, _ref4, _ref5, _item$metadata$num, _item$metadata, _ref6, _ref7, _item$metadata$num2, _item$metadata2, _ref8, _item$discount$discou, _item$discount7, _item$amount2, _item$amount3, _product$product_id, _product$is_charge_ta, _ref9, _product$original_pri, _ref10, _item$discount$discou2, _item$discount8, _item$discount$discou3, _item$discount9;
216
+ var _item$type2, _ref, _ref2, _item$discount$resour, _item$discount, _item$discount$title, _item$discount2, _item$metadata, _item$discount3, _item$discount4, _item$discount$fixed_, _item$discount5, _item$discount6, _item$amount, _ref3, _item$discount$origin, _item$discount7, _ref4, _ref5, _item$metadata$num, _item$metadata2, _item$discount$produc, _item$discount8, _ref6, _ref7, _item$metadata$num2, _item$metadata3, _item$discount9, _ref8, _item$discount$discou, _item$discount10, _item$amount2, _item$amount3, _product$product_id, _product$is_charge_ta, _ref9, _product$original_pri, _ref10, _item$discount$discou2, _item$discount11, _item$discount$discou3, _item$discount12;
178
217
  var item = _step2.value;
179
218
  var type = (_item$type2 = item === null || item === void 0 ? void 0 : item.type) !== null && _item$type2 !== void 0 ? _item$type2 : item === null || item === void 0 ? void 0 : item.tag;
180
219
  if (!type || type === 'product') continue;
@@ -185,22 +224,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
185
224
  var key = Number.isFinite(id) ? id : String(resourceId);
186
225
  var title = (_item$discount$title = item === null || item === void 0 || (_item$discount2 = item.discount) === null || _item$discount2 === void 0 ? void 0 : _item$discount2.title) !== null && _item$discount$title !== void 0 ? _item$discount$title : {};
187
226
  var amount = Number((item === null || item === void 0 ? void 0 : item.amount) || 0);
188
- var discountCardType = item === null || item === void 0 || (_item$discount3 = item.discount) === null || _item$discount3 === void 0 ? void 0 : _item$discount3.discount_card_type;
189
- var parValue = isDiscountCard ? discountCardType === 'fixed_amount' ? (_item$discount$fixed_ = item === null || item === void 0 || (_item$discount4 = item.discount) === null || _item$discount4 === void 0 ? void 0 : _item$discount4.fixed_amount) !== null && _item$discount$fixed_ !== void 0 ? _item$discount$fixed_ : item === null || item === void 0 ? void 0 : item.amount : item === null || item === void 0 || (_item$discount5 = item.discount) === null || _item$discount5 === void 0 ? void 0 : _item$discount5.percent : '0';
227
+ var encoded = (item === null || item === void 0 || (_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.encoded) || (item === null || item === void 0 ? void 0 : item.encoded) || (item === null || item === void 0 || (_item$discount3 = item.discount) === null || _item$discount3 === void 0 ? void 0 : _item$discount3.encoded) || '';
228
+ var discountCardType = item === null || item === void 0 || (_item$discount4 = item.discount) === null || _item$discount4 === void 0 ? void 0 : _item$discount4.discount_card_type;
229
+ var parValue = isDiscountCard ? discountCardType === 'fixed_amount' ? (_item$discount$fixed_ = item === null || item === void 0 || (_item$discount5 = item.discount) === null || _item$discount5 === void 0 ? void 0 : _item$discount5.fixed_amount) !== null && _item$discount$fixed_ !== void 0 ? _item$discount$fixed_ : item === null || item === void 0 ? void 0 : item.amount : item === null || item === void 0 || (_item$discount6 = item.discount) === null || _item$discount6 === void 0 ? void 0 : _item$discount6.percent : '0';
190
230
  var detail = {
191
231
  amount: String((_item$amount = item === null || item === void 0 ? void 0 : item.amount) !== null && _item$amount !== void 0 ? _item$amount : '0'),
192
232
  type: type,
193
233
  resource_id: key,
194
234
  title: title,
195
- original_amount: String((_ref3 = (_item$discount$origin = item === null || item === void 0 || (_item$discount6 = item.discount) === null || _item$discount6 === void 0 ? void 0 : _item$discount6.original_amount) !== null && _item$discount$origin !== void 0 ? _item$discount$origin : item === null || item === void 0 ? void 0 : item.amount) !== null && _ref3 !== void 0 ? _ref3 : '0'),
196
- num: Number((_ref4 = (_ref5 = (_item$metadata$num = item === null || item === void 0 || (_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.num) !== null && _item$metadata$num !== void 0 ? _item$metadata$num : product === null || product === void 0 ? void 0 : product.num) !== null && _ref5 !== void 0 ? _ref5 : product === null || product === void 0 ? void 0 : product.product_quantity) !== null && _ref4 !== void 0 ? _ref4 : 1) || 1,
235
+ original_amount: String((_ref3 = (_item$discount$origin = item === null || item === void 0 || (_item$discount7 = item.discount) === null || _item$discount7 === void 0 ? void 0 : _item$discount7.original_amount) !== null && _item$discount$origin !== void 0 ? _item$discount$origin : item === null || item === void 0 ? void 0 : item.amount) !== null && _ref3 !== void 0 ? _ref3 : '0'),
236
+ num: Number((_ref4 = (_ref5 = (_item$metadata$num = item === null || item === void 0 || (_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.num) !== null && _item$metadata$num !== void 0 ? _item$metadata$num : product === null || product === void 0 ? void 0 : product.num) !== null && _ref5 !== void 0 ? _ref5 : product === null || product === void 0 ? void 0 : product.product_quantity) !== null && _ref4 !== void 0 ? _ref4 : 1) || 1,
197
237
  metadata: item === null || item === void 0 ? void 0 : item.metadata,
198
- discount: item === null || item === void 0 ? void 0 : item.discount,
199
- _num: Number((_ref6 = (_ref7 = (_item$metadata$num2 = item === null || item === void 0 || (_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.num) !== null && _item$metadata$num2 !== void 0 ? _item$metadata$num2 : product === null || product === void 0 ? void 0 : product.num) !== null && _ref7 !== void 0 ? _ref7 : product === null || product === void 0 ? void 0 : product.product_quantity) !== null && _ref6 !== void 0 ? _ref6 : 1) || 1
238
+ discount: _objectSpread(_objectSpread({}, (item === null || item === void 0 ? void 0 : item.discount) || {}), {}, {
239
+ product_id: (_item$discount$produc = item === null || item === void 0 || (_item$discount8 = item.discount) === null || _item$discount8 === void 0 ? void 0 : _item$discount8.product_id) !== null && _item$discount$produc !== void 0 ? _item$discount$produc : product === null || product === void 0 ? void 0 : product.product_id
240
+ }),
241
+ _num: Number((_ref6 = (_ref7 = (_item$metadata$num2 = item === null || item === void 0 || (_item$metadata3 = item.metadata) === null || _item$metadata3 === void 0 ? void 0 : _item$metadata3.num) !== null && _item$metadata$num2 !== void 0 ? _item$metadata$num2 : product === null || product === void 0 ? void 0 : product.num) !== null && _ref7 !== void 0 ? _ref7 : product === null || product === void 0 ? void 0 : product.product_quantity) !== null && _ref6 !== void 0 ? _ref6 : 1) || 1
200
242
  };
201
243
  var existed = discountMap.get(key);
202
244
  if (existed) {
203
245
  var _existed$limited_rela;
246
+ if (!existed.encoded && encoded) {
247
+ existed.encoded = encoded;
248
+ existed.metadata = _objectSpread(_objectSpread({}, existed.metadata), {}, {
249
+ encoded: encoded
250
+ });
251
+ }
204
252
  existed.amount = Number(existed.amount || 0) + amount;
205
253
  existed.used_par_value = String(Number(existed.used_par_value || 0) + amount);
206
254
  if (!isDiscountCard) {
@@ -219,10 +267,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
219
267
  discountMap.set(key, {
220
268
  id: key,
221
269
  product_name: '',
222
- encoded: '',
223
- code: '',
270
+ encoded: encoded,
271
+ code: (item === null || item === void 0 ? void 0 : item.code) || (item === null || item === void 0 || (_item$discount9 = item.discount) === null || _item$discount9 === void 0 ? void 0 : _item$discount9.code) || '',
272
+ metadata: {
273
+ encoded: encoded
274
+ },
224
275
  tag: type,
225
- product_id: (_ref8 = (_item$discount$discou = item === null || item === void 0 || (_item$discount7 = item.discount) === null || _item$discount7 === void 0 ? void 0 : _item$discount7.discount_product_id) !== null && _item$discount$discou !== void 0 ? _item$discount$discou : product === null || product === void 0 ? void 0 : product.product_id) !== null && _ref8 !== void 0 ? _ref8 : 0,
276
+ product_id: (_ref8 = (_item$discount$discou = item === null || item === void 0 || (_item$discount10 = item.discount) === null || _item$discount10 === void 0 ? void 0 : _item$discount10.discount_product_id) !== null && _item$discount$discou !== void 0 ? _item$discount$discou : product === null || product === void 0 ? void 0 : product.product_id) !== null && _ref8 !== void 0 ? _ref8 : 0,
226
277
  relation_type: '',
227
278
  par_value: String(parValue !== null && parValue !== void 0 ? parValue : '0'),
228
279
  used_par_value: String((_item$amount2 = item === null || item === void 0 ? void 0 : item.amount) !== null && _item$amount2 !== void 0 ? _item$amount2 : '0'),
@@ -255,8 +306,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
255
306
  amount: amount,
256
307
  discount: _objectSpread(_objectSpread({}, (item === null || item === void 0 ? void 0 : item.discount) || {}), {}, {
257
308
  resource_id: key,
258
- discount_product_id: (_ref10 = (_item$discount$discou2 = item === null || item === void 0 || (_item$discount8 = item.discount) === null || _item$discount8 === void 0 ? void 0 : _item$discount8.discount_product_id) !== null && _item$discount$discou2 !== void 0 ? _item$discount$discou2 : product === null || product === void 0 ? void 0 : product.product_id) !== null && _ref10 !== void 0 ? _ref10 : 0,
259
- discount_calculation_mode: (_item$discount$discou3 = item === null || item === void 0 || (_item$discount9 = item.discount) === null || _item$discount9 === void 0 ? void 0 : _item$discount9.discount_calculation_mode) !== null && _item$discount$discou3 !== void 0 ? _item$discount$discou3 : 'item_level'
309
+ discount_product_id: (_ref10 = (_item$discount$discou2 = item === null || item === void 0 || (_item$discount11 = item.discount) === null || _item$discount11 === void 0 ? void 0 : _item$discount11.discount_product_id) !== null && _item$discount$discou2 !== void 0 ? _item$discount$discou2 : product === null || product === void 0 ? void 0 : product.product_id) !== null && _ref10 !== void 0 ? _ref10 : 0,
310
+ discount_calculation_mode: (_item$discount$discou3 = item === null || item === void 0 || (_item$discount12 = item.discount) === null || _item$discount12 === void 0 ? void 0 : _item$discount12.discount_calculation_mode) !== null && _item$discount$discou3 !== void 0 ? _item$discount$discou3 : 'item_level'
260
311
  }),
261
312
  applicableProductDetails: [detail],
262
313
  appliedProductDetails: [detail]
@@ -560,7 +611,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
560
611
  }, {
561
612
  key: "createDefaultRulesHooks",
562
613
  value: function createDefaultRulesHooks() {
563
- return createDefaultOrderRulesHooks();
614
+ var _this2 = this;
615
+ return createDefaultOrderRulesHooks(function () {
616
+ var _this2$store$tempOrde;
617
+ return ((_this2$store$tempOrde = _this2.store.tempOrder) === null || _this2$store$tempOrde === void 0 ? void 0 : _this2$store$tempOrde.bookings) || [];
618
+ });
619
+ }
620
+
621
+ /**
622
+ * Stable across notifyTempOrderChanged's immutable copy, but changes when a
623
+ * different local/server order becomes current.
624
+ */
625
+ }, {
626
+ key: "getDiscountConfigOrderIdentityKey",
627
+ value: function getDiscountConfigOrderIdentityKey(tempOrder) {
628
+ var _ref12, _identity$orderId, _tempOrder$request_un, _ref13, _identity$externalSal, _ref14, _ref15, _identity$localId, _tempOrder$_extend;
629
+ var identity = this.getOrderIdentity();
630
+ return JSON.stringify([(_ref12 = (_identity$orderId = identity === null || identity === void 0 ? void 0 : identity.orderId) !== null && _identity$orderId !== void 0 ? _identity$orderId : tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.order_id) !== null && _ref12 !== void 0 ? _ref12 : '', (_tempOrder$request_un = tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.request_unique_idempotency_token) !== null && _tempOrder$request_un !== void 0 ? _tempOrder$request_un : '', (_ref13 = (_identity$externalSal = identity === null || identity === void 0 ? void 0 : identity.externalSaleNumber) !== null && _identity$externalSal !== void 0 ? _identity$externalSal : tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.external_sale_number) !== null && _ref13 !== void 0 ? _ref13 : '', (_ref14 = (_ref15 = (_identity$localId = identity === null || identity === void 0 ? void 0 : identity.localId) !== null && _identity$localId !== void 0 ? _identity$localId : tempOrder === null || tempOrder === void 0 || (_tempOrder$_extend = tempOrder._extend) === null || _tempOrder$_extend === void 0 ? void 0 : _tempOrder$_extend.localId) !== null && _ref15 !== void 0 ? _ref15 : this.cacheId) !== null && _ref14 !== void 0 ? _ref14 : '']);
564
631
  }
565
632
 
566
633
  // ─── Discount: 公共 API ───
@@ -568,13 +635,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
568
635
  key: "loadDiscountConfig",
569
636
  value: function () {
570
637
  var _loadDiscountConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
571
- var _this$store$tempOrder, _this$store$discount, _this$store$tempOrder2;
572
- var orderId, prepareConfigResult, discountList, _this$store$discount2, _this$store$discount3, _this$store$discount4, currentDiscountList, currentEditDiscounts, currentScanDiscounts, currentScanDiscountIds, runtimeDiscountIds, runtimeDiscounts, mergedDiscountList;
638
+ var _this$store$tempOrder,
639
+ _this$store$discount,
640
+ _this3 = this,
641
+ _this$store$tempOrder2;
642
+ var orderId, requestEpoch, requestOrderIdentityKey, prepareConfigResult, isCurrentRequest, discountList, _this$store$discount2, _this$store$discount3, _this$store$discount4, currentDiscountList, currentCommittedDiscounts, currentScanDiscounts, currentScanDiscountById, committedDiscountById, mergedCommittedDiscountIds, refreshedScanDiscountIds, runtimeDiscountIds, runtimeDiscounts, retainedCommittedDiscounts, retainedScanDiscounts, mergedDiscountList;
573
643
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
574
644
  while (1) switch (_context3.prev = _context3.next) {
575
645
  case 0:
576
646
  orderId = params.orderId || ((_this$store$tempOrder = this.store.tempOrder) === null || _this$store$tempOrder === void 0 ? void 0 : _this$store$tempOrder.order_id) || undefined;
577
- _context3.next = 3;
647
+ requestEpoch = ++this.customerWalletPrepareConfigEpoch;
648
+ requestOrderIdentityKey = this.getDiscountConfigOrderIdentityKey(this.store.tempOrder);
649
+ _context3.next = 5;
578
650
  return (_this$store$discount = this.store.discount) === null || _this$store$discount === void 0 ? void 0 : _this$store$discount.loadPrepareConfig(_objectSpread({
579
651
  customer_id: params.customerId,
580
652
  action: params.action || (orderId ? 'edit' : 'create'),
@@ -583,56 +655,130 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
583
655
  with_wallet_pass_holder: 1,
584
656
  with_available_wallet_flag: 1,
585
657
  with_available_wallet_pass_flag: 1,
658
+ with_entitlement_pass: 1,
659
+ filter_order_wallet_pass_usage: 0,
586
660
  with_virtual_currency: 1,
587
661
  request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
588
662
  }, orderId ? {
589
663
  order_id: orderId
590
664
  } : {}));
591
- case 3:
665
+ case 5:
592
666
  prepareConfigResult = _context3.sent;
667
+ isCurrentRequest = function isCurrentRequest() {
668
+ var _this3$store$tempOrde, _this3$store$tempOrde2;
669
+ return requestEpoch === _this3.customerWalletPrepareConfigEpoch && _this3.getDiscountConfigOrderIdentityKey(_this3.store.tempOrder) === requestOrderIdentityKey && String((_this3$store$tempOrde = (_this3$store$tempOrde2 = _this3.store.tempOrder) === null || _this3$store$tempOrde2 === void 0 ? void 0 : _this3$store$tempOrde2.customer_id) !== null && _this3$store$tempOrde !== void 0 ? _this3$store$tempOrde : '') === String(params.customerId);
670
+ };
671
+ if (isCurrentRequest()) {
672
+ _context3.next = 9;
673
+ break;
674
+ }
675
+ return _context3.abrupt("return", this.getDiscountList());
676
+ case 9:
593
677
  discountList = prepareConfigResult === null || prepareConfigResult === void 0 ? void 0 : prepareConfigResult.discountList;
594
- this.store.availableWalletIds = (prepareConfigResult === null || prepareConfigResult === void 0 ? void 0 : prepareConfigResult.availableWalletIds) || [];
595
- this.store.virtualCurrencyList = (prepareConfigResult === null || prepareConfigResult === void 0 ? void 0 : prepareConfigResult.virtualCurrencyList) || [];
596
678
  if (prepareConfigResult) {
597
- this.writePointCardSnapshotFromPrepareConfig({
598
- orderId: orderId,
679
+ this.writeCustomerWalletSnapshotsFromPrepareConfig({
599
680
  customerId: params.customerId,
600
- availableWalletPassList: prepareConfigResult.availableWalletPassList || []
681
+ availableWalletIds: prepareConfigResult.availableWalletIds || [],
682
+ availableWalletPassList: prepareConfigResult.availableWalletPassList || [],
683
+ virtualCurrencyList: prepareConfigResult.virtualCurrencyList || []
601
684
  });
602
685
  }
603
686
  if (!discountList) {
604
- _context3.next = 20;
687
+ _context3.next = 32;
605
688
  break;
606
689
  }
607
690
  currentDiscountList = ((_this$store$discount2 = this.store.discount) === null || _this$store$discount2 === void 0 ? void 0 : _this$store$discount2.getDiscountList()) || [];
608
- currentEditDiscounts = currentDiscountList.filter(function (discount) {
609
- return discount === null || discount === void 0 ? void 0 : discount.isEditMode;
691
+ currentCommittedDiscounts = currentDiscountList.filter(function (discount) {
692
+ var _discount$committedAp;
693
+ return (discount === null || discount === void 0 ? void 0 : discount.isEditMode) || (discount === null || discount === void 0 || (_discount$committedAp = discount.committedAppliedProductDetails) === null || _discount$committedAp === void 0 ? void 0 : _discount$committedAp.length);
610
694
  });
611
695
  currentScanDiscounts = currentDiscountList.filter(function (discount) {
612
696
  return discount === null || discount === void 0 ? void 0 : discount.isScan;
613
697
  });
614
- currentScanDiscountIds = new Set(currentScanDiscounts.map(function (discount) {
615
- return discount === null || discount === void 0 ? void 0 : discount.id;
698
+ currentScanDiscountById = new Map(currentScanDiscounts.flatMap(function (discount) {
699
+ var id = getDiscountIdentityKey(discount);
700
+ return id === null ? [] : [[id, discount]];
701
+ }));
702
+ committedDiscountById = new Map(currentCommittedDiscounts.flatMap(function (discount) {
703
+ var id = getDiscountIdentityKey(discount);
704
+ return id === null ? [] : [[id, discount]];
616
705
  }));
706
+ mergedCommittedDiscountIds = new Set();
707
+ refreshedScanDiscountIds = new Set();
617
708
  runtimeDiscountIds = new Set();
618
- runtimeDiscounts = discountList.filter(function (discount) {
619
- if (currentScanDiscountIds.has(discount === null || discount === void 0 ? void 0 : discount.id)) return false;
620
- if (runtimeDiscountIds.has(discount === null || discount === void 0 ? void 0 : discount.id)) return false;
621
- runtimeDiscountIds.add(discount === null || discount === void 0 ? void 0 : discount.id);
622
- return true;
709
+ runtimeDiscounts = discountList.flatMap(function (discount) {
710
+ var id = getDiscountIdentityKey(discount);
711
+ if (id === null) return [discount];
712
+ if (runtimeDiscountIds.has(id)) return [];
713
+ runtimeDiscountIds.add(id);
714
+ var currentScanDiscount = currentScanDiscountById.get(id);
715
+ if (currentScanDiscount && (!isEntitlementPass(currentScanDiscount) || !isEntitlementPass(discount))) {
716
+ return [];
717
+ }
718
+ var committedDiscount = committedDiscountById.get(id);
719
+ var nextDiscount = discount;
720
+ if (committedDiscount && isEntitlementPass(committedDiscount) && isEntitlementPass(discount)) {
721
+ mergedCommittedDiscountIds.add(id);
722
+ nextDiscount = mergeCommittedEntitlementWithRuntime(committedDiscount, discount);
723
+ }
724
+ if (currentScanDiscount) {
725
+ var _currentScanDiscount$, _currentScanDiscount$2;
726
+ refreshedScanDiscountIds.add(id);
727
+ nextDiscount = _objectSpread(_objectSpread({}, nextDiscount), {}, {
728
+ isScan: true,
729
+ isSelected: (_currentScanDiscount$ = currentScanDiscount.isSelected) !== null && _currentScanDiscount$ !== void 0 ? _currentScanDiscount$ : nextDiscount.isSelected,
730
+ isManualSelect: (_currentScanDiscount$2 = currentScanDiscount.isManualSelect) !== null && _currentScanDiscount$2 !== void 0 ? _currentScanDiscount$2 : nextDiscount.isManualSelect
731
+ });
732
+ }
733
+ return [nextDiscount];
734
+ });
735
+ retainedCommittedDiscounts = currentCommittedDiscounts.filter(function (discount) {
736
+ var id = getDiscountIdentityKey(discount);
737
+ return id === null || !mergedCommittedDiscountIds.has(id);
738
+ }).map(function (discount) {
739
+ var _discount$committedAp2;
740
+ return (_discount$committedAp2 = discount.committedAppliedProductDetails) !== null && _discount$committedAp2 !== void 0 && _discount$committedAp2.length ? _objectSpread(_objectSpread({}, discount), {}, {
741
+ isEditMode: true,
742
+ isDisabled: true,
743
+ isSelected: true,
744
+ isUsed: true,
745
+ appliedProductDetails: _toConsumableArray(discount.committedAppliedProductDetails)
746
+ }) : discount;
747
+ });
748
+ retainedScanDiscounts = currentScanDiscounts.filter(function (discount) {
749
+ var id = getDiscountIdentityKey(discount);
750
+ return id === null || !refreshedScanDiscountIds.has(id);
623
751
  });
624
- mergedDiscountList = [].concat(_toConsumableArray(currentEditDiscounts), _toConsumableArray(currentScanDiscounts), _toConsumableArray(runtimeDiscounts));
625
- _context3.next = 18;
752
+ mergedDiscountList = [].concat(_toConsumableArray(retainedCommittedDiscounts), _toConsumableArray(retainedScanDiscounts), _toConsumableArray(runtimeDiscounts));
753
+ if (isCurrentRequest()) {
754
+ _context3.next = 26;
755
+ break;
756
+ }
757
+ return _context3.abrupt("return", this.getDiscountList());
758
+ case 26:
759
+ _context3.next = 28;
626
760
  return (_this$store$discount3 = this.store.discount) === null || _this$store$discount3 === void 0 ? void 0 : _this$store$discount3.setOriginalDiscountList(mergedDiscountList);
627
- case 18:
628
- _context3.next = 20;
761
+ case 28:
762
+ if (isCurrentRequest()) {
763
+ _context3.next = 30;
764
+ break;
765
+ }
766
+ return _context3.abrupt("return", this.getDiscountList());
767
+ case 30:
768
+ _context3.next = 32;
629
769
  return (_this$store$discount4 = this.store.discount) === null || _this$store$discount4 === void 0 ? void 0 : _this$store$discount4.setDiscountList(mergedDiscountList);
630
- case 20:
770
+ case 32:
771
+ if (isCurrentRequest()) {
772
+ _context3.next = 34;
773
+ break;
774
+ }
775
+ return _context3.abrupt("return", this.getDiscountList());
776
+ case 34:
631
777
  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) {
632
778
  this.applyDiscount();
633
779
  }
634
780
  return _context3.abrupt("return", this.getDiscountList());
635
- case 22:
781
+ case 36:
636
782
  case "end":
637
783
  return _context3.stop();
638
784
  }
@@ -659,6 +805,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
659
805
  value: function getVirtualCurrencyList() {
660
806
  return cloneDeep(this.store.virtualCurrencyList || []);
661
807
  }
808
+ }, {
809
+ key: "getCustomerWalletPrepareConfigEpoch",
810
+ value: function getCustomerWalletPrepareConfigEpoch() {
811
+ return this.customerWalletPrepareConfigEpoch;
812
+ }
662
813
  }, {
663
814
  key: "syncScannedDiscountsToOriginalDiscountList",
664
815
  value: function () {
@@ -701,13 +852,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
701
852
  key: "ensureEditDiscountConfigForProductChange",
702
853
  value: function () {
703
854
  var _ensureEditDiscountConfigForProductChange = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(tempOrder) {
704
- var _tempOrder$customer, _tempOrder$_extend, _tempOrder$_extend2, _this$store$discount10;
855
+ var _tempOrder$customer, _tempOrder$_extend2, _tempOrder$_extend3, _this$store$discount10;
705
856
  var orderId, customerId, currentDiscountList, hasRuntimeDiscounts;
706
857
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
707
858
  while (1) switch (_context5.prev = _context5.next) {
708
859
  case 0:
709
860
  orderId = tempOrder.order_id;
710
- customerId = Number(tempOrder.customer_id || ((_tempOrder$customer = tempOrder.customer) === null || _tempOrder$customer === void 0 ? void 0 : _tempOrder$customer.id) || ((_tempOrder$_extend = tempOrder._extend) === null || _tempOrder$_extend === void 0 || (_tempOrder$_extend = _tempOrder$_extend.customerSnapshot) === null || _tempOrder$_extend === void 0 ? void 0 : _tempOrder$_extend.id) || ((_tempOrder$_extend2 = tempOrder._extend) === null || _tempOrder$_extend2 === void 0 || (_tempOrder$_extend2 = _tempOrder$_extend2.customerSnapshot) === null || _tempOrder$_extend2 === void 0 ? void 0 : _tempOrder$_extend2.customer_id) || 0);
861
+ customerId = Number(tempOrder.customer_id || ((_tempOrder$customer = tempOrder.customer) === null || _tempOrder$customer === void 0 ? void 0 : _tempOrder$customer.id) || ((_tempOrder$_extend2 = tempOrder._extend) === null || _tempOrder$_extend2 === void 0 || (_tempOrder$_extend2 = _tempOrder$_extend2.customerSnapshot) === null || _tempOrder$_extend2 === void 0 ? void 0 : _tempOrder$_extend2.id) || ((_tempOrder$_extend3 = tempOrder._extend) === null || _tempOrder$_extend3 === void 0 || (_tempOrder$_extend3 = _tempOrder$_extend3.customerSnapshot) === null || _tempOrder$_extend3 === void 0 ? void 0 : _tempOrder$_extend3.customer_id) || 0);
711
862
  if (!(!orderId || !customerId || customerId === 1)) {
712
863
  _context5.next = 4;
713
864
  break;
@@ -747,7 +898,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
747
898
  value: function () {
748
899
  var _scanCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(code, customerId) {
749
900
  var _this$store$discount11, _tempOrder$holder, _this$store$summary;
750
- var resultDiscountWithReason, resultDiscountList, unavailableReasonKey, rulesModule, withScanList, currentSelected, tempOrder, holders, _ref12, isAvailable, newDiscountList, evaluatedDiscountList, unavailableReason, shouldRetainForLater, normalizedNewDiscountList, retainedDiscountList, resolvedDiscountList, _this$store$discount12, _this$store$discount13;
901
+ var resultDiscountWithReason, resultDiscountList, unavailableReasonKey, rulesModule, withScanList, currentSelected, tempOrder, holders, _ref16, isAvailable, newDiscountList, evaluatedDiscountList, unavailableReason, scannedIds, evaluatedScannedDiscounts, shouldRetainForLater, normalizedNewDiscountList, resolvedDiscountList, _this$store$discount12, _this$store$discount13, retainedDiscounts;
751
902
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
752
903
  while (1) switch (_context6.prev = _context6.next) {
753
904
  case 0:
@@ -837,7 +988,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
837
988
  case 20:
838
989
  tempOrder = this.store.tempOrder;
839
990
  holders = (tempOrder === null || tempOrder === void 0 || (_tempOrder$holder = tempOrder.holder) === null || _tempOrder$holder === void 0 ? void 0 : _tempOrder$holder.form_record) || [];
840
- _ref12 = rulesModule.isDiscountListAvailable({
991
+ _ref16 = rulesModule.isDiscountListAvailable({
841
992
  productList: (tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.products) || [],
842
993
  oldDiscountList: this.getDiscountList(),
843
994
  newDiscountList: withScanList,
@@ -849,47 +1000,73 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
849
1000
  }) || {
850
1001
  isAvailable: false,
851
1002
  discountList: this.getDiscountList()
852
- }, isAvailable = _ref12.isAvailable, newDiscountList = _ref12.discountList, evaluatedDiscountList = _ref12.evaluatedDiscountList, unavailableReason = _ref12.unavailableReason;
853
- shouldRetainForLater = !isAvailable && unavailableReason === UnavailableReason.ProductNotApplicable && withScanList.some(isCustomerPromotionDiscount);
1003
+ }, isAvailable = _ref16.isAvailable, newDiscountList = _ref16.discountList, evaluatedDiscountList = _ref16.evaluatedDiscountList, unavailableReason = _ref16.unavailableReason;
1004
+ scannedIds = new Set(withScanList.map(function (discount) {
1005
+ return String(discount.id);
1006
+ }));
1007
+ evaluatedScannedDiscounts = (evaluatedDiscountList || withScanList).filter(function (discount) {
1008
+ return scannedIds.has(String(discount.id)) && isCustomerPromotionDiscount(discount) && !getDiscountLifecycleReason(discount);
1009
+ });
1010
+ shouldRetainForLater = !isAvailable && evaluatedScannedDiscounts.length > 0;
854
1011
  normalizedNewDiscountList = newDiscountList ? markScannedDiscounts(newDiscountList, withScanList) : undefined;
855
- retainedDiscountList = evaluatedDiscountList ? markScannedDiscounts(evaluatedDiscountList, withScanList) : normalizedNewDiscountList;
856
1012
  resolvedDiscountList = normalizedNewDiscountList || this.getDiscountList();
857
1013
  if (!(isAvailable && normalizedNewDiscountList)) {
858
- _context6.next = 36;
1014
+ _context6.next = 37;
859
1015
  break;
860
1016
  }
861
- _context6.next = 30;
1017
+ _context6.next = 31;
862
1018
  return (_this$store$discount12 = this.store.discount) === null || _this$store$discount12 === void 0 ? void 0 : _this$store$discount12.setDiscountList(normalizedNewDiscountList);
863
- case 30:
864
- this.applyDiscount();
865
- _context6.next = 33;
1019
+ case 31:
1020
+ // 实际写回商品时沿用扫码试算的优先级,避免旧商品行的选卡覆盖本次扫码。
1021
+ this.applyDiscount({
1022
+ preferredEntitlementPassIds: withScanList.filter(function (discount) {
1023
+ return isEntitlementPass(discount);
1024
+ }).map(function (discount) {
1025
+ return discount.id;
1026
+ })
1027
+ });
1028
+ _context6.next = 34;
866
1029
  return this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
867
- case 33:
1030
+ case 34:
868
1031
  resolvedDiscountList = this.getDiscountList();
869
- _context6.next = 42;
1032
+ _context6.next = 45;
870
1033
  break;
871
- case 36:
872
- if (!(shouldRetainForLater && retainedDiscountList)) {
873
- _context6.next = 42;
1034
+ case 37:
1035
+ if (!shouldRetainForLater) {
1036
+ _context6.next = 45;
874
1037
  break;
875
1038
  }
876
- _context6.next = 39;
877
- return (_this$store$discount13 = this.store.discount) === null || _this$store$discount13 === void 0 ? void 0 : _this$store$discount13.setDiscountList(retainedDiscountList);
878
- case 39:
879
- _context6.next = 41;
1039
+ // 只合并本次识别的卡券;不把试算产生的其他选券状态写回订单。
1040
+ retainedDiscounts = new Map(this.getDiscountList().map(function (discount) {
1041
+ return [String(discount.id), discount];
1042
+ }));
1043
+ evaluatedScannedDiscounts.forEach(function (discount) {
1044
+ retainedDiscounts.set(String(discount.id), _objectSpread(_objectSpread({}, discount), {}, {
1045
+ isScan: true,
1046
+ isAvailable: false,
1047
+ isSelected: false,
1048
+ reasonCode: discount.reasonCode || 'product_not_applicable',
1049
+ appliedProductDetails: [],
1050
+ savedAmount: 0
1051
+ }));
1052
+ });
1053
+ _context6.next = 42;
1054
+ return (_this$store$discount13 = this.store.discount) === null || _this$store$discount13 === void 0 ? void 0 : _this$store$discount13.setDiscountList(_toConsumableArray(retainedDiscounts.values()));
1055
+ case 42:
1056
+ _context6.next = 44;
880
1057
  return this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
881
- case 41:
1058
+ case 44:
882
1059
  resolvedDiscountList = this.getDiscountList();
883
- case 42:
1060
+ case 45:
884
1061
  return _context6.abrupt("return", {
885
1062
  type: 'clientCalc',
886
1063
  isAvailable: isAvailable || false,
887
1064
  isAccepted: Boolean(isAvailable || shouldRetainForLater),
888
1065
  discountList: resolvedDiscountList,
889
- scannedDiscountList: resultDiscountList,
1066
+ scannedDiscountList: evaluatedScannedDiscounts,
890
1067
  unavailableReason: unavailableReason
891
1068
  });
892
- case 43:
1069
+ case 46:
893
1070
  case "end":
894
1071
  return _context6.stop();
895
1072
  }
@@ -905,7 +1082,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
905
1082
  value: function applyDiscount(options) {
906
1083
  var _this$store$discount16,
907
1084
  _this$store$summary2,
908
- _this2 = this;
1085
+ _this4 = this;
909
1086
  var tempOrder = this.store.tempOrder;
910
1087
  // 任意 products CRUD 后都应当重算 discount 状态;即使 products 为空,
911
1088
  // 也需要让 Rules.calcDiscount 把 DiscountModule 的 isSelected / isAvailable /
@@ -936,14 +1113,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
936
1113
  },
937
1114
  orderTotalAmount: Number(((_this$store$summary2 = this.store.summary) === null || _this$store$summary2 === void 0 ? void 0 : _this$store$summary2.total_amount) || 0)
938
1115
  }, {
939
- reapplyBookingDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids
1116
+ reapplyBookingDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids,
1117
+ reapplyWeighedDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyWeighedDiscountProductUids,
1118
+ preferredEntitlementPassIds: options === null || options === void 0 ? void 0 : options.preferredEntitlementPassIds
940
1119
  });
941
1120
  if (result !== null && result !== void 0 && result.productList) {
942
1121
  var previousProductsByUid = indexOrderProductsByUid(tempOrder.products);
943
1122
  tempOrder.products = this.applyProductDiscountPrices((result.productList || []).map(function (product, index) {
944
- var _ref13;
1123
+ var _ref17;
945
1124
  var uid = getOrderProductLineUid(product);
946
- var previous = (_ref13 = uid ? previousProductsByUid.get(uid) : undefined) !== null && _ref13 !== void 0 ? _ref13 : previousProductsByUid.get("__index__:".concat(index));
1125
+ var previous = (_ref17 = uid ? previousProductsByUid.get(uid) : undefined) !== null && _ref17 !== void 0 ? _ref17 : previousProductsByUid.get("__index__:".concat(index));
947
1126
  if (isManualProductDiscountProduct(previous)) {
948
1127
  return previous;
949
1128
  }
@@ -961,7 +1140,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
961
1140
  (_this$store$discount17 = this.store.discount) === null || _this$store$discount17 === void 0 || _this$store$discount17.setDiscountList(result.discountList);
962
1141
  }
963
1142
  this.hasActiveCustomerBoundDiscount = (tempOrder.products || []).some(function (product) {
964
- return _this2.productHasCustomerBoundDiscount(product);
1143
+ return _this4.productHasCustomerBoundDiscount(product);
965
1144
  });
966
1145
  }
967
1146
 
@@ -1024,7 +1203,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1024
1203
  var _evaluatePromotion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
1025
1204
  var _this$promotionEvalua,
1026
1205
  _this$promotionEvalua2,
1027
- _this3 = this;
1206
+ _this5 = this;
1028
1207
  var tempOrder, strategyConfigs, result, removeSet, _iterator3, _step3, reduce, _iterator6, _step6, _loop2, _iterator4, _step4, _loop, payload;
1029
1208
  return _regeneratorRuntime().wrap(function _callee7$(_context9) {
1030
1209
  while (1) switch (_context9.prev = _context9.next) {
@@ -1183,7 +1362,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1183
1362
  case 6:
1184
1363
  _context7.prev = 6;
1185
1364
  _context7.next = 9;
1186
- return _this3.giftSelectResolver({
1365
+ return _this5.giftSelectResolver({
1187
1366
  strategyId: addAction.strategyId,
1188
1367
  strategyName: addAction.strategyName,
1189
1368
  giftCount: addAction.giftCount,
@@ -1218,7 +1397,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1218
1397
  _context7.next = 26;
1219
1398
  break;
1220
1399
  }
1221
- linked = _this3.createLinkedProductAndBooking({
1400
+ linked = _this5.createLinkedProductAndBooking({
1222
1401
  product: gp,
1223
1402
  booking: booking
1224
1403
  });
@@ -1518,12 +1697,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1518
1697
  });
1519
1698
  }
1520
1699
  }, {
1521
- key: "clearTempOrderPointCardSnapshot",
1522
- value: function clearTempOrderPointCardSnapshot(tempOrder) {
1700
+ key: "clearTempOrderCustomerWalletSnapshots",
1701
+ value: function clearTempOrderCustomerWalletSnapshots(tempOrder) {
1523
1702
  var orderMetaList = normalizeOrderMetaList(tempOrder.order_meta_list);
1524
1703
  if (!orderMetaList) return;
1525
1704
  var nextOrderMetaList = _objectSpread({}, orderMetaList);
1526
1705
  delete nextOrderMetaList.point_cards_snapshot;
1706
+ delete nextOrderMetaList.virtual_currency_snapshot;
1527
1707
  if (Object.keys(nextOrderMetaList).length === 0) {
1528
1708
  delete tempOrder.order_meta_list;
1529
1709
  return;
@@ -1531,19 +1711,115 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1531
1711
  tempOrder.order_meta_list = nextOrderMetaList;
1532
1712
  }
1533
1713
  }, {
1534
- key: "writePointCardSnapshotFromPrepareConfig",
1535
- value: function writePointCardSnapshotFromPrepareConfig(params) {
1536
- var _tempOrder$customer_i, _params$orderId;
1714
+ key: "clearCustomerWalletState",
1715
+ value: function clearCustomerWalletState(tempOrder) {
1716
+ this.clearCustomerWalletRuntimeState();
1717
+ this.clearTempOrderCustomerWalletSnapshots(tempOrder);
1718
+ }
1719
+ }, {
1720
+ key: "clearCustomerWalletRuntimeState",
1721
+ value: function clearCustomerWalletRuntimeState() {
1722
+ this.customerWalletPrepareConfigEpoch += 1;
1723
+ this.pointCardSnapshotCodeCandidates.clear();
1724
+ this.store.availableWalletIds = [];
1725
+ this.store.virtualCurrencyList = [];
1726
+ }
1727
+ }, {
1728
+ key: "rememberPointCardSnapshotCodeCandidates",
1729
+ value: function rememberPointCardSnapshotCodeCandidates(value) {
1730
+ var _this6 = this;
1731
+ collectPointCardSnapshotCodeCandidates(value).forEach(function (_ref18) {
1732
+ var id = _ref18.id,
1733
+ code = _ref18.code;
1734
+ if (!_this6.pointCardSnapshotCodeCandidates.has(id)) {
1735
+ _this6.pointCardSnapshotCodeCandidates.set(id, code);
1736
+ }
1737
+ });
1738
+ }
1739
+ }, {
1740
+ key: "getRememberedPointCardSnapshotCodeCandidates",
1741
+ value: function getRememberedPointCardSnapshotCodeCandidates() {
1742
+ return _toConsumableArray(this.pointCardSnapshotCodeCandidates).map(function (_ref19) {
1743
+ var _ref20 = _slicedToArray(_ref19, 2),
1744
+ id = _ref20[0],
1745
+ code = _ref20[1];
1746
+ return {
1747
+ id: id,
1748
+ code: code
1749
+ };
1750
+ });
1751
+ }
1752
+ }, {
1753
+ key: "getPointCardSnapshotOrderIdentityKey",
1754
+ value: function getPointCardSnapshotOrderIdentityKey(identity) {
1755
+ if (identity !== null && identity !== void 0 && identity.externalSaleNumber) {
1756
+ return "external:".concat(identity.externalSaleNumber);
1757
+ }
1758
+ if ((identity === null || identity === void 0 ? void 0 : identity.orderId) !== undefined && identity.orderId !== null) {
1759
+ return "order:".concat(identity.orderId);
1760
+ }
1761
+ if (identity !== null && identity !== void 0 && identity.localId) return "local:".concat(identity.localId);
1762
+ if (identity !== null && identity !== void 0 && identity.orderNumber) return "number:".concat(identity.orderNumber);
1763
+ return '';
1764
+ }
1765
+ }, {
1766
+ key: "isPointCardSnapshotMergeContextCurrent",
1767
+ value: function isPointCardSnapshotMergeContextCurrent(context) {
1768
+ var _context$customerId, _this$store$tempOrder4, _this$store$tempOrder5;
1769
+ if (!context) return true;
1770
+ if (context.customerId !== undefined && String((_context$customerId = context.customerId) !== null && _context$customerId !== void 0 ? _context$customerId : '') !== String((_this$store$tempOrder4 = (_this$store$tempOrder5 = this.store.tempOrder) === null || _this$store$tempOrder5 === void 0 ? void 0 : _this$store$tempOrder5.customer_id) !== null && _this$store$tempOrder4 !== void 0 ? _this$store$tempOrder4 : '')) {
1771
+ return false;
1772
+ }
1773
+ var expectedOrderKey = this.getPointCardSnapshotOrderIdentityKey(context.orderIdentity);
1774
+ return !expectedOrderKey || expectedOrderKey === this.getPointCardSnapshotOrderIdentityKey(this.getOrderIdentity());
1775
+ }
1776
+ }, {
1777
+ key: "writeCustomerWalletSnapshotsFromPrepareConfig",
1778
+ value: function writeCustomerWalletSnapshotsFromPrepareConfig(params) {
1779
+ var _tempOrder$customer_i;
1537
1780
  var tempOrder = this.store.tempOrder;
1538
1781
  if (!tempOrder) return;
1539
1782
  if (String((_tempOrder$customer_i = tempOrder.customer_id) !== null && _tempOrder$customer_i !== void 0 ? _tempOrder$customer_i : '') !== String(params.customerId)) return;
1540
- var effectiveOrderId = (_params$orderId = params.orderId) !== null && _params$orderId !== void 0 ? _params$orderId : tempOrder.order_id;
1541
- if (hasPersistedOrderId(effectiveOrderId)) return;
1542
- tempOrder.order_meta_list = _objectSpread(_objectSpread({}, normalizeOrderMetaList(tempOrder.order_meta_list) || {}), {}, {
1543
- point_cards_snapshot: buildPointCardSnapshotFromWalletPassList(params.availableWalletPassList)
1783
+ var currentOrderMetaList = normalizeOrderMetaList(tempOrder.order_meta_list);
1784
+ var virtualCurrencyList = Array.isArray(params.virtualCurrencyList) ? params.virtualCurrencyList : [];
1785
+ var snapshotsWithExistingCodes = _mergePointCardSnapshotCodes(params.availableWalletPassList, currentOrderMetaList === null || currentOrderMetaList === void 0 ? void 0 : currentOrderMetaList.point_cards_snapshot);
1786
+ tempOrder.order_meta_list = _objectSpread(_objectSpread({}, currentOrderMetaList || {}), {}, {
1787
+ point_cards_snapshot: _mergePointCardSnapshotCodes(snapshotsWithExistingCodes, this.getRememberedPointCardSnapshotCodeCandidates()),
1788
+ virtual_currency_snapshot: buildVirtualCurrencySnapshotFromList(virtualCurrencyList)
1789
+ });
1790
+ this.store.availableWalletIds = _toConsumableArray(params.availableWalletIds);
1791
+ this.store.virtualCurrencyList = cloneDeep(virtualCurrencyList);
1792
+ this.persistTempOrder();
1793
+ this.saveDraftInBackground();
1794
+ }
1795
+
1796
+ /**
1797
+ * 将 Payment WalletPass 返回的实例 code 回填到当前订单 Snapshot。
1798
+ * 这里只按资产 ID 补空值,不新增卡、不覆盖 prepare/config 冻结的余额。
1799
+ */
1800
+ }, {
1801
+ key: "mergePointCardSnapshotCodes",
1802
+ value: function mergePointCardSnapshotCodes(walletPassList, context) {
1803
+ var tempOrder = this.store.tempOrder;
1804
+ var currentOrderMetaList = normalizeOrderMetaList(tempOrder === null || tempOrder === void 0 ? void 0 : tempOrder.order_meta_list);
1805
+ var currentSnapshots = (currentOrderMetaList === null || currentOrderMetaList === void 0 ? void 0 : currentOrderMetaList.point_cards_snapshot) || [];
1806
+ if (!tempOrder || !this.isPointCardSnapshotMergeContextCurrent(context)) {
1807
+ return currentSnapshots;
1808
+ }
1809
+ this.rememberPointCardSnapshotCodeCandidates(walletPassList);
1810
+ if (!currentSnapshots.length) return currentSnapshots;
1811
+ var nextSnapshots = _mergePointCardSnapshotCodes(currentSnapshots, this.getRememberedPointCardSnapshotCodeCandidates());
1812
+ var hasChanged = nextSnapshots.some(function (snapshot, index) {
1813
+ var _currentSnapshots$ind;
1814
+ return snapshot.code !== ((_currentSnapshots$ind = currentSnapshots[index]) === null || _currentSnapshots$ind === void 0 ? void 0 : _currentSnapshots$ind.code);
1815
+ });
1816
+ if (!hasChanged) return currentSnapshots;
1817
+ tempOrder.order_meta_list = _objectSpread(_objectSpread({}, currentOrderMetaList || {}), {}, {
1818
+ point_cards_snapshot: nextSnapshots
1544
1819
  });
1545
1820
  this.persistTempOrder();
1546
1821
  this.saveDraftInBackground();
1822
+ return nextSnapshots;
1547
1823
  }
1548
1824
  }, {
1549
1825
  key: "createExternalSaleNumber",
@@ -1645,15 +1921,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1645
1921
  }, {
1646
1922
  key: "extractOrderIdFromSubmitResult",
1647
1923
  value: function extractOrderIdFromSubmitResult(result) {
1648
- var _ref14, _ref15, _ref16, _result$data$order_id, _result$data, _result$data2;
1649
- return (_ref14 = (_ref15 = (_ref16 = (_result$data$order_id = result === null || result === void 0 || (_result$data = result.data) === null || _result$data === void 0 ? void 0 : _result$data.order_id) !== null && _result$data$order_id !== void 0 ? _result$data$order_id : result === null || result === void 0 ? void 0 : result.order_id) !== null && _ref16 !== void 0 ? _ref16 : result === null || result === void 0 || (_result$data2 = result.data) === null || _result$data2 === void 0 ? void 0 : _result$data2.id) !== null && _ref15 !== void 0 ? _ref15 : result === null || result === void 0 ? void 0 : result.id) !== null && _ref14 !== void 0 ? _ref14 : null;
1924
+ var _ref21, _ref22, _ref23, _result$data$order_id, _result$data, _result$data2;
1925
+ return (_ref21 = (_ref22 = (_ref23 = (_result$data$order_id = result === null || result === void 0 || (_result$data = result.data) === null || _result$data === void 0 ? void 0 : _result$data.order_id) !== null && _result$data$order_id !== void 0 ? _result$data$order_id : result === null || result === void 0 ? void 0 : result.order_id) !== null && _ref23 !== void 0 ? _ref23 : result === null || result === void 0 || (_result$data2 = result.data) === null || _result$data2 === void 0 ? void 0 : _result$data2.id) !== null && _ref22 !== void 0 ? _ref22 : result === null || result === void 0 ? void 0 : result.id) !== null && _ref21 !== void 0 ? _ref21 : null;
1650
1926
  }
1651
1927
  }, {
1652
1928
  key: "calculatePaymentEffectiveAmount",
1653
1929
  value: function calculatePaymentEffectiveAmount(payment) {
1654
- var _ref17, _payment$origin_amoun;
1930
+ var _ref24, _payment$origin_amoun;
1655
1931
  var amount = new Decimal(payment.amount || 0);
1656
- var originAmount = new Decimal((_ref17 = (_payment$origin_amoun = payment.origin_amount) !== null && _payment$origin_amoun !== void 0 ? _payment$origin_amoun : payment.amount) !== null && _ref17 !== void 0 ? _ref17 : 0);
1932
+ var originAmount = new Decimal((_ref24 = (_payment$origin_amoun = payment.origin_amount) !== null && _payment$origin_amoun !== void 0 ? _payment$origin_amoun : payment.amount) !== null && _ref24 !== void 0 ? _ref24 : 0);
1657
1933
  var serviceFee = new Decimal(payment.service_fee || 0);
1658
1934
  // TODO: 后端允许 amount 表示顾客实际支付总额后,移除这个兼容分支。
1659
1935
  var effectiveAmount = serviceFee.gt(0) && amount.eq(originAmount) ? amount.plus(serviceFee) : amount;
@@ -1663,23 +1939,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1663
1939
  }, {
1664
1940
  key: "calculatePaymentTotal",
1665
1941
  value: function calculatePaymentTotal(payments) {
1666
- var _this4 = this;
1942
+ var _this7 = this;
1667
1943
  return mapPaymentItemsToOrderPayments(payments, {
1668
1944
  includeVoided: false
1669
1945
  }).reduce(function (sum, payment) {
1670
1946
  if (!isPaidPaymentRecord(payment)) return sum;
1671
- return sum.plus(_this4.calculatePaymentEffectiveAmount(payment));
1947
+ return sum.plus(_this7.calculatePaymentEffectiveAmount(payment));
1672
1948
  }, new Decimal(0));
1673
1949
  }
1674
1950
  }, {
1675
1951
  key: "calculateOrderPaidPaymentTotal",
1676
1952
  value: function calculateOrderPaidPaymentTotal(payments) {
1677
- var _this5 = this;
1953
+ var _this8 = this;
1678
1954
  return mapPaymentItemsToOrderPayments(payments, {
1679
1955
  includeVoided: false
1680
1956
  }).reduce(function (sum, payment) {
1681
1957
  if (!isPaidPaymentRecord(payment)) return sum;
1682
- return sum.plus(_this5.calculatePaymentGapAmount(payment));
1958
+ return sum.plus(_this8.calculatePaymentGapAmount(payment));
1683
1959
  }, new Decimal(0));
1684
1960
  }
1685
1961
  }, {
@@ -1815,13 +2091,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1815
2091
  }, {
1816
2092
  key: "calculateDepositPaidAmount",
1817
2093
  value: function calculateDepositPaidAmount(payments) {
1818
- var _this6 = this;
2094
+ var _this9 = this;
1819
2095
  return (payments || []).reduce(function (sum, payment) {
1820
2096
  var paymentRecord = payment;
1821
2097
  if (!isPaidPaymentRecord(paymentRecord)) return sum;
1822
2098
  var isDepositPayment = paymentRecord.type === 'deposit' || paymentRecord.order_payment_type === 'deposit';
1823
2099
  if (!isDepositPayment) return sum;
1824
- return sum.plus(_this6.calculatePaymentGapAmount(paymentRecord));
2100
+ return sum.plus(_this9.calculatePaymentGapAmount(paymentRecord));
1825
2101
  }, new Decimal(0));
1826
2102
  }
1827
2103
  }, {
@@ -1858,28 +2134,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1858
2134
  }, {
1859
2135
  key: "getPaymentNumberDevicePrefixSync",
1860
2136
  value: function getPaymentNumberDevicePrefixSync() {
1861
- var _this7 = this;
2137
+ var _this10 = this;
1862
2138
  return resolvePaymentNumberDevicePrefixFromDeviceId(function (key) {
1863
- return _this7.getPaymentNumberAppData(key);
2139
+ return _this10.getPaymentNumberAppData(key);
1864
2140
  });
1865
2141
  }
1866
2142
  }, {
1867
2143
  key: "getPaymentNumberDevicePrefixAsync",
1868
2144
  value: function getPaymentNumberDevicePrefixAsync() {
1869
- var _this8 = this;
2145
+ var _this11 = this;
1870
2146
  return resolvePaymentNumberDevicePrefix(function (key) {
1871
- return _this8.getPaymentNumberAppData(key);
2147
+ return _this11.getPaymentNumberAppData(key);
1872
2148
  });
1873
2149
  }
1874
2150
  }, {
1875
2151
  key: "normalizePaymentSource",
1876
2152
  value: function normalizePaymentSource(payment, options) {
1877
- var _ref18, _paymentRecord$origin;
2153
+ var _ref25, _paymentRecord$origin;
1878
2154
  var paymentRecord = payment;
1879
2155
  var metadata = paymentRecord.metadata && _typeof(paymentRecord.metadata) === 'object' ? _objectSpread({}, paymentRecord.metadata) : {};
1880
2156
  var normalized = ensureOrderPaymentNumber(_objectSpread(_objectSpread({}, paymentRecord), {}, {
1881
2157
  metadata: metadata,
1882
- origin_amount: (_ref18 = (_paymentRecord$origin = paymentRecord.origin_amount) !== null && _paymentRecord$origin !== void 0 ? _paymentRecord$origin : paymentRecord.amount) !== null && _ref18 !== void 0 ? _ref18 : '0.00'
2158
+ origin_amount: (_ref25 = (_paymentRecord$origin = paymentRecord.origin_amount) !== null && _paymentRecord$origin !== void 0 ? _paymentRecord$origin : paymentRecord.amount) !== null && _ref25 !== void 0 ? _ref25 : '0.00'
1883
2159
  }), (options === null || options === void 0 ? void 0 : options.devicePrefix) || this.getPaymentNumberDevicePrefixSync(), createUuidV4);
1884
2160
  if (paymentRecord.status !== undefined) {
1885
2161
  normalized.status = paymentRecord.status;
@@ -1998,16 +2274,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1998
2274
  }, {
1999
2275
  key: "calculatePaidPaymentSummary",
2000
2276
  value: function calculatePaidPaymentSummary(payments) {
2001
- var _this9 = this;
2277
+ var _this12 = this;
2002
2278
  return (payments || []).reduce(function (summary, payment) {
2003
2279
  var paymentRecord = payment;
2004
2280
  if (!isPaidPaymentRecord(paymentRecord)) return summary;
2005
2281
  return {
2006
2282
  customerPaidAmount: summary.customerPaidAmount.plus(paymentRecord.amount || 0),
2007
- orderPaidAmount: summary.orderPaidAmount.plus(_this9.calculatePaymentOrderAmount(paymentRecord)),
2008
- gapPaidAmount: summary.gapPaidAmount.plus(_this9.calculatePaymentGapAmount(paymentRecord)),
2009
- payServiceChargeAmount: summary.payServiceChargeAmount.plus(_this9.calculatePaymentServiceFee(paymentRecord)),
2010
- roundingAmount: summary.roundingAmount.plus(_this9.calculatePaymentRoundingAmount(paymentRecord))
2283
+ orderPaidAmount: summary.orderPaidAmount.plus(_this12.calculatePaymentOrderAmount(paymentRecord)),
2284
+ gapPaidAmount: summary.gapPaidAmount.plus(_this12.calculatePaymentGapAmount(paymentRecord)),
2285
+ payServiceChargeAmount: summary.payServiceChargeAmount.plus(_this12.calculatePaymentServiceFee(paymentRecord)),
2286
+ roundingAmount: summary.roundingAmount.plus(_this12.calculatePaymentRoundingAmount(paymentRecord))
2011
2287
  };
2012
2288
  }, {
2013
2289
  customerPaidAmount: new Decimal(0),
@@ -2214,15 +2490,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2214
2490
  }, {
2215
2491
  key: "normalizeFingerprintValue",
2216
2492
  value: function normalizeFingerprintValue(value) {
2217
- var _this10 = this;
2493
+ var _this13 = this;
2218
2494
  if (Array.isArray(value)) {
2219
2495
  return value.map(function (item) {
2220
- return _this10.normalizeFingerprintValue(item);
2496
+ return _this13.normalizeFingerprintValue(item);
2221
2497
  });
2222
2498
  }
2223
2499
  if (!value || _typeof(value) !== 'object') return value !== null && value !== void 0 ? value : '';
2224
2500
  return Object.keys(value).sort().reduce(function (result, key) {
2225
- result[key] = _this10.normalizeFingerprintValue(value[key]);
2501
+ result[key] = _this13.normalizeFingerprintValue(value[key]);
2226
2502
  return result;
2227
2503
  }, {});
2228
2504
  }
@@ -2235,16 +2511,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2235
2511
  _product$payment_pric,
2236
2512
  _sku$code,
2237
2513
  _sku$barcode,
2238
- _ref19,
2514
+ _ref26,
2239
2515
  _sku$variant_id,
2240
- _this11 = this;
2516
+ _this14 = this;
2241
2517
  var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
2242
2518
  var metadata = (product === null || product === void 0 ? void 0 : product.metadata) || {};
2243
2519
  var discountTypes = ((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
2244
2520
  var _discount$type;
2245
2521
  return (_discount$type = discount === null || discount === void 0 ? void 0 : discount.type) !== null && _discount$type !== void 0 ? _discount$type : discount === null || discount === void 0 ? void 0 : discount.tag;
2246
2522
  });
2247
- var extensionType = (product === null || product === void 0 ? void 0 : product.extension_type) || (discountTypes.includes('good_pass') ? 'good_pass' : 'normal');
2523
+ var fullCoveragePassType = discountTypes.find(function (type) {
2524
+ return ['entitlement_pass', 'good_pass'].includes(type);
2525
+ });
2526
+ var extensionType = (product === null || product === void 0 ? void 0 : product.extension_type) || fullCoveragePassType || 'normal';
2248
2527
  return {
2249
2528
  product_id: (_product$product_id2 = product === null || product === void 0 ? void 0 : product.product_id) !== null && _product$product_id2 !== void 0 ? _product$product_id2 : null,
2250
2529
  product_variant_id: (_product$product_vari = product === null || product === void 0 ? void 0 : product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : null,
@@ -2262,37 +2541,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2262
2541
  product_sku: this.normalizeFingerprintValue({
2263
2542
  code: (_sku$code = sku.code) !== null && _sku$code !== void 0 ? _sku$code : '',
2264
2543
  barcode: (_sku$barcode = sku.barcode) !== null && _sku$barcode !== void 0 ? _sku$barcode : '',
2265
- variant_id: (_ref19 = (_sku$variant_id = sku.variant_id) !== null && _sku$variant_id !== void 0 ? _sku$variant_id : product === null || product === void 0 ? void 0 : product.product_variant_id) !== null && _ref19 !== void 0 ? _ref19 : 0,
2544
+ variant_id: (_ref26 = (_sku$variant_id = sku.variant_id) !== null && _sku$variant_id !== void 0 ? _sku$variant_id : product === null || product === void 0 ? void 0 : product.product_variant_id) !== null && _ref26 !== void 0 ? _ref26 : 0,
2266
2545
  variant: sku.variant || [],
2267
2546
  option: getProductSkuOptions(product || {}).map(function (option) {
2268
- var _ref20, _option$id, _option$option_group_, _ref21, _option$option_group_2, _option$num, _option$add_price;
2547
+ var _ref27, _option$id, _option$option_group_, _ref28, _option$option_group_2, _option$num, _option$add_price;
2269
2548
  return {
2270
- id: (_ref20 = (_option$id = option === null || option === void 0 ? void 0 : option.id) !== null && _option$id !== void 0 ? _option$id : option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _ref20 !== void 0 ? _ref20 : null,
2549
+ id: (_ref27 = (_option$id = option === null || option === void 0 ? void 0 : option.id) !== null && _option$id !== void 0 ? _option$id : option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _ref27 !== void 0 ? _ref27 : null,
2271
2550
  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,
2272
- option_group_item_id: (_ref21 = (_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 && _ref21 !== void 0 ? _ref21 : null,
2551
+ option_group_item_id: (_ref28 = (_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 && _ref28 !== void 0 ? _ref28 : null,
2273
2552
  num: Number((_option$num = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num !== void 0 ? _option$num : 1) || 1,
2274
- add_price: _this11.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)
2553
+ add_price: _this14.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)
2275
2554
  };
2276
2555
  })
2277
2556
  }),
2278
2557
  product_bundle: this.normalizeFingerprintValue(((product === null || product === void 0 ? void 0 : product.product_bundle) || []).map(function (bundle) {
2279
- var _ref22, _ref23, _bundle$bundle_produc, _ref24, _bundle$bundle_varian, _bundle$num, _bundle$price_type, _bundle$price_type_ex;
2558
+ var _ref29, _ref30, _bundle$bundle_produc, _ref31, _bundle$bundle_varian, _bundle$num, _bundle$price_type, _bundle$price_type_ex;
2280
2559
  return {
2281
- bundle_product_id: (_ref22 = (_ref23 = (_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 && _ref23 !== void 0 ? _ref23 : bundle === null || bundle === void 0 ? void 0 : bundle.product_id) !== null && _ref22 !== void 0 ? _ref22 : null,
2282
- bundle_variant_id: (_ref24 = (_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 && _ref24 !== void 0 ? _ref24 : 0,
2560
+ bundle_product_id: (_ref29 = (_ref30 = (_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 && _ref30 !== void 0 ? _ref30 : bundle === null || bundle === void 0 ? void 0 : bundle.product_id) !== null && _ref29 !== void 0 ? _ref29 : null,
2561
+ bundle_variant_id: (_ref31 = (_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 && _ref31 !== void 0 ? _ref31 : 0,
2283
2562
  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),
2284
- price: _this11.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.price),
2285
- bundle_selling_price: _this11.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.bundle_selling_price),
2563
+ price: _this14.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.price),
2564
+ bundle_selling_price: _this14.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.bundle_selling_price),
2286
2565
  price_type: (_bundle$price_type = bundle === null || bundle === void 0 ? void 0 : bundle.price_type) !== null && _bundle$price_type !== void 0 ? _bundle$price_type : '',
2287
2566
  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 : ''
2288
2567
  };
2289
2568
  })),
2290
2569
  discount_list: this.normalizeFingerprintValue(((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
2291
- var _ref25, _discount$type2, _ref26, _ref27, _discount$discount_id, _discount$discount;
2570
+ var _ref32, _discount$type2, _ref33, _ref34, _discount$discount_id, _discount$discount;
2292
2571
  return {
2293
- type: (_ref25 = (_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 && _ref25 !== void 0 ? _ref25 : '',
2294
- discount_id: (_ref26 = (_ref27 = (_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 && _ref27 !== void 0 ? _ref27 : discount === null || discount === void 0 || (_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) !== null && _ref26 !== void 0 ? _ref26 : null,
2295
- amount: _this11.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
2572
+ type: (_ref32 = (_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 && _ref32 !== void 0 ? _ref32 : '',
2573
+ discount_id: (_ref33 = (_ref34 = (_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 && _ref34 !== void 0 ? _ref34 : discount === null || discount === void 0 || (_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) !== null && _ref33 !== void 0 ? _ref33 : null,
2574
+ amount: _this14.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
2296
2575
  };
2297
2576
  }))
2298
2577
  };
@@ -2300,9 +2579,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2300
2579
  }, {
2301
2580
  key: "buildOrderProductsFingerprint",
2302
2581
  value: function buildOrderProductsFingerprint(products) {
2303
- var _this12 = this;
2582
+ var _this15 = this;
2304
2583
  var items = (products || []).map(function (product) {
2305
- return _this12.buildProductFingerprintItem(product);
2584
+ return _this15.buildProductFingerprintItem(product);
2306
2585
  });
2307
2586
  items.sort(function (left, right) {
2308
2587
  return JSON.stringify(left).localeCompare(JSON.stringify(right));
@@ -2315,30 +2594,33 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2315
2594
  var _product$product_id3,
2316
2595
  _product$product_vari2,
2317
2596
  _product$num2,
2318
- _ref28,
2597
+ _ref35,
2319
2598
  _metadata$unique_iden,
2320
2599
  _metadata$price_overr,
2321
2600
  _metadata$is_manual_d,
2322
2601
  _metadata$product_dis,
2323
2602
  _sku$code2,
2324
2603
  _sku$barcode2,
2325
- _ref29,
2604
+ _ref36,
2326
2605
  _sku$variant_id2,
2327
- _this13 = this;
2606
+ _this16 = this;
2328
2607
  var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
2329
2608
  var metadata = (product === null || product === void 0 ? void 0 : product.metadata) || {};
2330
2609
  var discountTypes = ((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
2331
2610
  var _discount$type3;
2332
2611
  return (_discount$type3 = discount === null || discount === void 0 ? void 0 : discount.type) !== null && _discount$type3 !== void 0 ? _discount$type3 : discount === null || discount === void 0 ? void 0 : discount.tag;
2333
2612
  });
2334
- var extensionType = (product === null || product === void 0 ? void 0 : product.extension_type) || (discountTypes.includes('good_pass') ? 'good_pass' : 'normal');
2613
+ var fullCoveragePassType = discountTypes.find(function (type) {
2614
+ return ['entitlement_pass', 'good_pass'].includes(type);
2615
+ });
2616
+ var extensionType = (product === null || product === void 0 ? void 0 : product.extension_type) || fullCoveragePassType || 'normal';
2335
2617
  return {
2336
2618
  product_id: (_product$product_id3 = product === null || product === void 0 ? void 0 : product.product_id) !== null && _product$product_id3 !== void 0 ? _product$product_id3 : null,
2337
2619
  product_variant_id: (_product$product_vari2 = product === null || product === void 0 ? void 0 : product.product_variant_id) !== null && _product$product_vari2 !== void 0 ? _product$product_vari2 : null,
2338
2620
  extension_type: extensionType,
2339
2621
  num: getSafeProductNum((_product$num2 = product === null || product === void 0 ? void 0 : product.num) !== null && _product$num2 !== void 0 ? _product$num2 : product === null || product === void 0 ? void 0 : product.product_quantity),
2340
2622
  metadata: {
2341
- unique_identification_number: (_ref28 = (_metadata$unique_iden = metadata.unique_identification_number) !== null && _metadata$unique_iden !== void 0 ? _metadata$unique_iden : product === null || product === void 0 ? void 0 : product.unique_identification_number) !== null && _ref28 !== void 0 ? _ref28 : '',
2623
+ unique_identification_number: (_ref35 = (_metadata$unique_iden = metadata.unique_identification_number) !== null && _metadata$unique_iden !== void 0 ? _metadata$unique_iden : product === null || product === void 0 ? void 0 : product.unique_identification_number) !== null && _ref35 !== void 0 ? _ref35 : '',
2342
2624
  price_override: (_metadata$price_overr = metadata.price_override) !== null && _metadata$price_overr !== void 0 ? _metadata$price_overr : '',
2343
2625
  is_manual_discount: (_metadata$is_manual_d = metadata.is_manual_discount) !== null && _metadata$is_manual_d !== void 0 ? _metadata$is_manual_d : '',
2344
2626
  product_discount_reason: (_metadata$product_dis = metadata.product_discount_reason) !== null && _metadata$product_dis !== void 0 ? _metadata$product_dis : ''
@@ -2346,47 +2628,47 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2346
2628
  product_sku: this.normalizeFingerprintValue({
2347
2629
  code: (_sku$code2 = sku.code) !== null && _sku$code2 !== void 0 ? _sku$code2 : '',
2348
2630
  barcode: (_sku$barcode2 = sku.barcode) !== null && _sku$barcode2 !== void 0 ? _sku$barcode2 : '',
2349
- variant_id: (_ref29 = (_sku$variant_id2 = sku.variant_id) !== null && _sku$variant_id2 !== void 0 ? _sku$variant_id2 : product === null || product === void 0 ? void 0 : product.product_variant_id) !== null && _ref29 !== void 0 ? _ref29 : 0,
2631
+ variant_id: (_ref36 = (_sku$variant_id2 = sku.variant_id) !== null && _sku$variant_id2 !== void 0 ? _sku$variant_id2 : product === null || product === void 0 ? void 0 : product.product_variant_id) !== null && _ref36 !== void 0 ? _ref36 : 0,
2350
2632
  variant: sku.variant || [],
2351
2633
  option: getProductSkuOptions(product || {}).map(function (option) {
2352
- var _ref30, _option$id2, _option$option_group_3, _ref31, _option$option_group_4, _option$num2, _option$add_price2;
2634
+ var _ref37, _option$id2, _option$option_group_3, _ref38, _option$option_group_4, _option$num2, _option$add_price2;
2353
2635
  return {
2354
- id: (_ref30 = (_option$id2 = option === null || option === void 0 ? void 0 : option.id) !== null && _option$id2 !== void 0 ? _option$id2 : option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _ref30 !== void 0 ? _ref30 : null,
2636
+ id: (_ref37 = (_option$id2 = option === null || option === void 0 ? void 0 : option.id) !== null && _option$id2 !== void 0 ? _option$id2 : option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _ref37 !== void 0 ? _ref37 : null,
2355
2637
  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,
2356
- option_group_item_id: (_ref31 = (_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 && _ref31 !== void 0 ? _ref31 : null,
2638
+ option_group_item_id: (_ref38 = (_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 && _ref38 !== void 0 ? _ref38 : null,
2357
2639
  num: Number((_option$num2 = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num2 !== void 0 ? _option$num2 : 1) || 1,
2358
- add_price: _this13.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)
2640
+ add_price: _this16.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)
2359
2641
  };
2360
2642
  })
2361
2643
  }),
2362
2644
  product_bundle: this.normalizeFingerprintValue(((product === null || product === void 0 ? void 0 : product.product_bundle) || []).map(function (bundle) {
2363
- var _ref32, _bundle$bundle_id, _ref33, _bundle$bundle_group_, _ref34, _ref35, _bundle$bundle_produc2, _ref36, _bundle$bundle_varian2, _bundle$num2, _bundle$price_type2, _bundle$price_type_ex2;
2645
+ var _ref39, _bundle$bundle_id, _ref40, _bundle$bundle_group_, _ref41, _ref42, _bundle$bundle_produc2, _ref43, _bundle$bundle_varian2, _bundle$num2, _bundle$price_type2, _bundle$price_type_ex2;
2364
2646
  return {
2365
- bundle_id: (_ref32 = (_bundle$bundle_id = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_id) !== null && _bundle$bundle_id !== void 0 ? _bundle$bundle_id : bundle === null || bundle === void 0 ? void 0 : bundle.id) !== null && _ref32 !== void 0 ? _ref32 : null,
2366
- bundle_group_id: (_ref33 = (_bundle$bundle_group_ = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_group_id) !== null && _bundle$bundle_group_ !== void 0 ? _bundle$bundle_group_ : bundle === null || bundle === void 0 ? void 0 : bundle.group_id) !== null && _ref33 !== void 0 ? _ref33 : null,
2367
- bundle_product_id: (_ref34 = (_ref35 = (_bundle$bundle_produc2 = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_product_id) !== null && _bundle$bundle_produc2 !== void 0 ? _bundle$bundle_produc2 : bundle === null || bundle === void 0 ? void 0 : bundle._bundle_product_id) !== null && _ref35 !== void 0 ? _ref35 : bundle === null || bundle === void 0 ? void 0 : bundle.product_id) !== null && _ref34 !== void 0 ? _ref34 : null,
2368
- bundle_variant_id: (_ref36 = (_bundle$bundle_varian2 = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_variant_id) !== null && _bundle$bundle_varian2 !== void 0 ? _bundle$bundle_varian2 : bundle === null || bundle === void 0 ? void 0 : bundle.product_variant_id) !== null && _ref36 !== void 0 ? _ref36 : 0,
2647
+ bundle_id: (_ref39 = (_bundle$bundle_id = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_id) !== null && _bundle$bundle_id !== void 0 ? _bundle$bundle_id : bundle === null || bundle === void 0 ? void 0 : bundle.id) !== null && _ref39 !== void 0 ? _ref39 : null,
2648
+ bundle_group_id: (_ref40 = (_bundle$bundle_group_ = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_group_id) !== null && _bundle$bundle_group_ !== void 0 ? _bundle$bundle_group_ : bundle === null || bundle === void 0 ? void 0 : bundle.group_id) !== null && _ref40 !== void 0 ? _ref40 : null,
2649
+ bundle_product_id: (_ref41 = (_ref42 = (_bundle$bundle_produc2 = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_product_id) !== null && _bundle$bundle_produc2 !== void 0 ? _bundle$bundle_produc2 : bundle === null || bundle === void 0 ? void 0 : bundle._bundle_product_id) !== null && _ref42 !== void 0 ? _ref42 : bundle === null || bundle === void 0 ? void 0 : bundle.product_id) !== null && _ref41 !== void 0 ? _ref41 : null,
2650
+ bundle_variant_id: (_ref43 = (_bundle$bundle_varian2 = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_variant_id) !== null && _bundle$bundle_varian2 !== void 0 ? _bundle$bundle_varian2 : bundle === null || bundle === void 0 ? void 0 : bundle.product_variant_id) !== null && _ref43 !== void 0 ? _ref43 : 0,
2369
2651
  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),
2370
2652
  price_type: (_bundle$price_type2 = bundle === null || bundle === void 0 ? void 0 : bundle.price_type) !== null && _bundle$price_type2 !== void 0 ? _bundle$price_type2 : '',
2371
2653
  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 : '',
2372
- option: _this13.normalizeFingerprintValue(((bundle === null || bundle === void 0 ? void 0 : bundle.option) || []).map(function (option) {
2373
- var _ref37, _option$id3, _option$option_group_5, _ref38, _option$option_group_6, _option$num3, _option$add_price3;
2654
+ option: _this16.normalizeFingerprintValue(((bundle === null || bundle === void 0 ? void 0 : bundle.option) || []).map(function (option) {
2655
+ var _ref44, _option$id3, _option$option_group_5, _ref45, _option$option_group_6, _option$num3, _option$add_price3;
2374
2656
  return {
2375
- id: (_ref37 = (_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 && _ref37 !== void 0 ? _ref37 : null,
2657
+ id: (_ref44 = (_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 && _ref44 !== void 0 ? _ref44 : null,
2376
2658
  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,
2377
- option_group_item_id: (_ref38 = (_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 && _ref38 !== void 0 ? _ref38 : null,
2659
+ option_group_item_id: (_ref45 = (_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 && _ref45 !== void 0 ? _ref45 : null,
2378
2660
  num: Number((_option$num3 = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num3 !== void 0 ? _option$num3 : 1) || 1,
2379
- add_price: _this13.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)
2661
+ add_price: _this16.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)
2380
2662
  };
2381
2663
  }))
2382
2664
  };
2383
2665
  })),
2384
2666
  discount_list: this.normalizeFingerprintValue(((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
2385
- var _ref39, _discount$type4, _ref40, _ref41, _discount$discount_id2, _discount$discount2;
2667
+ var _ref46, _discount$type4, _ref47, _ref48, _discount$discount_id2, _discount$discount2;
2386
2668
  return {
2387
- type: (_ref39 = (_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 && _ref39 !== void 0 ? _ref39 : '',
2388
- discount_id: (_ref40 = (_ref41 = (_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 && _ref41 !== void 0 ? _ref41 : discount === null || discount === void 0 || (_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.resource_id) !== null && _ref40 !== void 0 ? _ref40 : null,
2389
- amount: _this13.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
2669
+ type: (_ref46 = (_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 && _ref46 !== void 0 ? _ref46 : '',
2670
+ discount_id: (_ref47 = (_ref48 = (_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 && _ref48 !== void 0 ? _ref48 : discount === null || discount === void 0 || (_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.resource_id) !== null && _ref47 !== void 0 ? _ref47 : null,
2671
+ amount: _this16.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
2390
2672
  };
2391
2673
  }))
2392
2674
  };
@@ -2394,9 +2676,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2394
2676
  }, {
2395
2677
  key: "buildOrderProductsStructuralFingerprint",
2396
2678
  value: function buildOrderProductsStructuralFingerprint(products) {
2397
- var _this14 = this;
2679
+ var _this17 = this;
2398
2680
  var items = (products || []).map(function (product) {
2399
- return _this14.buildProductStructuralFingerprintItem(product);
2681
+ return _this17.buildProductStructuralFingerprintItem(product);
2400
2682
  });
2401
2683
  items.sort(function (left, right) {
2402
2684
  return JSON.stringify(left).localeCompare(JSON.stringify(right));
@@ -2406,8 +2688,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2406
2688
  }, {
2407
2689
  key: "getManualDepositOverride",
2408
2690
  value: function getManualDepositOverride(tempOrder) {
2409
- var _tempOrder$_extend3;
2410
- var override = (_tempOrder$_extend3 = tempOrder._extend) === null || _tempOrder$_extend3 === void 0 ? void 0 : _tempOrder$_extend3.manualDepositOverride;
2691
+ var _tempOrder$_extend4;
2692
+ var override = (_tempOrder$_extend4 = tempOrder._extend) === null || _tempOrder$_extend4 === void 0 ? void 0 : _tempOrder$_extend4.manualDepositOverride;
2411
2693
  if (!override || _typeof(override) !== 'object') return null;
2412
2694
  if (typeof override.amount !== 'string') return null;
2413
2695
  if (typeof override.productStructuralFingerprint !== 'string') return null;
@@ -2426,16 +2708,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2426
2708
  }, {
2427
2709
  key: "clearManualDepositOverride",
2428
2710
  value: function clearManualDepositOverride(tempOrder) {
2429
- var _tempOrder$_extend4;
2430
- if (!((_tempOrder$_extend4 = tempOrder._extend) !== null && _tempOrder$_extend4 !== void 0 && _tempOrder$_extend4.manualDepositOverride)) return;
2711
+ var _tempOrder$_extend5;
2712
+ if (!((_tempOrder$_extend5 = tempOrder._extend) !== null && _tempOrder$_extend5 !== void 0 && _tempOrder$_extend5.manualDepositOverride)) return;
2431
2713
  tempOrder._extend = _objectSpread({}, tempOrder._extend);
2432
2714
  delete tempOrder._extend.manualDepositOverride;
2433
2715
  }
2434
2716
  }, {
2435
2717
  key: "getOriginalSalesSnapshot",
2436
2718
  value: function getOriginalSalesSnapshot(tempOrder) {
2437
- var _tempOrder$_extend5;
2438
- var snapshot = (_tempOrder$_extend5 = tempOrder._extend) === null || _tempOrder$_extend5 === void 0 ? void 0 : _tempOrder$_extend5.originalSalesSnapshot;
2719
+ var _tempOrder$_extend6;
2720
+ var snapshot = (_tempOrder$_extend6 = tempOrder._extend) === null || _tempOrder$_extend6 === void 0 ? void 0 : _tempOrder$_extend6.originalSalesSnapshot;
2439
2721
  if (!snapshot || _typeof(snapshot) !== 'object') return null;
2440
2722
  if (typeof snapshot.productFingerprint !== 'string') return null;
2441
2723
  return snapshot;
@@ -2639,6 +2921,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2639
2921
  var freshTempOrder = this.createDefaultTempOrderInstance();
2640
2922
  this.ensureExternalSaleNumber(freshTempOrder);
2641
2923
  this.store.tempOrder = freshTempOrder;
2924
+ this.clearCustomerWalletRuntimeState();
2642
2925
  this.store.summary = createEmptySummary();
2643
2926
  this.store.lastOrderInfo = undefined;
2644
2927
  this.store.syncState = undefined;
@@ -2671,32 +2954,33 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2671
2954
  ensureIdentity: false
2672
2955
  });
2673
2956
  this.store.tempOrder = nextTempOrder;
2957
+ this.clearCustomerWalletRuntimeState();
2674
2958
  if (!((options === null || options === void 0 ? void 0 : options.recalculateSummary) !== false)) {
2675
- _context13.next = 10;
2959
+ _context13.next = 11;
2676
2960
  break;
2677
2961
  }
2678
- _context13.next = 8;
2962
+ _context13.next = 9;
2679
2963
  return this.recalculateSummary({
2680
2964
  createIfMissing: false
2681
2965
  });
2682
- case 8:
2683
- _context13.next = 11;
2966
+ case 9:
2967
+ _context13.next = 12;
2684
2968
  break;
2685
- case 10:
2686
- this.store.summary = createEmptySummary();
2687
2969
  case 11:
2970
+ this.store.summary = createEmptySummary();
2971
+ case 12:
2688
2972
  if ((options === null || options === void 0 ? void 0 : options.persist) !== false) {
2689
2973
  this.persistTempOrder();
2690
2974
  }
2691
2975
  if (!(options !== null && options !== void 0 && options.saveDraft)) {
2692
- _context13.next = 15;
2976
+ _context13.next = 16;
2693
2977
  break;
2694
2978
  }
2695
- _context13.next = 15;
2979
+ _context13.next = 16;
2696
2980
  return this.saveDraft();
2697
- case 15:
2698
- return _context13.abrupt("return", nextTempOrder);
2699
2981
  case 16:
2982
+ return _context13.abrupt("return", nextTempOrder);
2983
+ case 17:
2700
2984
  case "end":
2701
2985
  return _context13.stop();
2702
2986
  }
@@ -2710,13 +2994,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2710
2994
  }, {
2711
2995
  key: "getOrderIdentity",
2712
2996
  value: function getOrderIdentity() {
2713
- var _ref42, _ref43, _tempOrder$order_id, _tempOrder$_extend6;
2997
+ var _ref49, _ref50, _tempOrder$order_id, _tempOrder$_extend7;
2714
2998
  var tempOrder = this.store.tempOrder;
2715
2999
  if (!tempOrder) return null;
2716
3000
  var lastOrderInfo = this.store.lastOrderInfo || {};
2717
- var orderId = (_ref42 = (_ref43 = (_tempOrder$order_id = tempOrder.order_id) !== null && _tempOrder$order_id !== void 0 ? _tempOrder$order_id : lastOrderInfo.order_id) !== null && _ref43 !== void 0 ? _ref43 : lastOrderInfo.id) !== null && _ref42 !== void 0 ? _ref42 : null;
3001
+ var orderId = (_ref49 = (_ref50 = (_tempOrder$order_id = tempOrder.order_id) !== null && _tempOrder$order_id !== void 0 ? _tempOrder$order_id : lastOrderInfo.order_id) !== null && _ref50 !== void 0 ? _ref50 : lastOrderInfo.id) !== null && _ref49 !== void 0 ? _ref49 : null;
2718
3002
  return {
2719
- localId: this.cacheId || ((_tempOrder$_extend6 = tempOrder._extend) === null || _tempOrder$_extend6 === void 0 ? void 0 : _tempOrder$_extend6.localId),
3003
+ localId: this.cacheId || ((_tempOrder$_extend7 = tempOrder._extend) === null || _tempOrder$_extend7 === void 0 ? void 0 : _tempOrder$_extend7.localId),
2720
3004
  orderId: orderId,
2721
3005
  externalSaleNumber: tempOrder.external_sale_number || lastOrderInfo.external_sale_number || '',
2722
3006
  orderNumber: tempOrder.order_number || lastOrderInfo.order_number || '',
@@ -2846,9 +3130,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2846
3130
  }, {
2847
3131
  key: "sanitizeTempOrderProducts",
2848
3132
  value: function sanitizeTempOrderProducts(tempOrder) {
2849
- var _this15 = this;
3133
+ var _this18 = this;
2850
3134
  tempOrder.products = (tempOrder.products || []).map(function (product) {
2851
- return _this15.sanitizeOrderProductForTempOrder(_this15.normalizeVirtualSettlementProductIfEnabled(product));
3135
+ return _this18.sanitizeOrderProductForTempOrder(_this18.normalizeVirtualSettlementProductIfEnabled(product));
2852
3136
  });
2853
3137
  this.syncTempOrderSettlementState(tempOrder);
2854
3138
  ensureUniqueProductLineUids(tempOrder);
@@ -2869,8 +3153,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2869
3153
  }, {
2870
3154
  key: "repairDuplicateProductLineIdentities",
2871
3155
  value: function repairDuplicateProductLineIdentities(tempOrder) {
2872
- var _tempOrder$_extend7;
2873
- var result = repairDuplicateOrderProductLineIdentities(tempOrder.products, (_tempOrder$_extend7 = tempOrder._extend) === null || _tempOrder$_extend7 === void 0 ? void 0 : _tempOrder$_extend7.productsByUid);
3156
+ var _tempOrder$_extend8;
3157
+ var result = repairDuplicateOrderProductLineIdentities(tempOrder.products, (_tempOrder$_extend8 = tempOrder._extend) === null || _tempOrder$_extend8 === void 0 ? void 0 : _tempOrder$_extend8.productsByUid);
2874
3158
  if (!result.repairs.length) return;
2875
3159
  tempOrder.products = result.products;
2876
3160
  if (result.productsByUid) {
@@ -2884,11 +3168,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2884
3168
  }, {
2885
3169
  key: "captureProductRuntime",
2886
3170
  value: function captureProductRuntime(tempOrder, rawProduct, normalizedProduct, existedUid) {
2887
- var _extend$productsByUid, _ref44, _rawProduct$_origin;
3171
+ var _extend$productsByUid, _ref51, _rawProduct$_origin;
2888
3172
  var uid = existedUid || this.getProductUid(normalizedProduct);
2889
3173
  var extend = this.ensureExtend(tempOrder);
2890
3174
  var existed = ((_extend$productsByUid = extend.productsByUid) === null || _extend$productsByUid === void 0 ? void 0 : _extend$productsByUid[uid]) || {};
2891
- var origin = (_ref44 = (_rawProduct$_origin = rawProduct._origin) !== null && _rawProduct$_origin !== void 0 ? _rawProduct$_origin : normalizedProduct._origin) !== null && _ref44 !== void 0 ? _ref44 : existed.origin;
3175
+ var origin = (_ref51 = (_rawProduct$_origin = rawProduct._origin) !== null && _rawProduct$_origin !== void 0 ? _rawProduct$_origin : normalizedProduct._origin) !== null && _ref51 !== void 0 ? _ref51 : existed.origin;
2892
3176
  extend.productsByUid[uid] = _objectSpread(_objectSpread({}, existed), origin !== undefined ? {
2893
3177
  origin: origin
2894
3178
  } : {});
@@ -2968,7 +3252,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2968
3252
  }, {
2969
3253
  key: "syncLinkedBookingHoldersToProducts",
2970
3254
  value: function syncLinkedBookingHoldersToProducts(tempOrder) {
2971
- var _this16 = this;
3255
+ var _this19 = this;
2972
3256
  var bookings = tempOrder.bookings || [];
2973
3257
  var products = tempOrder.products || [];
2974
3258
  if (!bookings.length || !products.length) return;
@@ -2993,7 +3277,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2993
3277
  var bookingUid = product.booking_uid || ((_product$metadata4 = product.metadata) === null || _product$metadata4 === void 0 ? void 0 : _product$metadata4.booking_uid);
2994
3278
  var linkedBooking = (productUid !== undefined && productUid !== null && String(productUid) !== '' ? bookingByProductUid.get(String(productUid)) : undefined) || (bookingUid !== undefined && bookingUid !== null && String(bookingUid) !== '' ? bookingByBookingUid.get(String(bookingUid)) : undefined);
2995
3279
  if (linkedBooking) {
2996
- _this16.setProductHolderFromBooking(product, linkedBooking);
3280
+ _this19.setProductHolderFromBooking(product, linkedBooking);
2997
3281
  }
2998
3282
  });
2999
3283
  }
@@ -3031,7 +3315,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3031
3315
  }, {
3032
3316
  key: "buildTempOrderHolderFromBookings",
3033
3317
  value: function buildTempOrderHolderFromBookings(tempOrder) {
3034
- var _baseHolder$customer_, _baseHolder, _ref45, _baseHolder$form_id, _baseHolder2, _tempOrder$holder2, _baseHolder3, _this$otherParams2;
3318
+ var _baseHolder$customer_, _baseHolder, _ref52, _baseHolder$form_id, _baseHolder2, _tempOrder$holder2, _baseHolder3, _this$otherParams2;
3035
3319
  var holderRecords = [];
3036
3320
  var holderNames = [];
3037
3321
  var baseHolder = null;
@@ -3078,7 +3362,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3078
3362
  }
3079
3363
  var nextHolder = {
3080
3364
  customer_id: (_baseHolder$customer_ = (_baseHolder = baseHolder) === null || _baseHolder === void 0 ? void 0 : _baseHolder.customer_id) !== null && _baseHolder$customer_ !== void 0 ? _baseHolder$customer_ : tempOrder.customer_id,
3081
- form_id: (_ref45 = (_baseHolder$form_id = (_baseHolder2 = baseHolder) === null || _baseHolder2 === void 0 ? void 0 : _baseHolder2.form_id) !== null && _baseHolder$form_id !== void 0 ? _baseHolder$form_id : (_tempOrder$holder2 = tempOrder.holder) === null || _tempOrder$holder2 === void 0 ? void 0 : _tempOrder$holder2.form_id) !== null && _ref45 !== void 0 ? _ref45 : 0,
3365
+ form_id: (_ref52 = (_baseHolder$form_id = (_baseHolder2 = baseHolder) === null || _baseHolder2 === void 0 ? void 0 : _baseHolder2.form_id) !== null && _baseHolder$form_id !== void 0 ? _baseHolder$form_id : (_tempOrder$holder2 = tempOrder.holder) === null || _tempOrder$holder2 === void 0 ? void 0 : _tempOrder$holder2.form_id) !== null && _ref52 !== void 0 ? _ref52 : 0,
3082
3366
  form_record: holderRecords
3083
3367
  };
3084
3368
  if (holderNames.length) {
@@ -3121,9 +3405,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3121
3405
  }, {
3122
3406
  key: "findBookingIndexByUniqueIdentificationNumber",
3123
3407
  value: function findBookingIndexByUniqueIdentificationNumber(tempOrder, uniqueIdentificationNumber) {
3124
- var _this17 = this;
3408
+ var _this20 = this;
3125
3409
  return (tempOrder.bookings || []).findIndex(function (booking) {
3126
- return _this17.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
3410
+ return _this20.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
3127
3411
  });
3128
3412
  }
3129
3413
  }, {
@@ -3131,12 +3415,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3131
3415
  value: function removeLinkedBookingsForProduct(tempOrder, product) {
3132
3416
  var _product$metadata5,
3133
3417
  _product$metadata6,
3134
- _this18 = this;
3418
+ _this21 = this;
3135
3419
  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);
3136
3420
  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);
3137
3421
  if (!productUid && !bookingUid) return;
3138
3422
  tempOrder.bookings = (tempOrder.bookings || []).filter(function (booking) {
3139
- var currentBookingUid = _this18.getBookingUniqueIdentificationNumber(booking);
3423
+ var currentBookingUid = _this21.getBookingUniqueIdentificationNumber(booking);
3140
3424
  if (bookingUid && currentBookingUid === String(bookingUid)) return false;
3141
3425
  if (productUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) return false;
3142
3426
  return true;
@@ -3153,9 +3437,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3153
3437
  }, {
3154
3438
  key: "applyOrderProductsDepositSummary",
3155
3439
  value: function applyOrderProductsDepositSummary(tempOrder, summary) {
3156
- var _tempOrder$_extend8;
3440
+ var _tempOrder$_extend9;
3157
3441
  var depositSummary = calculateOrderProductsDeposit(tempOrder.products || [], {
3158
- productsByUid: (_tempOrder$_extend8 = tempOrder._extend) === null || _tempOrder$_extend8 === void 0 ? void 0 : _tempOrder$_extend8.productsByUid
3442
+ productsByUid: (_tempOrder$_extend9 = tempOrder._extend) === null || _tempOrder$_extend9 === void 0 ? void 0 : _tempOrder$_extend9.productsByUid
3159
3443
  });
3160
3444
  var manualDepositOverride = this.getManualDepositOverride(tempOrder);
3161
3445
  var currentStructuralFingerprint = manualDepositOverride ? this.buildOrderProductsStructuralFingerprint(tempOrder.products) : '';
@@ -3183,7 +3467,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3183
3467
  key: "recalculateSummary",
3184
3468
  value: function () {
3185
3469
  var _recalculateSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(options) {
3186
- var _this$otherParams3, _ref46, _salesSummaryResult$e;
3470
+ var _this$otherParams3, _ref53, _salesSummaryResult$e;
3187
3471
  var tempOrder, originalSnapshot, hasShopDiscountChanged, shouldReuseOriginalSnapshot, snapshotSummary, shouldFullRecalculateFromSnapshot, summaryProducts, salesSummary, existedSummary, totalRefundAmount, paidPaymentSummary, emptyBaseSummary, emptySummaryBase, emptySummaryWithDeposit, emptySummary, salesSummaryResult, roundingAmount, payServiceChargeAmount, hasSalesSummaryAmount, expectAmount, amountPaymentPatch, normalizedExpectAmountPatch, summaryForGap, summary;
3188
3472
  return _regeneratorRuntime().wrap(function _callee13$(_context15) {
3189
3473
  while (1) switch (_context15.prev = _context15.next) {
@@ -3262,7 +3546,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3262
3546
  roundingAmount = paidPaymentSummary.roundingAmount;
3263
3547
  payServiceChargeAmount = paidPaymentSummary.payServiceChargeAmount;
3264
3548
  hasSalesSummaryAmount = salesSummaryResult.expect_amount !== undefined || salesSummaryResult.total_amount !== undefined;
3265
- expectAmount = hasSalesSummaryAmount ? new Decimal((_ref46 = (_salesSummaryResult$e = salesSummaryResult.expect_amount) !== null && _salesSummaryResult$e !== void 0 ? _salesSummaryResult$e : salesSummaryResult.total_amount) !== null && _ref46 !== void 0 ? _ref46 : 0) : null;
3549
+ expectAmount = hasSalesSummaryAmount ? new Decimal((_ref53 = (_salesSummaryResult$e = salesSummaryResult.expect_amount) !== null && _salesSummaryResult$e !== void 0 ? _salesSummaryResult$e : salesSummaryResult.total_amount) !== null && _ref53 !== void 0 ? _ref53 : 0) : null;
3266
3550
  amountPaymentPatch = hasSalesSummaryAmount || !roundingAmount.eq(0) || !payServiceChargeAmount.eq(0) ? _objectSpread({
3267
3551
  rounding_amount: roundingAmount.toFixed(2)
3268
3552
  }, expectAmount ? {
@@ -3385,8 +3669,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3385
3669
  }, {
3386
3670
  key: "getTempOrderNote",
3387
3671
  value: function getTempOrderNote() {
3388
- var _this$store$tempOrder4;
3389
- return ((_this$store$tempOrder4 = this.store.tempOrder) === null || _this$store$tempOrder4 === void 0 ? void 0 : _this$store$tempOrder4.note) || '';
3672
+ var _this$store$tempOrder6;
3673
+ return ((_this$store$tempOrder6 = this.store.tempOrder) === null || _this$store$tempOrder6 === void 0 ? void 0 : _this$store$tempOrder6.note) || '';
3390
3674
  }
3391
3675
  }, {
3392
3676
  key: "ensureSalesNotesRuntimeState",
@@ -3438,7 +3722,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3438
3722
  }, {
3439
3723
  key: "removeSalesNotesForMissingProductLines",
3440
3724
  value: function removeSalesNotesForMissingProductLines(tempOrder) {
3441
- var _this19 = this;
3725
+ var _this22 = this;
3442
3726
  var state = this.ensureSalesNotesRuntimeState(tempOrder);
3443
3727
  if (!state.loaded || !Array.isArray(tempOrder.notes) || tempOrder.notes.length === 0) {
3444
3728
  return;
@@ -3450,7 +3734,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3450
3734
  return typeof uid === 'string' && uid.length > 0;
3451
3735
  }));
3452
3736
  var nextNotes = tempOrder.notes.filter(function (note) {
3453
- var primary = _this19.getSalesNotePrimaryRelation(note);
3737
+ var primary = _this22.getSalesNotePrimaryRelation(note);
3454
3738
  if (!primary || primary.target_type !== 'order_detail') return true;
3455
3739
  return remainingProductUids.has(primary.target_uuid);
3456
3740
  });
@@ -3462,7 +3746,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3462
3746
  key: "setSalesNoteOnTempOrder",
3463
3747
  value: function setSalesNoteOnTempOrder(tempOrder, input) {
3464
3748
  var _input$target,
3465
- _this20 = this,
3749
+ _this23 = this,
3466
3750
  _tempOrder$shop_order;
3467
3751
  this.ensureSalesNotesLoadedForMutation(tempOrder);
3468
3752
  var note_type = String(input.note_type || '').trim();
@@ -3486,7 +3770,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3486
3770
  var notes = tempOrder.notes || [];
3487
3771
  // 当前 allergy policy 固定同一商品行只保留一条;业务调用方不参与去重规则。
3488
3772
  var existingIndex = policy.uniquePerPrimaryTarget ? notes.findIndex(function (note) {
3489
- var primary = _this20.getSalesNotePrimaryRelation(note);
3773
+ var primary = _this23.getSalesNotePrimaryRelation(note);
3490
3774
  return note.note_type === note_type && (primary === null || primary === void 0 ? void 0 : primary.target_type) === 'order_detail' && primary.target_uuid === target_uuid;
3491
3775
  }) : -1;
3492
3776
  var existing = existingIndex >= 0 ? notes[existingIndex] : null;
@@ -3738,17 +4022,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3738
4022
  }, {
3739
4023
  key: "buildTempOrderCustomer",
3740
4024
  value: function buildTempOrderCustomer(params) {
3741
- var _ref47, _ref48, _ref49, _source$name, _ref50, _ref51, _ref52, _source$customer_name, _source$id, _source$customer_id, _ref53, _source$country_calli, _source$phone, _source$email;
4025
+ var _ref54, _ref55, _ref56, _source$name, _ref57, _ref58, _ref59, _source$customer_name, _source$id, _source$customer_id, _ref60, _source$country_calli, _source$phone, _source$email;
3742
4026
  if (!params.customerId) return null;
3743
4027
  var source = params.source ? cloneDeep(params.source) : {};
3744
- var name = (_ref47 = (_ref48 = (_ref49 = (_source$name = source.name) !== null && _source$name !== void 0 ? _source$name : source.display_name) !== null && _ref49 !== void 0 ? _ref49 : source.customerName) !== null && _ref48 !== void 0 ? _ref48 : source.customer_name) !== null && _ref47 !== void 0 ? _ref47 : params.customerName;
3745
- var customerName = (_ref50 = (_ref51 = (_ref52 = (_source$customer_name = source.customer_name) !== null && _source$customer_name !== void 0 ? _source$customer_name : source.customerName) !== null && _ref52 !== void 0 ? _ref52 : source.display_name) !== null && _ref51 !== void 0 ? _ref51 : source.name) !== null && _ref50 !== void 0 ? _ref50 : params.customerName;
4028
+ var name = (_ref54 = (_ref55 = (_ref56 = (_source$name = source.name) !== null && _source$name !== void 0 ? _source$name : source.display_name) !== null && _ref56 !== void 0 ? _ref56 : source.customerName) !== null && _ref55 !== void 0 ? _ref55 : source.customer_name) !== null && _ref54 !== void 0 ? _ref54 : params.customerName;
4029
+ var customerName = (_ref57 = (_ref58 = (_ref59 = (_source$customer_name = source.customer_name) !== null && _source$customer_name !== void 0 ? _source$customer_name : source.customerName) !== null && _ref59 !== void 0 ? _ref59 : source.display_name) !== null && _ref58 !== void 0 ? _ref58 : source.name) !== null && _ref57 !== void 0 ? _ref57 : params.customerName;
3746
4030
  return _objectSpread(_objectSpread({}, source), {}, {
3747
4031
  id: (_source$id = source.id) !== null && _source$id !== void 0 ? _source$id : params.customerId,
3748
4032
  customer_id: (_source$customer_id = source.customer_id) !== null && _source$customer_id !== void 0 ? _source$customer_id : params.customerId,
3749
4033
  name: String(name || ''),
3750
4034
  customer_name: String(customerName || ''),
3751
- country_calling_code: String((_ref53 = (_source$country_calli = source.country_calling_code) !== null && _source$country_calli !== void 0 ? _source$country_calli : source.countryCallingCode) !== null && _ref53 !== void 0 ? _ref53 : params.countryCallingCode),
4035
+ country_calling_code: String((_ref60 = (_source$country_calli = source.country_calling_code) !== null && _source$country_calli !== void 0 ? _source$country_calli : source.countryCallingCode) !== null && _ref60 !== void 0 ? _ref60 : params.countryCallingCode),
3752
4036
  phone: String((_source$phone = source.phone) !== null && _source$phone !== void 0 ? _source$phone : params.phone),
3753
4037
  email: String((_source$email = source.email) !== null && _source$email !== void 0 ? _source$email : params.email)
3754
4038
  });
@@ -3758,7 +4042,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3758
4042
  value: function isCustomerBoundDiscount(discount) {
3759
4043
  var _discount$type5;
3760
4044
  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;
3761
- return type === 'good_pass' || type === 'discount_card' || type === 'product_discount_card';
4045
+ return type === 'entitlement_pass' || type === 'good_pass' || type === 'discount_card' || type === 'product_discount_card';
3762
4046
  }
3763
4047
  }, {
3764
4048
  key: "shouldKeepCustomerBoundDiscountAfterCustomerChange",
@@ -3768,15 +4052,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3768
4052
  }, {
3769
4053
  key: "productHasCustomerBoundDiscount",
3770
4054
  value: function productHasCustomerBoundDiscount(product) {
3771
- var _this21 = this;
4055
+ var _this24 = this;
3772
4056
  if (((product === null || product === void 0 ? void 0 : product.discount_list) || []).some(function (discount) {
3773
- return _this21.isCustomerBoundDiscount(discount);
4057
+ return _this24.isCustomerBoundDiscount(discount);
3774
4058
  })) {
3775
4059
  return true;
3776
4060
  }
3777
4061
  return ((product === null || product === void 0 ? void 0 : product.product_bundle) || []).some(function (bundle) {
3778
4062
  return ((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []).some(function (discount) {
3779
- return _this21.isCustomerBoundDiscount(discount);
4063
+ return _this24.isCustomerBoundDiscount(discount);
3780
4064
  });
3781
4065
  });
3782
4066
  }
@@ -3785,18 +4069,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3785
4069
  value: function shouldSkipDiscountCalculation(tempOrder) {
3786
4070
  var _this$store$discount20,
3787
4071
  _this$store$discount21,
3788
- _this22 = this;
4072
+ _this25 = this;
3789
4073
  if (this.hasActiveCustomerBoundDiscount) return false;
3790
4074
  var discountList = ((_this$store$discount20 = this.store.discount) === null || _this$store$discount20 === void 0 || (_this$store$discount21 = _this$store$discount20.getDiscountList) === null || _this$store$discount21 === void 0 ? void 0 : _this$store$discount21.call(_this$store$discount20)) || [];
3791
4075
  if (discountList.length > 0) return false;
3792
4076
  return !(tempOrder.products || []).some(function (product) {
3793
- return _this22.productHasCustomerBoundDiscount(product);
4077
+ return _this25.productHasCustomerBoundDiscount(product);
3794
4078
  });
3795
4079
  }
3796
4080
  }, {
3797
4081
  key: "clearCustomerBoundDiscounts",
3798
4082
  value: function clearCustomerBoundDiscounts(tempOrder) {
3799
- var _this23 = this,
4083
+ var _this26 = this,
3800
4084
  _discountModule$getDi,
3801
4085
  _discountModule$getOr,
3802
4086
  _discountModule$setDi,
@@ -3805,7 +4089,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3805
4089
  var filterDiscountList = function filterDiscountList(discountList) {
3806
4090
  if (!Array.isArray(discountList)) return [];
3807
4091
  return discountList.filter(function (discount) {
3808
- var shouldRemove = _this23.isCustomerBoundDiscount(discount);
4092
+ var shouldRemove = _this26.isCustomerBoundDiscount(discount);
3809
4093
  if (shouldRemove) didRemoveCustomerBoundDiscount = true;
3810
4094
  return !shouldRemove;
3811
4095
  });
@@ -3832,12 +4116,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3832
4116
  var currentDiscounts = ((_discountModule$getDi = discountModule.getDiscountList) === null || _discountModule$getDi === void 0 ? void 0 : _discountModule$getDi.call(discountModule)) || [];
3833
4117
  var currentOriginalDiscounts = ((_discountModule$getOr = discountModule.getOriginalDiscountList) === null || _discountModule$getOr === void 0 ? void 0 : _discountModule$getOr.call(discountModule)) || [];
3834
4118
  var nextDiscounts = currentDiscounts.filter(function (discount) {
3835
- if (_this23.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
3836
- return !_this23.isCustomerBoundDiscount(discount);
4119
+ if (_this26.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
4120
+ return !_this26.isCustomerBoundDiscount(discount);
3837
4121
  });
3838
4122
  var nextOriginalDiscounts = currentOriginalDiscounts.filter(function (discount) {
3839
- if (_this23.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
3840
- return !_this23.isCustomerBoundDiscount(discount);
4123
+ if (_this26.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
4124
+ return !_this26.isCustomerBoundDiscount(discount);
3841
4125
  });
3842
4126
  void ((_discountModule$setDi = discountModule.setDiscountList) === null || _discountModule$setDi === void 0 ? void 0 : _discountModule$setDi.call(discountModule, nextDiscounts));
3843
4127
  void ((_discountModule$setOr = discountModule.setOriginalDiscountList) === null || _discountModule$setOr === void 0 ? void 0 : _discountModule$setOr.call(discountModule, nextOriginalDiscounts));
@@ -3852,14 +4136,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3852
4136
  }, {
3853
4137
  key: "updateTempOrderCustomer",
3854
4138
  value: function updateTempOrderCustomer(customer) {
3855
- var _tempOrder$customer_i3, _ref54, _ref55, _customer$customer_id, _ref56, _ref57, _ref58, _customer$customer_na, _ref59, _customer$country_cal, _tempOrder$customer_i4;
4139
+ var _tempOrder$customer_i3, _ref61, _ref62, _customer$customer_id, _ref63, _ref64, _ref65, _customer$customer_na, _ref66, _customer$country_cal, _tempOrder$customer_i4;
3856
4140
  var tempOrder = this.ensureTempOrder();
3857
4141
  var previousCustomerId = (_tempOrder$customer_i3 = tempOrder.customer_id) !== null && _tempOrder$customer_i3 !== void 0 ? _tempOrder$customer_i3 : null;
3858
- var customerId = (_ref54 = (_ref55 = (_customer$customer_id = customer.customer_id) !== null && _customer$customer_id !== void 0 ? _customer$customer_id : customer.customerId) !== null && _ref55 !== void 0 ? _ref55 : customer.id) !== null && _ref54 !== void 0 ? _ref54 : null;
3859
- var customerName = (_ref56 = (_ref57 = (_ref58 = (_customer$customer_na = customer.customer_name) !== null && _customer$customer_na !== void 0 ? _customer$customer_na : customer.customerName) !== null && _ref58 !== void 0 ? _ref58 : customer.display_name) !== null && _ref57 !== void 0 ? _ref57 : customer.name) !== null && _ref56 !== void 0 ? _ref56 : '';
4142
+ var customerId = (_ref61 = (_ref62 = (_customer$customer_id = customer.customer_id) !== null && _customer$customer_id !== void 0 ? _customer$customer_id : customer.customerId) !== null && _ref62 !== void 0 ? _ref62 : customer.id) !== null && _ref61 !== void 0 ? _ref61 : null;
4143
+ var customerName = (_ref63 = (_ref64 = (_ref65 = (_customer$customer_na = customer.customer_name) !== null && _customer$customer_na !== void 0 ? _customer$customer_na : customer.customerName) !== null && _ref65 !== void 0 ? _ref65 : customer.display_name) !== null && _ref64 !== void 0 ? _ref64 : customer.name) !== null && _ref63 !== void 0 ? _ref63 : '';
3860
4144
  tempOrder.customer_id = customerId === null || customerId === undefined || customerId === '' ? null : Number(customerId);
3861
4145
  tempOrder.customer_name = String(customerName || '');
3862
- tempOrder.country_calling_code = String((_ref59 = (_customer$country_cal = customer.country_calling_code) !== null && _customer$country_cal !== void 0 ? _customer$country_cal : customer.countryCallingCode) !== null && _ref59 !== void 0 ? _ref59 : '');
4146
+ tempOrder.country_calling_code = String((_ref66 = (_customer$country_cal = customer.country_calling_code) !== null && _customer$country_cal !== void 0 ? _customer$country_cal : customer.countryCallingCode) !== null && _ref66 !== void 0 ? _ref66 : '');
3863
4147
  tempOrder.phone = String(customer.phone || '');
3864
4148
  tempOrder.email = String(customer.email || '');
3865
4149
  tempOrder.customer = this.buildTempOrderCustomer({
@@ -3871,9 +4155,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3871
4155
  email: tempOrder.email
3872
4156
  });
3873
4157
  var nextCustomerId = (_tempOrder$customer_i4 = tempOrder.customer_id) !== null && _tempOrder$customer_i4 !== void 0 ? _tempOrder$customer_i4 : null;
3874
- if (String(previousCustomerId !== null && previousCustomerId !== void 0 ? previousCustomerId : '') !== String(nextCustomerId !== null && nextCustomerId !== void 0 ? nextCustomerId : '') && !hasPersistedOrderId(tempOrder.order_id)) {
3875
- this.store.availableWalletIds = [];
3876
- this.clearTempOrderPointCardSnapshot(tempOrder);
4158
+ if (String(previousCustomerId !== null && previousCustomerId !== void 0 ? previousCustomerId : '') !== String(nextCustomerId !== null && nextCustomerId !== void 0 ? nextCustomerId : '')) {
4159
+ this.clearCustomerWalletState(tempOrder);
3877
4160
  }
3878
4161
  this.persistTempOrder();
3879
4162
  return {
@@ -3912,11 +4195,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3912
4195
  }
3913
4196
  var nextCustomerId = (_tempOrder$customer_i6 = tempOrder.customer_id) !== null && _tempOrder$customer_i6 !== void 0 ? _tempOrder$customer_i6 : null;
3914
4197
  if (String(previousCustomerId !== null && previousCustomerId !== void 0 ? previousCustomerId : '') !== String(nextCustomerId !== null && nextCustomerId !== void 0 ? nextCustomerId : '')) {
3915
- this.store.availableWalletIds = [];
3916
- this.store.virtualCurrencyList = [];
3917
- if (!hasPersistedOrderId(tempOrder.order_id)) {
3918
- this.clearTempOrderPointCardSnapshot(tempOrder);
3919
- }
4198
+ this.clearCustomerWalletState(tempOrder);
3920
4199
  clearTempOrderHolderAssignments(tempOrder);
3921
4200
  this.clearCustomerBoundDiscounts(tempOrder);
3922
4201
  this.applyDiscount();
@@ -3945,8 +4224,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3945
4224
  }, {
3946
4225
  key: "getOrderCustomerSnapshot",
3947
4226
  value: function getOrderCustomerSnapshot() {
3948
- var _this$store$tempOrder5;
3949
- var snapshot = (_this$store$tempOrder5 = this.store.tempOrder) === null || _this$store$tempOrder5 === void 0 || (_this$store$tempOrder5 = _this$store$tempOrder5._extend) === null || _this$store$tempOrder5 === void 0 ? void 0 : _this$store$tempOrder5.customerSnapshot;
4227
+ var _this$store$tempOrder7;
4228
+ var snapshot = (_this$store$tempOrder7 = this.store.tempOrder) === null || _this$store$tempOrder7 === void 0 || (_this$store$tempOrder7 = _this$store$tempOrder7._extend) === null || _this$store$tempOrder7 === void 0 ? void 0 : _this$store$tempOrder7.customerSnapshot;
3950
4229
  return snapshot ? cloneDeep(snapshot) : null;
3951
4230
  }
3952
4231
  }, {
@@ -3961,11 +4240,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3961
4240
  tempOrder.email = '';
3962
4241
  tempOrder.customer = null;
3963
4242
  if (tempOrder._extend) delete tempOrder._extend.customerSnapshot;
3964
- this.store.availableWalletIds = [];
3965
- this.store.virtualCurrencyList = [];
3966
- if (!hasPersistedOrderId(tempOrder.order_id)) {
3967
- this.clearTempOrderPointCardSnapshot(tempOrder);
3968
- }
4243
+ this.clearCustomerWalletState(tempOrder);
3969
4244
  this.clearCustomerBoundDiscounts(tempOrder);
3970
4245
  this.applyDiscount();
3971
4246
  this.persistTempOrder();
@@ -4010,10 +4285,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4010
4285
  }, {
4011
4286
  key: "setOrderPayments",
4012
4287
  value: function setOrderPayments(payments) {
4013
- var _this24 = this;
4288
+ var _this27 = this;
4014
4289
  var tempOrder = this.ensureTempOrder();
4015
4290
  tempOrder.payments = mapPaymentItemsToOrderPayments((payments || []).map(function (payment) {
4016
- return _this24.normalizePaymentSource(payment, {
4291
+ return _this27.normalizePaymentSource(payment, {
4017
4292
  defaultPaid: false
4018
4293
  });
4019
4294
  }));
@@ -4068,7 +4343,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4068
4343
  }, {
4069
4344
  key: "addOrderPaymentWithDevicePrefix",
4070
4345
  value: function addOrderPaymentWithDevicePrefix(payment, devicePrefix) {
4071
- var _this25 = this;
4346
+ var _this28 = this;
4072
4347
  this.logInfo('addOrderPayment', {
4073
4348
  payment: payment
4074
4349
  });
@@ -4086,7 +4361,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4086
4361
  void this.recalculateSummary({
4087
4362
  createIfMissing: true
4088
4363
  }).catch(function (error) {
4089
- _this25.logError('recalculate summary after addOrderPayment failed', {
4364
+ _this28.logError('recalculate summary after addOrderPayment failed', {
4090
4365
  error: error instanceof Error ? error.message : String(error)
4091
4366
  });
4092
4367
  });
@@ -4199,7 +4474,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4199
4474
  }, {
4200
4475
  key: "applyPaymentLifecycleChange",
4201
4476
  value: function applyPaymentLifecycleChange(tempOrder, options) {
4202
- var _this26 = this;
4477
+ var _this29 = this;
4203
4478
  this.updateTempOrderPaymentStatus(tempOrder);
4204
4479
  if ((options === null || options === void 0 ? void 0 : options.persist) !== false) {
4205
4480
  this.persistTempOrder();
@@ -4209,7 +4484,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4209
4484
  void this.recalculateSummary({
4210
4485
  createIfMissing: true
4211
4486
  }).catch(function (error) {
4212
- _this26.logError("recalculate summary after ".concat(logContext, " failed"), {
4487
+ _this29.logError("recalculate summary after ".concat(logContext, " failed"), {
4213
4488
  error: error instanceof Error ? error.message : String(error)
4214
4489
  });
4215
4490
  });
@@ -4253,7 +4528,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4253
4528
  }, {
4254
4529
  key: "updateVoucherOrderPayments",
4255
4530
  value: function updateVoucherOrderPayments(payments, options) {
4256
- var _this27 = this;
4531
+ var _this30 = this;
4257
4532
  var tempOrder = this.ensureTempOrder();
4258
4533
  var isOrderPaymentType = function isOrderPaymentType(value) {
4259
4534
  return value === 'normal' || value === 'deposit';
@@ -4288,7 +4563,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4288
4563
  });
4289
4564
  };
4290
4565
  var mappedVouchers = mapPaymentItemsToOrderPayments(payments.map(function (payment) {
4291
- return _this27.normalizePaymentSource(normalizeVoucherPaymentStatus(withVoucherPaymentType(payment)), {
4566
+ return _this30.normalizePaymentSource(normalizeVoucherPaymentStatus(withVoucherPaymentType(payment)), {
4292
4567
  defaultPaid: false,
4293
4568
  devicePrefix: options === null || options === void 0 ? void 0 : options.devicePrefix
4294
4569
  });
@@ -4341,7 +4616,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4341
4616
  void this.recalculateSummary({
4342
4617
  createIfMissing: true
4343
4618
  }).catch(function (error) {
4344
- _this27.logError('recalculate summary after updateVoucherOrderPayments failed', {
4619
+ _this30.logError('recalculate summary after updateVoucherOrderPayments failed', {
4345
4620
  error: error instanceof Error ? error.message : String(error)
4346
4621
  });
4347
4622
  });
@@ -4399,7 +4674,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4399
4674
  key: "shouldMergeProductToOrder",
4400
4675
  value: function shouldMergeProductToOrder(params) {
4401
4676
  var _this$orderHooks,
4402
- _this28 = this;
4677
+ _this31 = this;
4403
4678
  var onBeforeMergeProductToOrder = (_this$orderHooks = this.orderHooks) === null || _this$orderHooks === void 0 ? void 0 : _this$orderHooks.onBeforeMergeProductToOrder;
4404
4679
  if (!onBeforeMergeProductToOrder) return true;
4405
4680
  var result = onBeforeMergeProductToOrder(_objectSpread(_objectSpread({}, params), {}, {
@@ -4407,7 +4682,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4407
4682
  }));
4408
4683
  if (result && _typeof(result) === 'object' && typeof result.then === 'function') {
4409
4684
  return Promise.resolve(result).then(function (resolved) {
4410
- return _this28.normalizeShouldMergeProductResult(resolved);
4685
+ return _this31.normalizeShouldMergeProductResult(resolved);
4411
4686
  });
4412
4687
  }
4413
4688
  return this.normalizeShouldMergeProductResult(result);
@@ -4456,7 +4731,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4456
4731
  }, {
4457
4732
  key: "assertAndLockProductSettlement",
4458
4733
  value: function assertAndLockProductSettlement(tempOrder, product) {
4459
- var _ref60, _ref61, _product$selling_pric;
4734
+ var _ref67, _ref68, _product$selling_pric;
4460
4735
  if (!this.isMultiCurrencySettlementEnabled()) return;
4461
4736
  var currentKey = getTempOrderSettlementKey(tempOrder);
4462
4737
  var incomingKey = getSettlementKey(getSelectedSettlementSnapshot(product)) || 'legal_currency';
@@ -4483,7 +4758,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4483
4758
  }
4484
4759
  applyTempOrderSettlementState(tempOrder, snapshot || {
4485
4760
  settlement_type: 'legal_currency',
4486
- price: (_ref60 = (_ref61 = (_product$selling_pric = product.selling_price) !== null && _product$selling_pric !== void 0 ? _product$selling_pric : product.original_price) !== null && _ref61 !== void 0 ? _ref61 : product.payment_price) !== null && _ref60 !== void 0 ? _ref60 : 0,
4761
+ price: (_ref67 = (_ref68 = (_product$selling_pric = product.selling_price) !== null && _product$selling_pric !== void 0 ? _product$selling_pric : product.original_price) !== null && _ref68 !== void 0 ? _ref68 : product.payment_price) !== null && _ref67 !== void 0 ? _ref67 : 0,
4487
4762
  unit_label: tempOrder.currency_code,
4488
4763
  symbol: tempOrder.currency_symbol,
4489
4764
  amount_format: tempOrder.currency_format
@@ -4608,7 +4883,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4608
4883
  _metadata,
4609
4884
  _productToAdd$metadat,
4610
4885
  _origin,
4611
- _this29 = this;
4886
+ _this32 = this;
4612
4887
  var linked = booking ? this.createLinkedProductAndBooking({
4613
4888
  product: product,
4614
4889
  booking: booking
@@ -4635,18 +4910,35 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4635
4910
  }
4636
4911
  normalizedIncoming.discount_list = normalizeOrderProductDiscountList(normalizedIncoming.discount_list);
4637
4912
  var hasIncomingGoodPass = this.hasGoodPassDiscount(normalizedIncoming);
4913
+ var hasIncomingEntitlementPass = this.hasEntitlementPassDiscount(normalizedIncoming);
4914
+ var isIncomingEntitlementAppend = this.isRuntimeEntitlementAppend(productToAdd, tempOrder);
4915
+ var isIncomingPersistedEntitlementPass = hasIncomingEntitlementPass && this.isPersistedProductLine(normalizedIncoming);
4638
4916
  var hasIncomingProductNote = this.hasOrderProductLineNote(normalizedIncoming);
4639
4917
  var hasIncomingManualProductDiscount = isManualProductDiscountProduct(normalizedIncoming);
4640
4918
  var hasIncomingBookingUid = this.hasLinkedBookingUid(productToAdd) || this.hasLinkedBookingUid(normalizedIncoming);
4641
4919
  var isIncomingCustomItem = ((_productToAdd$metadat = productToAdd.metadata) === null || _productToAdd$metadat === void 0 || (_productToAdd$metadat = _productToAdd$metadat.origin) === null || _productToAdd$metadat === void 0 ? void 0 : _productToAdd$metadat.isCustomItem) === true || ((_origin = productToAdd._origin) === null || _origin === void 0 ? void 0 : _origin.isCustomItem) === true;
4642
- var shouldForceNewLine = disableMerge || !!booking || hasIncomingProductNote || hasIncomingManualProductDiscount || hasIncomingBookingUid || isIncomingCustomItem || isWeighingProduct;
4643
- var matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex(function (item) {
4644
- var _item$metadata3;
4645
- if (_this29.hasGoodPassDiscount(item)) return false;
4646
- if (_this29.hasOrderProductLineNote(item)) return false;
4647
- if (isManualProductDiscountProduct(item)) return false;
4648
- if (item.order_detail_id !== undefined && item.order_detail_id !== null) return false;
4649
- if ((_item$metadata3 = item.metadata) !== null && _item$metadata3 !== void 0 && _item$metadata3.is_edit_for_runtime) return false;
4920
+ var shouldForceNewLine = disableMerge || !!booking || hasIncomingGoodPass || isIncomingPersistedEntitlementPass || hasIncomingBookingUid || isIncomingCustomItem || isWeighingProduct;
4921
+ var matchedIndex = shouldForceNewLine ? -1 : tempOrder.products.findIndex(function (item) {
4922
+ if (_this32.hasGoodPassDiscount(item)) return false;
4923
+ var isRuntimeEntitlementPass = _this32.isRuntimeEntitlementAppend(item, tempOrder);
4924
+ if (isIncomingEntitlementAppend !== isRuntimeEntitlementPass) {
4925
+ return false;
4926
+ }
4927
+ if (isIncomingEntitlementAppend && _this32.isPersistedProductLine(item)) {
4928
+ return false;
4929
+ }
4930
+ var hasExistingProductNote = _this32.hasOrderProductLineNote(item);
4931
+ if ((hasIncomingProductNote || hasExistingProductNote) && (!isRuntimeEntitlementPass || String(normalizedIncoming.note || '').trim() !== String(item.note || '').trim())) {
4932
+ return false;
4933
+ }
4934
+ var hasExistingManualProductDiscount = isManualProductDiscountProduct(item);
4935
+ if (isRuntimeEntitlementPass && !_this32.hasSameEntitlementMergePriceConfig(normalizedIncoming, item)) {
4936
+ return false;
4937
+ }
4938
+ if ((hasIncomingManualProductDiscount || hasExistingManualProductDiscount) && !isRuntimeEntitlementPass) {
4939
+ return false;
4940
+ }
4941
+ if (_this32.isPersistedProductLine(item)) return false;
4650
4942
  if (item.product_id !== productToAdd.product_id) return false;
4651
4943
  if (item.product_variant_id !== productToAdd.product_variant_id) return false;
4652
4944
  var existedFingerprint = buildProductLineFingerprint(getProductSkuOptions(item), item.product_bundle);
@@ -4657,7 +4949,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4657
4949
  var commitProductLine = function commitProductLine(shouldMerge) {
4658
4950
  var committedProduct;
4659
4951
  if (matchedIndex === -1 || !matchedProduct || !shouldMerge) {
4660
- _this29.captureProductRuntime(tempOrder, productToAdd, normalizedIncoming);
4952
+ _this32.captureProductRuntime(tempOrder, productToAdd, normalizedIncoming);
4661
4953
  if (linked) {
4662
4954
  normalizedIncoming.booking_uid = linked.bookingUid;
4663
4955
  normalizedIncoming.metadata = _objectSpread(_objectSpread({}, normalizedIncoming.metadata || {}), {}, {
@@ -4675,7 +4967,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4675
4967
  var _targetProduct$metada;
4676
4968
  var targetProduct = matchedProduct;
4677
4969
  var targetUid = (_targetProduct$metada = targetProduct.metadata) === null || _targetProduct$metada === void 0 ? void 0 : _targetProduct$metada.unique_identification_number;
4678
- var normalizedProduct = _this29.normalizeVirtualSettlementProductIfEnabled(mergeOrderProductDisplayFields(targetProduct, normalizeOrderProduct(_objectSpread(_objectSpread({}, productToAdd), {}, {
4970
+ var normalizedProduct = _this32.normalizeVirtualSettlementProductIfEnabled(mergeOrderProductDisplayFields(targetProduct, normalizeOrderProduct(_objectSpread(_objectSpread({}, productToAdd), {}, {
4679
4971
  metadata: _objectSpread(_objectSpread({}, productToAdd.metadata || {}), {}, {
4680
4972
  unique_identification_number: targetUid
4681
4973
  })
@@ -4698,7 +4990,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4698
4990
  order_detail_id: targetProduct.order_detail_id,
4699
4991
  num: nextNum
4700
4992
  });
4701
- _this29.captureProductRuntime(tempOrder, productToAdd, tempOrder.products[matchedIndex], targetUid);
4993
+ _this32.captureProductRuntime(tempOrder, productToAdd, tempOrder.products[matchedIndex], targetUid);
4702
4994
  committedProduct = tempOrder.products[matchedIndex];
4703
4995
  if (matchedIndex !== tempOrder.products.length - 1) {
4704
4996
  var mergedProduct = tempOrder.products[matchedIndex];
@@ -4736,14 +5028,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4736
5028
  }, {
4737
5029
  key: "createSplitBookingLine",
4738
5030
  value: function createSplitBookingLine(product, booking, index, splitCount) {
4739
- var _booking$metadata6, _ref62, _ref63, _bookingHolder$form_r, _booking$metadata7, _product$metadata10, _bookingHolder$name, _singleBooking$metada;
5031
+ var _booking$metadata6, _ref69, _ref70, _bookingHolder$form_r, _booking$metadata7, _product$metadata10, _bookingHolder$name, _singleBooking$metada;
4740
5032
  var singleLine = cloneDeep(product);
4741
5033
  singleLine.num = 1;
4742
5034
  delete singleLine.product_quantity;
4743
5035
  var singleBooking = cloneDeep(booking);
4744
5036
  var bookingHolder = booking !== null && booking !== void 0 && booking.holder && _typeof(booking.holder) === 'object' ? booking.holder : null;
4745
5037
  var metadataHolder = booking !== null && booking !== void 0 && (_booking$metadata6 = booking.metadata) !== null && _booking$metadata6 !== void 0 && _booking$metadata6.holder && _typeof(booking.metadata.holder) === 'object' ? booking.metadata.holder : null;
4746
- var rawHolderIds = (_ref62 = (_ref63 = (_bookingHolder$form_r = bookingHolder === null || bookingHolder === void 0 ? void 0 : bookingHolder.form_record) !== null && _bookingHolder$form_r !== void 0 ? _bookingHolder$form_r : booking === null || booking === void 0 || (_booking$metadata7 = booking.metadata) === null || _booking$metadata7 === void 0 ? void 0 : _booking$metadata7.holder_id) !== null && _ref63 !== void 0 ? _ref63 : metadataHolder === null || metadataHolder === void 0 ? void 0 : metadataHolder.form_record) !== null && _ref62 !== void 0 ? _ref62 : product === null || product === void 0 || (_product$metadata10 = product.metadata) === null || _product$metadata10 === void 0 ? void 0 : _product$metadata10.holder_id;
5038
+ var rawHolderIds = (_ref69 = (_ref70 = (_bookingHolder$form_r = bookingHolder === null || bookingHolder === void 0 ? void 0 : bookingHolder.form_record) !== null && _bookingHolder$form_r !== void 0 ? _bookingHolder$form_r : booking === null || booking === void 0 || (_booking$metadata7 = booking.metadata) === null || _booking$metadata7 === void 0 ? void 0 : _booking$metadata7.holder_id) !== null && _ref70 !== void 0 ? _ref70 : metadataHolder === null || metadataHolder === void 0 ? void 0 : metadataHolder.form_record) !== null && _ref69 !== void 0 ? _ref69 : product === null || product === void 0 || (_product$metadata10 = product.metadata) === null || _product$metadata10 === void 0 ? void 0 : _product$metadata10.holder_id;
4747
5039
  var holderIds = (Array.isArray(rawHolderIds) ? rawHolderIds : [rawHolderIds]).map(function (holderId) {
4748
5040
  return holderId && _typeof(holderId) === 'object' ? holderId.form_record_id : holderId;
4749
5041
  }).filter(function (holderId) {
@@ -4808,8 +5100,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4808
5100
  key: "addProductToOrder",
4809
5101
  value: (function () {
4810
5102
  var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(product, booking, options) {
4811
- var _this30 = this;
4812
- var tempOrder, salesNoteDrafts, mutationSnapshot, attachSalesNoteDrafts, rollbackProductAndNotesMutation, insertAfterProductUid, anchorIndex, insertAtIndex, _ref64, _productRecord$num, productRecord, splitCount, i, splitLine, committedProduct, _committedProduct, _committedProduct2;
5103
+ var _this33 = this;
5104
+ var tempOrder, salesNoteDrafts, mutationSnapshot, attachSalesNoteDrafts, rollbackProductAndNotesMutation, insertAfterProductUid, anchorIndex, insertAtIndex, _ref71, _productRecord$num, productRecord, splitCount, i, splitLine, committedProduct, _committedProduct, _committedProduct2;
4813
5105
  return _regeneratorRuntime().wrap(function _callee23$(_context25) {
4814
5106
  while (1) switch (_context25.prev = _context25.next) {
4815
5107
  case 0:
@@ -4837,7 +5129,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4837
5129
  throw new Error('[Order Notes] 商品行缺少 unique_identification_number');
4838
5130
  }
4839
5131
  salesNoteDrafts.forEach(function (draft) {
4840
- _this30.setSalesNoteOnTempOrder(tempOrder, {
5132
+ _this33.setSalesNoteOnTempOrder(tempOrder, {
4841
5133
  note_type: draft.note_type,
4842
5134
  target: {
4843
5135
  target_type: 'order_detail',
@@ -4867,7 +5159,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4867
5159
  break;
4868
5160
  }
4869
5161
  productRecord = product;
4870
- splitCount = getSafeProductNum((_ref64 = (_productRecord$num = productRecord.num) !== null && _productRecord$num !== void 0 ? _productRecord$num : productRecord.product_quantity) !== null && _ref64 !== void 0 ? _ref64 : 1);
5162
+ splitCount = getSafeProductNum((_ref71 = (_productRecord$num = productRecord.num) !== null && _productRecord$num !== void 0 ? _productRecord$num : productRecord.product_quantity) !== null && _ref71 !== void 0 ? _ref71 : 1);
4871
5163
  if (!(splitCount > 1)) {
4872
5164
  _context25.next = 27;
4873
5165
  break;
@@ -4972,7 +5264,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4972
5264
  key: "addProductsToOrder",
4973
5265
  value: (function () {
4974
5266
  var _addProductsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(items, options) {
4975
- var tempOrder, _iterator20, _step20, item, product, booking, _ref65, _productRecord$num2, productRecord, splitCount, i, splitLine, _appendResult, appendResult;
5267
+ var tempOrder, _iterator20, _step20, item, product, booking, _ref72, _productRecord$num2, productRecord, splitCount, i, splitLine, _appendResult, appendResult;
4976
5268
  return _regeneratorRuntime().wrap(function _callee24$(_context26) {
4977
5269
  while (1) switch (_context26.prev = _context26.next) {
4978
5270
  case 0:
@@ -5004,7 +5296,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5004
5296
  break;
5005
5297
  }
5006
5298
  productRecord = product;
5007
- splitCount = getSafeProductNum((_ref65 = (_productRecord$num2 = productRecord.num) !== null && _productRecord$num2 !== void 0 ? _productRecord$num2 : productRecord.product_quantity) !== null && _ref65 !== void 0 ? _ref65 : 1);
5299
+ splitCount = getSafeProductNum((_ref72 = (_productRecord$num2 = productRecord.num) !== null && _productRecord$num2 !== void 0 ? _productRecord$num2 : productRecord.product_quantity) !== null && _ref72 !== void 0 ? _ref72 : 1);
5008
5300
  if (!(splitCount > 1)) {
5009
5301
  _context26.next = 26;
5010
5302
  break;
@@ -5071,45 +5363,99 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5071
5363
  return addProductsToOrder;
5072
5364
  }())
5073
5365
  }, {
5074
- key: "hasGoodPassDiscount",
5075
- value: function hasGoodPassDiscount(product) {
5366
+ key: "getFullCoveragePassDiscounts",
5367
+ value: function getFullCoveragePassDiscounts(product) {
5076
5368
  var _product$_extend;
5077
- var hasMainGoodPass = (product.discount_list || []).some(function (item) {
5078
- return (item === null || item === void 0 ? void 0 : item.type) === 'good_pass' || (item === null || item === void 0 ? void 0 : item.tag) === 'good_pass';
5079
- });
5080
- if (hasMainGoodPass) return true;
5081
- var bundleDiscountList = [];
5369
+ var discountList = _toConsumableArray(product.discount_list || []);
5082
5370
  (product.product_bundle || []).forEach(function (item) {
5083
- bundleDiscountList.push.apply(bundleDiscountList, _toConsumableArray((item === null || item === void 0 ? void 0 : item.discount_list) || []));
5371
+ discountList.push.apply(discountList, _toConsumableArray((item === null || item === void 0 ? void 0 : item.discount_list) || []));
5084
5372
  });
5085
5373
  ((product === null || product === void 0 || (_product$_extend = product._extend) === null || _product$_extend === void 0 || (_product$_extend = _product$_extend.other) === null || _product$_extend === void 0 ? void 0 : _product$_extend.bundle) || []).forEach(function (item) {
5086
- bundleDiscountList.push.apply(bundleDiscountList, _toConsumableArray((item === null || item === void 0 ? void 0 : item.discount_list) || []));
5374
+ discountList.push.apply(discountList, _toConsumableArray((item === null || item === void 0 ? void 0 : item.discount_list) || []));
5375
+ });
5376
+ return discountList.filter(function (item) {
5377
+ return isFullCoveragePass(item);
5087
5378
  });
5088
- return bundleDiscountList.some(function (item) {
5089
- return (item === null || item === void 0 ? void 0 : item.type) === 'good_pass' || (item === null || item === void 0 ? void 0 : item.tag) === 'good_pass';
5379
+ }
5380
+ }, {
5381
+ key: "hasEntitlementPassDiscount",
5382
+ value: function hasEntitlementPassDiscount(product) {
5383
+ return this.getFullCoveragePassDiscounts(product).some(function (item) {
5384
+ return isEntitlementPass(item);
5385
+ });
5386
+ }
5387
+ }, {
5388
+ key: "hasGoodPassDiscount",
5389
+ value: function hasGoodPassDiscount(product) {
5390
+ return this.getFullCoveragePassDiscounts(product).some(function (item) {
5391
+ return !isEntitlementPass(item);
5090
5392
  });
5091
5393
  }
5394
+ }, {
5395
+ key: "isPersistedProductLine",
5396
+ value: function isPersistedProductLine(product) {
5397
+ var _product$metadata11;
5398
+ return product.order_detail_id !== undefined && product.order_detail_id !== null && product.order_detail_id !== '' || ((_product$metadata11 = product.metadata) === null || _product$metadata11 === void 0 ? void 0 : _product$metadata11.is_edit_for_runtime) === true;
5399
+ }
5400
+ }, {
5401
+ key: "isRuntimeEntitlementAppend",
5402
+ value: function isRuntimeEntitlementAppend(product, tempOrder) {
5403
+ var _product$metadata$uni, _product$metadata12, _tempOrder$_extend10, _product$_origin;
5404
+ if (this.isPersistedProductLine(product)) return false;
5405
+ var uid = (_product$metadata$uni = (_product$metadata12 = product.metadata) === null || _product$metadata12 === void 0 ? void 0 : _product$metadata12.unique_identification_number) !== null && _product$metadata$uni !== void 0 ? _product$metadata$uni : product.unique_identification_number;
5406
+ var storedOrigin = uid !== undefined && uid !== null && uid !== '' ? (_tempOrder$_extend10 = tempOrder._extend) === null || _tempOrder$_extend10 === void 0 || (_tempOrder$_extend10 = _tempOrder$_extend10.productsByUid) === null || _tempOrder$_extend10 === void 0 || (_tempOrder$_extend10 = _tempOrder$_extend10[String(uid)]) === null || _tempOrder$_extend10 === void 0 ? void 0 : _tempOrder$_extend10.origin : undefined;
5407
+ return Boolean((product === null || product === void 0 || (_product$_origin = product._origin) === null || _product$_origin === void 0 ? void 0 : _product$_origin.__entitlementPassRuntimeAppend) === true || (storedOrigin === null || storedOrigin === void 0 ? void 0 : storedOrigin.__entitlementPassRuntimeAppend) === true);
5408
+ }
5409
+ }, {
5410
+ key: "hasSameEntitlementMergePriceConfig",
5411
+ value: function hasSameEntitlementMergePriceConfig(incoming, existing) {
5412
+ var _this34 = this;
5413
+ var buildPriceConfig = function buildPriceConfig(product) {
5414
+ var metadata = product.metadata || {};
5415
+ var bundle = (product.product_bundle || []).map(function (item) {
5416
+ var _ref73, _item$bundle_id, _ref74, _ref75, _item$bundle_product_, _ref76, _item$bundle_variant_, _ref77, _item$price_type, _ref78, _item$price_type_ext;
5417
+ return {
5418
+ bundle_id: (_ref73 = (_item$bundle_id = item.bundle_id) !== null && _item$bundle_id !== void 0 ? _item$bundle_id : item.id) !== null && _ref73 !== void 0 ? _ref73 : null,
5419
+ bundle_product_id: (_ref74 = (_ref75 = (_item$bundle_product_ = item.bundle_product_id) !== null && _item$bundle_product_ !== void 0 ? _item$bundle_product_ : item._bundle_product_id) !== null && _ref75 !== void 0 ? _ref75 : item.product_id) !== null && _ref74 !== void 0 ? _ref74 : null,
5420
+ bundle_variant_id: (_ref76 = (_item$bundle_variant_ = item.bundle_variant_id) !== null && _item$bundle_variant_ !== void 0 ? _item$bundle_variant_ : item.product_variant_id) !== null && _ref76 !== void 0 ? _ref76 : 0,
5421
+ price_type: (_ref77 = (_item$price_type = item.price_type) !== null && _item$price_type !== void 0 ? _item$price_type : item.custom_price_type) !== null && _ref77 !== void 0 ? _ref77 : '',
5422
+ price_type_ext: (_ref78 = (_item$price_type_ext = item.price_type_ext) !== null && _item$price_type_ext !== void 0 ? _item$price_type_ext : item.custom_price_type_ext) !== null && _ref78 !== void 0 ? _ref78 : ''
5423
+ };
5424
+ }).sort(function (left, right) {
5425
+ return JSON.stringify(left).localeCompare(JSON.stringify(right));
5426
+ });
5427
+ return JSON.stringify({
5428
+ original_price: _this34.normalizeFingerprintMoney(product.original_price),
5429
+ source_product_price: _this34.normalizeFingerprintMoney(metadata.source_product_price),
5430
+ main_product_original_price: _this34.normalizeFingerprintMoney(metadata.main_product_original_price),
5431
+ price_override: _this34.normalizeFingerprintMoney(metadata.price_override),
5432
+ is_manual_discount: Boolean(metadata.is_manual_discount),
5433
+ bundle: bundle
5434
+ });
5435
+ };
5436
+ return buildPriceConfig(incoming) === buildPriceConfig(existing);
5437
+ }
5092
5438
  }, {
5093
5439
  key: "getBundleRuntimeIdentity",
5094
5440
  value: function getBundleRuntimeIdentity(bundle) {
5095
- var _ref66, _bundle$bundle_id2, _ref67, _bundle$bundle_group_2, _ref68, _ref69, _bundle$bundle_produc3, _ref70, _bundle$bundle_varian3;
5441
+ var _ref79, _bundle$bundle_id2, _ref80, _bundle$bundle_group_2, _ref81, _ref82, _bundle$bundle_produc3, _ref83, _bundle$bundle_varian3;
5096
5442
  if (!bundle || _typeof(bundle) !== 'object') return '';
5097
- return [(_ref66 = (_bundle$bundle_id2 = bundle.bundle_id) !== null && _bundle$bundle_id2 !== void 0 ? _bundle$bundle_id2 : bundle.id) !== null && _ref66 !== void 0 ? _ref66 : '', (_ref67 = (_bundle$bundle_group_2 = bundle.bundle_group_id) !== null && _bundle$bundle_group_2 !== void 0 ? _bundle$bundle_group_2 : bundle.group_id) !== null && _ref67 !== void 0 ? _ref67 : '', (_ref68 = (_ref69 = (_bundle$bundle_produc3 = bundle.bundle_product_id) !== null && _bundle$bundle_produc3 !== void 0 ? _bundle$bundle_produc3 : bundle._bundle_product_id) !== null && _ref69 !== void 0 ? _ref69 : bundle.product_id) !== null && _ref68 !== void 0 ? _ref68 : '', (_ref70 = (_bundle$bundle_varian3 = bundle.bundle_variant_id) !== null && _bundle$bundle_varian3 !== void 0 ? _bundle$bundle_varian3 : bundle.product_variant_id) !== null && _ref70 !== void 0 ? _ref70 : 0].join('|');
5443
+ return [(_ref79 = (_bundle$bundle_id2 = bundle.bundle_id) !== null && _bundle$bundle_id2 !== void 0 ? _bundle$bundle_id2 : bundle.id) !== null && _ref79 !== void 0 ? _ref79 : '', (_ref80 = (_bundle$bundle_group_2 = bundle.bundle_group_id) !== null && _bundle$bundle_group_2 !== void 0 ? _bundle$bundle_group_2 : bundle.group_id) !== null && _ref80 !== void 0 ? _ref80 : '', (_ref81 = (_ref82 = (_bundle$bundle_produc3 = bundle.bundle_product_id) !== null && _bundle$bundle_produc3 !== void 0 ? _bundle$bundle_produc3 : bundle._bundle_product_id) !== null && _ref82 !== void 0 ? _ref82 : bundle.product_id) !== null && _ref81 !== void 0 ? _ref81 : '', (_ref83 = (_bundle$bundle_varian3 = bundle.bundle_variant_id) !== null && _bundle$bundle_varian3 !== void 0 ? _bundle$bundle_varian3 : bundle.product_variant_id) !== null && _ref83 !== void 0 ? _ref83 : 0].join('|');
5098
5444
  }
5099
5445
  }, {
5100
5446
  key: "preservePersistedBundlePriceFields",
5101
5447
  value: function preservePersistedBundlePriceFields(previousBundles, nextBundles) {
5102
- var _this31 = this;
5448
+ var _this35 = this;
5103
5449
  if (!Array.isArray(nextBundles)) return nextBundles;
5104
5450
  if (!Array.isArray(previousBundles) || previousBundles.length === 0) return nextBundles;
5105
5451
  var previousByIdentity = new Map();
5106
5452
  previousBundles.forEach(function (bundle) {
5107
- var identity = _this31.getBundleRuntimeIdentity(bundle);
5453
+ var identity = _this35.getBundleRuntimeIdentity(bundle);
5108
5454
  if (identity) previousByIdentity.set(identity, bundle);
5109
5455
  });
5110
5456
  return nextBundles.map(function (bundle, index) {
5111
5457
  if (!bundle || _typeof(bundle) !== 'object') return bundle;
5112
- var previous = previousByIdentity.get(_this31.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
5458
+ var previous = previousByIdentity.get(_this35.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
5113
5459
  if (!previous || _typeof(previous) !== 'object') return bundle;
5114
5460
  return _objectSpread(_objectSpread(_objectSpread({}, bundle), (bundle.cover === undefined || bundle.cover === null || bundle.cover === '') && previous.cover !== undefined && previous.cover !== null && previous.cover !== '' ? {
5115
5461
  cover: previous.cover
@@ -5125,8 +5471,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5125
5471
  }
5126
5472
  }, {
5127
5473
  key: "applyOrderProductUpdateToTempOrder",
5128
- value: function applyOrderProductUpdateToTempOrder(tempOrder, params) {
5129
- var _targetProduct$metada2, _product_sku, _metadata2, _metadata3, _metadata4, _metadata5, _metadata6, _metadata7, _metadata8, _metadata9, _metadata10, _nextProduct$metadata, _targetProduct$metada15, _tempOrder$products$p, _tempOrder$products$p2;
5474
+ value: function applyOrderProductUpdateToTempOrder(tempOrder, params, reapplyWeighedDiscountProductUids) {
5475
+ var _targetProduct$metada2, _product_sku, _metadata2, _metadata3, _metadata4, _metadata5, _metadata6, _metadata7, _metadata8, _metadata9, _metadata10, _nextProduct$metadata2, _targetProduct$metada20, _tempOrder$products$p, _tempOrder$products$p2;
5130
5476
  var product_id = params.product_id,
5131
5477
  product_variant_id = params.product_variant_id,
5132
5478
  updates = params.updates,
@@ -5192,7 +5538,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5192
5538
  var previousLineFingerprint = buildProductLineFingerprint(getProductSkuOptions(targetProduct), targetProduct.product_bundle);
5193
5539
  var nextLineFingerprint = buildProductLineFingerprint(getProductSkuOptions(nextProduct), nextProduct.product_bundle);
5194
5540
  var callerChangesVariant = Number(product_variant_id || 0) !== Number(targetProduct.product_variant_id || 0);
5195
- var callerChangesLineConfiguration = callerChangesVariant || previousLineFingerprint !== nextLineFingerprint;
5541
+ var callerChangesWeighing = getWeighedProductPriceFingerprint(targetProduct.product_sku) !== getWeighedProductPriceFingerprint(nextProduct.product_sku);
5542
+ var callerChangesLineConfiguration = callerChangesVariant || callerChangesWeighing || previousLineFingerprint !== nextLineFingerprint;
5196
5543
  var isPersistedOrderLine = targetProduct.order_detail_id !== undefined && targetProduct.order_detail_id !== null;
5197
5544
  var callerChangesDiscountList = Array.isArray(updates === null || updates === void 0 ? void 0 : updates.discount_list) && updates.discount_list.length > 0 && !isSameDiscountList(updates.discount_list, targetProduct.discount_list);
5198
5545
  var callerUpdatesManualPrice = (updates === null || updates === void 0 || (_metadata8 = updates.metadata) === null || _metadata8 === void 0 ? void 0 : _metadata8.price_override) !== undefined || (updates === null || updates === void 0 || (_metadata9 = updates.metadata) === null || _metadata9 === void 0 ? void 0 : _metadata9.is_manual_discount) !== undefined || (updates === null || updates === void 0 || (_metadata10 = updates.metadata) === null || _metadata10 === void 0 ? void 0 : _metadata10.product_discount_reason) !== undefined || callerChangesDiscountList;
@@ -5208,33 +5555,50 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5208
5555
  };
5209
5556
  return hasChangedPrice(updates.selling_price, targetProduct.selling_price) || hasChangedPrice(updates.original_price, targetProduct.original_price);
5210
5557
  }();
5558
+ var weighedSourcePrice = callerChangesWeighing ? resolveWeighedSourcePrice(nextProduct.product_sku) : undefined;
5559
+ var hasResolvedWeighedPrice = weighedSourcePrice !== undefined;
5560
+ if (hasResolvedWeighedPrice && !callerUpdatesSourcePrice) {
5561
+ var _ref84, _targetProduct$metada3, _targetProduct$metada4, _ref85, _targetProduct$metada5, _targetProduct$metada6;
5562
+ var nextMainOriginal = new Decimal(weighedSourcePrice).plus(sumOptionUnitPrice(getProductSkuOptions(nextProduct)));
5563
+ var previousMainOriginal = new Decimal((_ref84 = (_targetProduct$metada3 = (_targetProduct$metada4 = targetProduct.metadata) === null || _targetProduct$metada4 === void 0 ? void 0 : _targetProduct$metada4.main_product_original_price) !== null && _targetProduct$metada3 !== void 0 ? _targetProduct$metada3 : targetProduct.original_price) !== null && _ref84 !== void 0 ? _ref84 : 0);
5564
+ var previousMainSelling = new Decimal((_ref85 = (_targetProduct$metada5 = (_targetProduct$metada6 = targetProduct.metadata) === null || _targetProduct$metada6 === void 0 ? void 0 : _targetProduct$metada6.main_product_selling_price) !== null && _targetProduct$metada5 !== void 0 ? _targetProduct$metada5 : targetProduct.selling_price) !== null && _ref85 !== void 0 ? _ref85 : 0);
5565
+ // A manual final price remains fixed; other legacy discounts keep their amount
5566
+ // until Rules reapplies the currently selected wallet discount below.
5567
+ var nextMainSelling = isManualProductDiscountProduct(nextProduct) ? previousMainSelling : nextMainOriginal.minus(previousMainOriginal.minus(previousMainSelling));
5568
+ nextProduct.metadata = _objectSpread(_objectSpread({}, nextProduct.metadata), {}, {
5569
+ source_product_price: weighedSourcePrice,
5570
+ main_product_original_price: callerUpdatesMainOriginalPrice ? nextProduct.metadata.main_product_original_price : nextMainOriginal.toFixed(2),
5571
+ main_product_selling_price: callerUpdatesMainSellingPrice ? nextProduct.metadata.main_product_selling_price : Decimal.max(0, nextMainSelling).toFixed(2),
5572
+ price_schema_version: 2
5573
+ });
5574
+ }
5211
5575
  if (isPersistedOrderLine && !callerChangesLineConfiguration && !callerUpdatesManualPrice && !callerAllowsBookingReprice) {
5212
- var _targetProduct$metada3, _targetProduct$metada4, _targetProduct$metada5, _targetProduct$metada6, _targetProduct$metada7;
5576
+ var _targetProduct$metada7, _targetProduct$metada8, _targetProduct$metada9, _targetProduct$metada10, _targetProduct$metada11;
5213
5577
  nextProduct.selling_price = targetProduct.selling_price;
5214
5578
  nextProduct.original_price = targetProduct.original_price;
5215
5579
  nextProduct.payment_price = targetProduct.payment_price;
5216
5580
  nextProduct.metadata = _objectSpread(_objectSpread({}, nextProduct.metadata || {}), {}, {
5217
- source_product_price: (_targetProduct$metada3 = targetProduct.metadata) === null || _targetProduct$metada3 === void 0 ? void 0 : _targetProduct$metada3.source_product_price,
5218
- main_product_selling_price: (_targetProduct$metada4 = targetProduct.metadata) === null || _targetProduct$metada4 === void 0 ? void 0 : _targetProduct$metada4.main_product_selling_price,
5219
- main_product_original_price: (_targetProduct$metada5 = targetProduct.metadata) === null || _targetProduct$metada5 === void 0 ? void 0 : _targetProduct$metada5.main_product_original_price,
5220
- price_schema_version: (_targetProduct$metada6 = (_targetProduct$metada7 = targetProduct.metadata) === null || _targetProduct$metada7 === void 0 ? void 0 : _targetProduct$metada7.price_schema_version) !== null && _targetProduct$metada6 !== void 0 ? _targetProduct$metada6 : 2
5581
+ source_product_price: (_targetProduct$metada7 = targetProduct.metadata) === null || _targetProduct$metada7 === void 0 ? void 0 : _targetProduct$metada7.source_product_price,
5582
+ main_product_selling_price: (_targetProduct$metada8 = targetProduct.metadata) === null || _targetProduct$metada8 === void 0 ? void 0 : _targetProduct$metada8.main_product_selling_price,
5583
+ main_product_original_price: (_targetProduct$metada9 = targetProduct.metadata) === null || _targetProduct$metada9 === void 0 ? void 0 : _targetProduct$metada9.main_product_original_price,
5584
+ price_schema_version: (_targetProduct$metada10 = (_targetProduct$metada11 = targetProduct.metadata) === null || _targetProduct$metada11 === void 0 ? void 0 : _targetProduct$metada11.price_schema_version) !== null && _targetProduct$metada10 !== void 0 ? _targetProduct$metada10 : 2
5221
5585
  });
5222
5586
  nextProduct.product_bundle = this.preservePersistedBundlePriceFields(targetProduct.product_bundle, nextProduct.product_bundle);
5223
5587
  } else if (callerChangesLineConfiguration && callerUpdatesSourcePrice && (!callerUpdatesMainSellingPrice || !callerUpdatesMainOriginalPrice)) {
5224
- var _targetProduct$metada8, _targetProduct$metada9;
5588
+ var _targetProduct$metada12, _targetProduct$metada13, _targetProduct$metada14;
5225
5589
  // 新配置只传了 source 时,不能把未传的 main_product_* 从旧行继承下来。
5226
5590
  // 以新 source + 新 option 重建券前价;券后价未显式提供时保留旧主商品折扣额。
5227
- var previousMainOriginal = new Decimal(Number((_targetProduct$metada8 = targetProduct.metadata) === null || _targetProduct$metada8 === void 0 ? void 0 : _targetProduct$metada8.main_product_original_price) || 0);
5228
- var previousMainSelling = new Decimal(Number((_targetProduct$metada9 = targetProduct.metadata) === null || _targetProduct$metada9 === void 0 ? void 0 : _targetProduct$metada9.main_product_selling_price) || previousMainOriginal.toNumber());
5229
- var preservedDiscount = previousMainOriginal.minus(previousMainSelling);
5230
- var nextMainOriginal = new Decimal(Number(updates.metadata.source_product_price) || 0).plus(sumOptionUnitPrice(getProductSkuOptions(nextProduct)));
5591
+ var _previousMainOriginal = new Decimal(Number((_targetProduct$metada12 = targetProduct.metadata) === null || _targetProduct$metada12 === void 0 ? void 0 : _targetProduct$metada12.main_product_original_price) || 0);
5592
+ var _previousMainSelling = new Decimal(Number((_targetProduct$metada13 = (_targetProduct$metada14 = targetProduct.metadata) === null || _targetProduct$metada14 === void 0 ? void 0 : _targetProduct$metada14.main_product_selling_price) !== null && _targetProduct$metada13 !== void 0 ? _targetProduct$metada13 : _previousMainOriginal.toNumber()));
5593
+ var preservedDiscount = _previousMainOriginal.minus(_previousMainSelling);
5594
+ var _nextMainOriginal = new Decimal(Number(updates.metadata.source_product_price) || 0).plus(sumOptionUnitPrice(getProductSkuOptions(nextProduct)));
5231
5595
  nextProduct.metadata = _objectSpread(_objectSpread({}, nextProduct.metadata || {}), {}, {
5232
5596
  source_product_price: String(updates.metadata.source_product_price),
5233
- main_product_original_price: callerUpdatesMainOriginalPrice ? String(updates.metadata.main_product_original_price) : nextMainOriginal.toDecimalPlaces(2).toFixed(2),
5234
- main_product_selling_price: callerUpdatesMainSellingPrice ? String(updates.metadata.main_product_selling_price) : nextMainOriginal.minus(preservedDiscount).toDecimalPlaces(2).toFixed(2),
5597
+ main_product_original_price: callerUpdatesMainOriginalPrice ? String(updates.metadata.main_product_original_price) : _nextMainOriginal.toDecimalPlaces(2).toFixed(2),
5598
+ main_product_selling_price: callerUpdatesMainSellingPrice ? String(updates.metadata.main_product_selling_price) : hasResolvedWeighedPrice && isManualProductDiscountProduct(nextProduct) ? _previousMainSelling.toFixed(2) : _nextMainOriginal.minus(preservedDiscount).toDecimalPlaces(2).toFixed(2),
5235
5599
  price_schema_version: 2
5236
5600
  });
5237
- } else if (callerChangesVariant && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
5601
+ } else if (callerChangesVariant && !hasResolvedWeighedPrice && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
5238
5602
  // variant 已变化但 caller 没有显式报价时,旧 v2 metadata 不能继续充当权威价格源。
5239
5603
  // 清理后由 normalize 优先读取 metadata.origin.variant 中新 variant 的目录价;
5240
5604
  // 顶层 original/selling 的旧差额仍会作为 legacy discount 迁移到新价格。
@@ -5244,24 +5608,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5244
5608
  delete nextProduct.metadata.main_product_selling_price;
5245
5609
  delete nextProduct.metadata.main_product_original_price;
5246
5610
  delete nextProduct.metadata.price_schema_version;
5247
- } else if (callerChangesLineConfiguration && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
5248
- var _ref71, _targetProduct$metada10, _targetProduct$metada11, _ref72, _targetProduct$metada12, _targetProduct$metada13, _targetProduct$metada14;
5611
+ } else if (callerChangesLineConfiguration && !hasResolvedWeighedPrice && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
5612
+ var _ref86, _targetProduct$metada15, _targetProduct$metada16, _ref87, _targetProduct$metada17, _targetProduct$metada18, _targetProduct$metada19;
5249
5613
  // 仅 option / bundle 变化时,保留历史 source 和主商品折扣金额,
5250
5614
  // 但必须让 original 与 selling 一起随新的 option 金额移动。
5251
5615
  var previousOptionSum = sumOptionUnitPrice(getProductSkuOptions(targetProduct));
5252
5616
  var nextOptionSum = sumOptionUnitPrice(getProductSkuOptions(nextProduct));
5253
- var _previousMainOriginal = new Decimal(Number((_ref71 = (_targetProduct$metada10 = (_targetProduct$metada11 = targetProduct.metadata) === null || _targetProduct$metada11 === void 0 ? void 0 : _targetProduct$metada11.main_product_original_price) !== null && _targetProduct$metada10 !== void 0 ? _targetProduct$metada10 : targetProduct.original_price) !== null && _ref71 !== void 0 ? _ref71 : 0) || 0);
5254
- var _previousMainSelling = new Decimal(Number((_ref72 = (_targetProduct$metada12 = (_targetProduct$metada13 = targetProduct.metadata) === null || _targetProduct$metada13 === void 0 ? void 0 : _targetProduct$metada13.main_product_selling_price) !== null && _targetProduct$metada12 !== void 0 ? _targetProduct$metada12 : targetProduct.selling_price) !== null && _ref72 !== void 0 ? _ref72 : _previousMainOriginal.toNumber()) || 0);
5255
- var _preservedDiscount = _previousMainOriginal.minus(_previousMainSelling);
5256
- var previousSource = ((_targetProduct$metada14 = targetProduct.metadata) === null || _targetProduct$metada14 === void 0 ? void 0 : _targetProduct$metada14.source_product_price) != null ? new Decimal(Number(targetProduct.metadata.source_product_price) || 0) : _previousMainOriginal.minus(previousOptionSum);
5257
- var _nextMainOriginal = previousSource.plus(nextOptionSum);
5617
+ var _previousMainOriginal2 = new Decimal(Number((_ref86 = (_targetProduct$metada15 = (_targetProduct$metada16 = targetProduct.metadata) === null || _targetProduct$metada16 === void 0 ? void 0 : _targetProduct$metada16.main_product_original_price) !== null && _targetProduct$metada15 !== void 0 ? _targetProduct$metada15 : targetProduct.original_price) !== null && _ref86 !== void 0 ? _ref86 : 0) || 0);
5618
+ var _previousMainSelling2 = new Decimal(Number((_ref87 = (_targetProduct$metada17 = (_targetProduct$metada18 = targetProduct.metadata) === null || _targetProduct$metada18 === void 0 ? void 0 : _targetProduct$metada18.main_product_selling_price) !== null && _targetProduct$metada17 !== void 0 ? _targetProduct$metada17 : targetProduct.selling_price) !== null && _ref87 !== void 0 ? _ref87 : _previousMainOriginal2.toNumber()) || 0);
5619
+ var _preservedDiscount = _previousMainOriginal2.minus(_previousMainSelling2);
5620
+ var previousSource = ((_targetProduct$metada19 = targetProduct.metadata) === null || _targetProduct$metada19 === void 0 ? void 0 : _targetProduct$metada19.source_product_price) != null ? new Decimal(Number(targetProduct.metadata.source_product_price) || 0) : _previousMainOriginal2.minus(previousOptionSum);
5621
+ var _nextMainOriginal2 = previousSource.plus(nextOptionSum);
5258
5622
  nextProduct.metadata = _objectSpread(_objectSpread({}, nextProduct.metadata || {}), {}, {
5259
5623
  source_product_price: previousSource.toDecimalPlaces(2).toFixed(2),
5260
- main_product_original_price: _nextMainOriginal.toDecimalPlaces(2).toFixed(2),
5261
- main_product_selling_price: _nextMainOriginal.minus(_preservedDiscount).toDecimalPlaces(2).toFixed(2),
5624
+ main_product_original_price: _nextMainOriginal2.toDecimalPlaces(2).toFixed(2),
5625
+ main_product_selling_price: _nextMainOriginal2.minus(_preservedDiscount).toDecimalPlaces(2).toFixed(2),
5262
5626
  price_schema_version: 2
5263
5627
  });
5264
- } else if (callerUpdatesTopPrice && !callerUpdatesMainMeta) {
5628
+ } else if (callerUpdatesTopPrice && !callerUpdatesMainMeta && !hasResolvedWeighedPrice) {
5265
5629
  var _existedMeta = nextProduct.metadata || {};
5266
5630
  nextProduct.metadata = _objectSpread({}, _existedMeta);
5267
5631
  delete nextProduct.metadata.source_product_price;
@@ -5269,11 +5633,40 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5269
5633
  delete nextProduct.metadata.main_product_original_price;
5270
5634
  delete nextProduct.metadata.price_schema_version;
5271
5635
  }
5636
+ if (callerChangesLineConfiguration && resolveWeighedSourcePrice(nextProduct.product_sku) !== undefined && nextProduct.metadata.main_product_original_price != null && nextProduct.metadata.main_product_selling_price != null && isManualProductDiscountProduct(nextProduct)) {
5637
+ var _nextProduct$metadata;
5638
+ var originalPrice = composeLinePrice({
5639
+ mainPrice: nextProduct.metadata.main_product_original_price,
5640
+ bundle: withOriginalBundleOptionPrices(nextProduct.product_bundle),
5641
+ useOriginalBundle: true
5642
+ });
5643
+ var sellingPrice = composeLinePrice({
5644
+ mainPrice: nextProduct.metadata.main_product_selling_price,
5645
+ bundle: nextProduct.product_bundle
5646
+ });
5647
+ var previousManualDiscount = findManualProductDiscountItem(nextProduct.discount_list);
5648
+ nextProduct.original_price = originalPrice;
5649
+ nextProduct.metadata = _objectSpread(_objectSpread({}, nextProduct.metadata), {}, {
5650
+ origin: _objectSpread(_objectSpread({}, nextProduct.metadata.origin), {}, {
5651
+ _extend: _objectSpread(_objectSpread({}, (_nextProduct$metadata = nextProduct.metadata.origin) === null || _nextProduct$metadata === void 0 ? void 0 : _nextProduct$metadata._extend), {}, {
5652
+ origin_total: Number(originalPrice)
5653
+ })
5654
+ })
5655
+ });
5656
+ nextProduct.discount_list = mergeManualProductDiscountIntoList(nextProduct.discount_list, buildManualProductDiscountItem({
5657
+ originTotal: Number(originalPrice),
5658
+ sellingTotal: Number(sellingPrice),
5659
+ quantity: nextProduct.num,
5660
+ message: previousManualDiscount === null || previousManualDiscount === void 0 ? void 0 : previousManualDiscount.discount.message,
5661
+ discountway: previousManualDiscount === null || previousManualDiscount === void 0 ? void 0 : previousManualDiscount.discount.discountway,
5662
+ discount_per: previousManualDiscount === null || previousManualDiscount === void 0 ? void 0 : previousManualDiscount.discount.discount_per
5663
+ }));
5664
+ }
5272
5665
  // normalizeOrderProduct 幂等:v2 metadata 存在 → 保留 main_product_* 折扣重算 composite;
5273
5666
  // 否则 → 把顶层 selling_price 视作 source,派生 main_product_* 并写 price_schema_version: 2。
5274
5667
  var normalizedProduct = this.normalizeVirtualSettlementProductIfEnabled(mergeOrderProductDisplayFields(nextProduct, normalizeOrderProduct(nextProduct)));
5275
- normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
5276
- var preservedBookingUid = nextProduct.booking_uid || ((_nextProduct$metadata = nextProduct.metadata) === null || _nextProduct$metadata === void 0 ? void 0 : _nextProduct$metadata.booking_uid) || targetProduct.booking_uid || ((_targetProduct$metada15 = targetProduct.metadata) === null || _targetProduct$metada15 === void 0 ? void 0 : _targetProduct$metada15.booking_uid);
5668
+ normalizedProduct.discount_list = normalizeOrderProductDiscountList(isPersistedOrderLine ? syncReducedEntitlementPassUsageCount(normalizedProduct.discount_list, targetProduct.num, normalizedProduct.num) : normalizedProduct.discount_list);
5669
+ var preservedBookingUid = nextProduct.booking_uid || ((_nextProduct$metadata2 = nextProduct.metadata) === null || _nextProduct$metadata2 === void 0 ? void 0 : _nextProduct$metadata2.booking_uid) || targetProduct.booking_uid || ((_targetProduct$metada20 = targetProduct.metadata) === null || _targetProduct$metada20 === void 0 ? void 0 : _targetProduct$metada20.booking_uid);
5277
5670
  if (!booking && preservedBookingUid) {
5278
5671
  normalizedProduct.booking_uid = preservedBookingUid;
5279
5672
  normalizedProduct.metadata = _objectSpread(_objectSpread({}, normalizedProduct.metadata || {}), {}, {
@@ -5281,8 +5674,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5281
5674
  });
5282
5675
  }
5283
5676
  if (booking) {
5284
- var _normalizedProduct$me, _targetProduct$metada16;
5285
- var productUid = String(((_normalizedProduct$me = normalizedProduct.metadata) === null || _normalizedProduct$me === void 0 ? void 0 : _normalizedProduct$me.unique_identification_number) || ((_targetProduct$metada16 = targetProduct.metadata) === null || _targetProduct$metada16 === void 0 ? void 0 : _targetProduct$metada16.unique_identification_number) || unique_identification_number || createUuidV4());
5677
+ var _normalizedProduct$me, _targetProduct$metada21;
5678
+ var productUid = String(((_normalizedProduct$me = normalizedProduct.metadata) === null || _normalizedProduct$me === void 0 ? void 0 : _normalizedProduct$me.unique_identification_number) || ((_targetProduct$metada21 = targetProduct.metadata) === null || _targetProduct$metada21 === void 0 ? void 0 : _targetProduct$metada21.unique_identification_number) || unique_identification_number || createUuidV4());
5286
5679
  normalizedProduct.metadata = _objectSpread(_objectSpread({}, normalizedProduct.metadata || {}), {}, {
5287
5680
  unique_identification_number: productUid
5288
5681
  });
@@ -5302,6 +5695,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5302
5695
  });
5303
5696
  tempOrder.bookings = [].concat(_toConsumableArray(tempOrder.bookings || []), [linked.booking]);
5304
5697
  }
5698
+ if (callerChangesWeighing && !isManualProductDiscountProduct(normalizedProduct)) {
5699
+ var _normalizedProduct$me2;
5700
+ var uid = (_normalizedProduct$me2 = normalizedProduct.metadata) === null || _normalizedProduct$me2 === void 0 ? void 0 : _normalizedProduct$me2.unique_identification_number;
5701
+ if (uid) reapplyWeighedDiscountProductUids === null || reapplyWeighedDiscountProductUids === void 0 || reapplyWeighedDiscountProductUids.push(String(uid));
5702
+ }
5305
5703
  tempOrder.products[productIndex] = normalizedProduct;
5306
5704
  this.syncTempOrderHolderFromBookings(tempOrder);
5307
5705
  this.captureProductRuntime(tempOrder, updates, tempOrder.products[productIndex], (_tempOrder$products$p = tempOrder.products[productIndex].metadata) === null || _tempOrder$products$p === void 0 ? void 0 : _tempOrder$products$p.unique_identification_number);
@@ -5311,32 +5709,34 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5311
5709
  key: "updateOrderProduct",
5312
5710
  value: function () {
5313
5711
  var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(params) {
5314
- var tempOrder, updatedProductUid, promotionPayload;
5712
+ var tempOrder, reapplyWeighedDiscountProductUids, updatedProductUid, promotionPayload;
5315
5713
  return _regeneratorRuntime().wrap(function _callee25$(_context27) {
5316
5714
  while (1) switch (_context27.prev = _context27.next) {
5317
5715
  case 0:
5318
5716
  tempOrder = this.ensureTempOrder();
5319
- updatedProductUid = this.applyOrderProductUpdateToTempOrder(tempOrder, params);
5320
- _context27.next = 4;
5717
+ reapplyWeighedDiscountProductUids = [];
5718
+ updatedProductUid = this.applyOrderProductUpdateToTempOrder(tempOrder, params, reapplyWeighedDiscountProductUids);
5719
+ _context27.next = 5;
5321
5720
  return this.evaluatePromotion();
5322
- case 4:
5721
+ case 5:
5323
5722
  promotionPayload = _context27.sent;
5324
5723
  this.applyDiscount({
5724
+ reapplyWeighedDiscountProductUids: reapplyWeighedDiscountProductUids,
5325
5725
  reapplyBookingDiscountProductUids: params.allow_booking_discount_reapply && updatedProductUid ? [String(updatedProductUid)] : undefined
5326
5726
  });
5327
5727
  this.sanitizeTempOrderProducts(tempOrder);
5328
- _context27.next = 9;
5728
+ _context27.next = 10;
5329
5729
  return this.recalculateSummary({
5330
5730
  createIfMissing: true
5331
5731
  });
5332
- case 9:
5732
+ case 10:
5333
5733
  this.persistTempOrder();
5334
5734
  this.emitPromotionApplied(promotionPayload);
5335
5735
  this.logInfo('updateOrderProduct success', {
5336
5736
  params: params
5337
5737
  });
5338
5738
  return _context27.abrupt("return", tempOrder.products);
5339
- case 13:
5739
+ case 14:
5340
5740
  case "end":
5341
5741
  return _context27.stop();
5342
5742
  }
@@ -5351,8 +5751,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5351
5751
  key: "updateOrderProducts",
5352
5752
  value: function () {
5353
5753
  var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(paramsList) {
5354
- var _this32 = this;
5355
- var tempOrder, reapplyBookingDiscountProductUids;
5754
+ var _this36 = this;
5755
+ var tempOrder, reapplyWeighedDiscountProductUids, reapplyBookingDiscountProductUids;
5356
5756
  return _regeneratorRuntime().wrap(function _callee26$(_context28) {
5357
5757
  while (1) switch (_context28.prev = _context28.next) {
5358
5758
  case 0:
@@ -5363,24 +5763,26 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5363
5763
  }
5364
5764
  return _context28.abrupt("return", tempOrder.products);
5365
5765
  case 3:
5766
+ reapplyWeighedDiscountProductUids = [];
5366
5767
  reapplyBookingDiscountProductUids = paramsList.reduce(function (acc, params) {
5367
- var updatedProductUid = _this32.applyOrderProductUpdateToTempOrder(tempOrder, params);
5768
+ var updatedProductUid = _this36.applyOrderProductUpdateToTempOrder(tempOrder, params, reapplyWeighedDiscountProductUids);
5368
5769
  // 批量改预约时间时,延迟到最后一次折扣计算里统一恢复已选预约折扣卡。
5369
5770
  if (params.allow_booking_discount_reapply && updatedProductUid) {
5370
5771
  acc.push(String(updatedProductUid));
5371
5772
  }
5372
5773
  return acc;
5373
5774
  }, []);
5374
- _context28.next = 6;
5775
+ _context28.next = 7;
5375
5776
  return this.finalizeAfterProductsMutation(tempOrder, {
5777
+ reapplyWeighedDiscountProductUids: reapplyWeighedDiscountProductUids,
5376
5778
  reapplyBookingDiscountProductUids: reapplyBookingDiscountProductUids.length ? reapplyBookingDiscountProductUids : undefined
5377
5779
  });
5378
- case 6:
5780
+ case 7:
5379
5781
  this.logInfo('updateOrderProduct success', {
5380
5782
  paramsList: paramsList
5381
5783
  });
5382
5784
  return _context28.abrupt("return", tempOrder.products);
5383
- case 8:
5785
+ case 9:
5384
5786
  case "end":
5385
5787
  return _context28.stop();
5386
5788
  }
@@ -5395,8 +5797,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5395
5797
  key: "updateOrderProductQuantity",
5396
5798
  value: function () {
5397
5799
  var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(params) {
5398
- var _targetProduct$metada17;
5399
- var product_id, product_variant_id, num, unique_identification_number, identity_key, product_sku, product_bundle, tempOrder, identityLookup, productIndex, targetUid, targetProduct, normalizedProduct, settlementSnapshot, currencyProductId, asset, requiredAmount, balance, isVirtualSettlement, promotionPayload;
5800
+ var _targetProduct$metada22;
5801
+ var product_id, product_variant_id, num, unique_identification_number, identity_key, product_sku, product_bundle, tempOrder, identityLookup, productIndex, targetUid, targetProduct, isPersistedOrderLine, normalizedProduct, settlementSnapshot, currencyProductId, asset, requiredAmount, balance, isVirtualSettlement, promotionPayload;
5400
5802
  return _regeneratorRuntime().wrap(function _callee27$(_context29) {
5401
5803
  while (1) switch (_context29.prev = _context29.next) {
5402
5804
  case 0:
@@ -5434,16 +5836,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5434
5836
  throw new Error('[Order] 目标商品不存在,无法更新数量');
5435
5837
  case 13:
5436
5838
  targetProduct = tempOrder.products[productIndex];
5839
+ isPersistedOrderLine = targetProduct.order_detail_id !== undefined && targetProduct.order_detail_id !== null;
5437
5840
  normalizedProduct = this.normalizeVirtualSettlementProductIfEnabled(normalizeOrderProduct(_objectSpread(_objectSpread({}, targetProduct), {}, {
5438
5841
  num: getSafeProductNum(num),
5439
5842
  metadata: _objectSpread(_objectSpread({}, targetProduct.metadata || {}), {}, {
5440
- unique_identification_number: ((_targetProduct$metada17 = targetProduct.metadata) === null || _targetProduct$metada17 === void 0 ? void 0 : _targetProduct$metada17.unique_identification_number) || unique_identification_number
5843
+ unique_identification_number: ((_targetProduct$metada22 = targetProduct.metadata) === null || _targetProduct$metada22 === void 0 ? void 0 : _targetProduct$metada22.unique_identification_number) || unique_identification_number
5441
5844
  })
5442
5845
  })));
5443
- normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
5846
+ normalizedProduct.discount_list = normalizeOrderProductDiscountList(isPersistedOrderLine ? syncReducedEntitlementPassUsageCount(normalizedProduct.discount_list, targetProduct.num, normalizedProduct.num) : normalizedProduct.discount_list);
5444
5847
  settlementSnapshot = getSelectedSettlementSnapshot(normalizedProduct);
5445
5848
  if (!(this.isMultiCurrencySettlementEnabled() && (settlementSnapshot === null || settlementSnapshot === void 0 ? void 0 : settlementSnapshot.settlement_type) === 'virtual_currency' && tempOrder.customer_id && Number(tempOrder.customer_id) !== 1)) {
5446
- _context29.next = 26;
5849
+ _context29.next = 27;
5447
5850
  break;
5448
5851
  }
5449
5852
  currencyProductId = Number(settlementSnapshot.currency_product_id);
@@ -5451,11 +5854,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5451
5854
  return Number(item === null || item === void 0 ? void 0 : item.product_id) === currencyProductId;
5452
5855
  });
5453
5856
  if (asset) {
5454
- _context29.next = 22;
5857
+ _context29.next = 23;
5455
5858
  break;
5456
5859
  }
5457
5860
  throw new VirtualCurrencyAssetNotFoundError(currencyProductId);
5458
- case 22:
5861
+ case 23:
5459
5862
  requiredAmount = tempOrder.products.reduce(function (sum, item, index) {
5460
5863
  var current = index === productIndex ? normalizedProduct : item;
5461
5864
  var currentSnapshot = getSelectedSettlementSnapshot(current);
@@ -5463,44 +5866,44 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5463
5866
  }, new Decimal(0));
5464
5867
  balance = new Decimal(asset.balance || 0);
5465
5868
  if (!balance.lt(requiredAmount)) {
5466
- _context29.next = 26;
5869
+ _context29.next = 27;
5467
5870
  break;
5468
5871
  }
5469
5872
  throw new VirtualCurrencyBalanceError(balance.toFixed(2), requiredAmount.toFixed(2));
5470
- case 26:
5873
+ case 27:
5471
5874
  tempOrder.products[productIndex] = normalizedProduct;
5472
5875
  this.prepareVirtualSettlementTempOrder(tempOrder);
5473
5876
  isVirtualSettlement = this.isActiveVirtualSettlementOrder(tempOrder);
5474
5877
  if (isVirtualSettlement) {
5475
- _context29.next = 35;
5878
+ _context29.next = 36;
5476
5879
  break;
5477
5880
  }
5478
- _context29.next = 32;
5881
+ _context29.next = 33;
5479
5882
  return this.evaluatePromotion();
5480
- case 32:
5883
+ case 33:
5481
5884
  _context29.t0 = _context29.sent;
5482
- _context29.next = 36;
5885
+ _context29.next = 37;
5483
5886
  break;
5484
- case 35:
5485
- _context29.t0 = null;
5486
5887
  case 36:
5888
+ _context29.t0 = null;
5889
+ case 37:
5487
5890
  promotionPayload = _context29.t0;
5488
5891
  if (!isVirtualSettlement) {
5489
5892
  this.applyDiscount();
5490
5893
  }
5491
5894
  this.sanitizeTempOrderProducts(tempOrder);
5492
- _context29.next = 41;
5895
+ _context29.next = 42;
5493
5896
  return this.recalculateSummary({
5494
5897
  createIfMissing: true
5495
5898
  });
5496
- case 41:
5899
+ case 42:
5497
5900
  this.persistTempOrder();
5498
5901
  this.emitPromotionApplied(promotionPayload);
5499
5902
  this.logInfo('updateOrderProductQuantity success', {
5500
5903
  params: params
5501
5904
  });
5502
5905
  return _context29.abrupt("return", tempOrder.products);
5503
- case 45:
5906
+ case 46:
5504
5907
  case "end":
5505
5908
  return _context29.stop();
5506
5909
  }
@@ -5558,7 +5961,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5558
5961
  case 3:
5559
5962
  promotionPayload = _context30.sent;
5560
5963
  this.applyDiscount({
5561
- reapplyBookingDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids
5964
+ reapplyBookingDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids,
5965
+ reapplyWeighedDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyWeighedDiscountProductUids
5562
5966
  });
5563
5967
  this.sanitizeTempOrderProducts(tempOrder);
5564
5968
  _context30.next = 8;
@@ -5590,7 +5994,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5590
5994
  key: "removeProductsFromOrder",
5591
5995
  value: (function () {
5592
5996
  var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(identities, options) {
5593
- var _this33 = this;
5997
+ var _this37 = this;
5594
5998
  var tempOrder, productsBeforeRemove, bookingsBeforeRemove, preserveDisplayPosition, anchorIndex, productsAfterAnchor, matchedProducts, removedProducts, _i2, _removedProducts, product, linkedBookingUidsToRemove, _iterator21, _step21, _loop3, remainingProductIndex, remainingProduct, nextProduct, productsWithoutRemaining, nextProductIndex;
5595
5999
  return _regeneratorRuntime().wrap(function _callee29$(_context32) {
5596
6000
  while (1) switch (_context32.prev = _context32.next) {
@@ -5655,7 +6059,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5655
6059
  }
5656
6060
  if (productUid !== undefined && productUid !== null && productUid !== '') {
5657
6061
  bookingsBeforeRemove.forEach(function (booking) {
5658
- var bookingUid = _this33.getBookingUniqueIdentificationNumber(booking);
6062
+ var bookingUid = _this37.getBookingUniqueIdentificationNumber(booking);
5659
6063
  if (bookingUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) {
5660
6064
  linkedBookingUidsToRemove.add(bookingUid);
5661
6065
  }
@@ -5870,23 +6274,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5870
6274
  }, {
5871
6275
  key: "buildCurrentSubmitPayloadForLocalPrint",
5872
6276
  value: function buildCurrentSubmitPayloadForLocalPrint(params) {
5873
- var _params$cacheId, _this$otherParams5, _ref73, _params$businessCode, _this$otherParams6, _this$otherParams7;
6277
+ var _params$cacheId, _this$otherParams5, _ref88, _params$businessCode, _this$otherParams6, _this$otherParams7;
5874
6278
  var tempOrder = this.ensureTempOrder();
5875
6279
  this.persistTempOrder();
5876
6280
  var payload = buildSubmitPayload({
5877
6281
  tempOrder: tempOrder,
5878
6282
  cacheId: (_params$cacheId = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId !== void 0 ? _params$cacheId : this.cacheId,
5879
6283
  platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams5 = this.otherParams) === null || _this$otherParams5 === void 0 ? void 0 : _this$otherParams5.platform),
5880
- businessCode: (_ref73 = (_params$businessCode = params === null || params === void 0 ? void 0 : params.businessCode) !== null && _params$businessCode !== void 0 ? _params$businessCode : (_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.businessCode) !== null && _ref73 !== void 0 ? _ref73 : (_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.business_code,
6284
+ businessCode: (_ref88 = (_params$businessCode = params === null || params === void 0 ? void 0 : params.businessCode) !== null && _params$businessCode !== void 0 ? _params$businessCode : (_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.businessCode) !== null && _ref88 !== void 0 ? _ref88 : (_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.business_code,
5881
6285
  channel: params === null || params === void 0 ? void 0 : params.channel,
5882
6286
  type: params === null || params === void 0 ? void 0 : params.type,
5883
6287
  summary: this.store.summary || createEmptySummary(),
5884
6288
  enhance: function enhance(nextPayload) {
5885
- var _ref74, _tempOrder$order_numb, _ref75, _tempOrder$shop_order2, _ref76, _tempOrder$shop_full_;
6289
+ var _ref89, _tempOrder$order_numb, _ref90, _tempOrder$shop_order2, _ref91, _tempOrder$shop_full_;
5886
6290
  return _objectSpread(_objectSpread({}, nextPayload), {}, {
5887
- order_number: (_ref74 = (_tempOrder$order_numb = tempOrder.order_number) !== null && _tempOrder$order_numb !== void 0 ? _tempOrder$order_numb : nextPayload.order_number) !== null && _ref74 !== void 0 ? _ref74 : null,
5888
- shop_order_number: (_ref75 = (_tempOrder$shop_order2 = tempOrder.shop_order_number) !== null && _tempOrder$shop_order2 !== void 0 ? _tempOrder$shop_order2 : nextPayload.shop_order_number) !== null && _ref75 !== void 0 ? _ref75 : null,
5889
- shop_full_order_number: (_ref76 = (_tempOrder$shop_full_ = tempOrder.shop_full_order_number) !== null && _tempOrder$shop_full_ !== void 0 ? _tempOrder$shop_full_ : nextPayload.shop_full_order_number) !== null && _ref76 !== void 0 ? _ref76 : null,
6291
+ order_number: (_ref89 = (_tempOrder$order_numb = tempOrder.order_number) !== null && _tempOrder$order_numb !== void 0 ? _tempOrder$order_numb : nextPayload.order_number) !== null && _ref89 !== void 0 ? _ref89 : null,
6292
+ shop_order_number: (_ref90 = (_tempOrder$shop_order2 = tempOrder.shop_order_number) !== null && _tempOrder$shop_order2 !== void 0 ? _tempOrder$shop_order2 : nextPayload.shop_order_number) !== null && _ref90 !== void 0 ? _ref90 : null,
6293
+ shop_full_order_number: (_ref91 = (_tempOrder$shop_full_ = tempOrder.shop_full_order_number) !== null && _tempOrder$shop_full_ !== void 0 ? _tempOrder$shop_full_ : nextPayload.shop_full_order_number) !== null && _ref91 !== void 0 ? _ref91 : null,
5890
6294
  small_ticket_data_flag: 1
5891
6295
  });
5892
6296
  }
@@ -6050,7 +6454,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6050
6454
  key: "runSubmitTempOrder",
6051
6455
  value: function () {
6052
6456
  var _runSubmitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(params) {
6053
- var _params$cacheId3, _this$otherParams12, _ref77, _ref78, _submitSnapshot$busin, _this$otherParams13, _this$otherParams14, _submitSnapshot$type;
6457
+ var _params$cacheId3, _this$otherParams12, _ref92, _ref93, _submitSnapshot$busin, _this$otherParams13, _this$otherParams14, _submitSnapshot$type;
6054
6458
  var tempOrder, isOnlineStorePlatform, shouldConfirmPendingVoucherPayments, hasPaymentOverride, preparedPaymentOverride, latestSummary, effectiveCacheId, hasPaymentStatusOverride, shouldOverridePaymentStatus, hasSmallTicketDataFlagOverride, enhancePayload, submitSnapshot, payload, result, _payload$payments, _payload$payments2, backendErrorResponse, isLocalPendingSubmit, salesNotesState, submittedOrderId, resultRecord;
6055
6459
  return _regeneratorRuntime().wrap(function _callee37$(_context40) {
6056
6460
  while (1) switch (_context40.prev = _context40.next) {
@@ -6117,7 +6521,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6117
6521
  tempOrder: tempOrder,
6118
6522
  cacheId: effectiveCacheId,
6119
6523
  platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams12 = this.otherParams) === null || _this$otherParams12 === void 0 ? void 0 : _this$otherParams12.platform),
6120
- businessCode: (_ref77 = (_ref78 = (_submitSnapshot$busin = submitSnapshot.businessCode) !== null && _submitSnapshot$busin !== void 0 ? _submitSnapshot$busin : params === null || params === void 0 ? void 0 : params.businessCode) !== null && _ref78 !== void 0 ? _ref78 : (_this$otherParams13 = this.otherParams) === null || _this$otherParams13 === void 0 ? void 0 : _this$otherParams13.businessCode) !== null && _ref77 !== void 0 ? _ref77 : (_this$otherParams14 = this.otherParams) === null || _this$otherParams14 === void 0 ? void 0 : _this$otherParams14.business_code,
6524
+ businessCode: (_ref92 = (_ref93 = (_submitSnapshot$busin = submitSnapshot.businessCode) !== null && _submitSnapshot$busin !== void 0 ? _submitSnapshot$busin : params === null || params === void 0 ? void 0 : params.businessCode) !== null && _ref93 !== void 0 ? _ref93 : (_this$otherParams13 = this.otherParams) === null || _this$otherParams13 === void 0 ? void 0 : _this$otherParams13.businessCode) !== null && _ref92 !== void 0 ? _ref92 : (_this$otherParams14 = this.otherParams) === null || _this$otherParams14 === void 0 ? void 0 : _this$otherParams14.business_code,
6121
6525
  channel: params === null || params === void 0 ? void 0 : params.channel,
6122
6526
  type: (_submitSnapshot$type = submitSnapshot.type) !== null && _submitSnapshot$type !== void 0 ? _submitSnapshot$type : params === null || params === void 0 ? void 0 : params.type,
6123
6527
  summary: latestSummary,
@@ -6287,10 +6691,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6287
6691
  value: function extractSubmitErrorResponse(error) {
6288
6692
  var _error$response,
6289
6693
  _error$response2,
6290
- _this34 = this;
6694
+ _this38 = this;
6291
6695
  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];
6292
6696
  return candidates.find(function (candidate) {
6293
- return _this34.isSubmitErrorResponse(candidate);
6697
+ return _this38.isSubmitErrorResponse(candidate);
6294
6698
  }) || null;
6295
6699
  }
6296
6700
  }, {
@@ -6318,7 +6722,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6318
6722
  key: "syncPaymentsToOrder",
6319
6723
  value: function () {
6320
6724
  var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
6321
- var _this35 = this,
6725
+ var _this39 = this,
6322
6726
  _params$confirmPendin;
6323
6727
  var tempOrder, needsPaymentNumber, devicePrefix, mappedPayments, shouldConfirmPendingVoucherPayments, effectivePayments, completion, orderPaidPaymentTotal, paymentStatus, paymentSyncIdempotencyToken, enhancePayload, submitParams, submitResult;
6324
6728
  return _regeneratorRuntime().wrap(function _callee39$(_context42) {
@@ -6343,7 +6747,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6343
6747
  case 9:
6344
6748
  devicePrefix = _context42.t0;
6345
6749
  mappedPayments = mapPaymentItemsToOrderPayments((params.payments || []).map(function (payment) {
6346
- return _this35.normalizePaymentSource(payment, {
6750
+ return _this39.normalizePaymentSource(payment, {
6347
6751
  defaultPaid: false,
6348
6752
  devicePrefix: devicePrefix
6349
6753
  });
@@ -6422,7 +6826,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6422
6826
  }, {
6423
6827
  key: "createOrder",
6424
6828
  value: function createOrder(params) {
6425
- var _this36 = this;
6829
+ var _this40 = this;
6426
6830
  var order = _objectSpread({
6427
6831
  type: (params === null || params === void 0 ? void 0 : params.type) || 'appointment_booking',
6428
6832
  // 要从外面拿,virtual
@@ -6454,7 +6858,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6454
6858
 
6455
6859
  // 为预约补齐 holder 信息
6456
6860
  if (params !== null && params !== void 0 && (_params$extraData = params.extraData) !== null && _params$extraData !== void 0 && _params$extraData.is_add_holder_info) {
6457
- ensureCartItemOriginHolder(item, _this36.window);
6861
+ ensureCartItemOriginHolder(item, _this40.window);
6458
6862
  }
6459
6863
 
6460
6864
  // 购物车是否为普通商品
@@ -6754,17 +7158,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6754
7158
  key: "submitSalesOrder",
6755
7159
  value: function () {
6756
7160
  var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44(params) {
6757
- var url, query, fetchUrl;
7161
+ var url, query, fetchUrl, requestQuery;
6758
7162
  return _regeneratorRuntime().wrap(function _callee44$(_context47) {
6759
7163
  while (1) switch (_context47.prev = _context47.next) {
6760
7164
  case 0:
6761
7165
  url = params.url, query = params.query;
6762
7166
  fetchUrl = url || '/order/sales/checkout';
6763
- return _context47.abrupt("return", this.request.post(fetchUrl, query, {
7167
+ requestQuery = this.isSalesCheckoutHandledByOsServer(fetchUrl) ? query : stripOsPrivatePayloadFields(query);
7168
+ return _context47.abrupt("return", this.request.post(fetchUrl, requestQuery, {
6764
7169
  osServer: true,
6765
7170
  customToast: function customToast() {}
6766
7171
  }));
6767
- case 3:
7172
+ case 4:
6768
7173
  case "end":
6769
7174
  return _context47.stop();
6770
7175
  }
@@ -6775,6 +7180,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6775
7180
  }
6776
7181
  return submitSalesOrder;
6777
7182
  }()
7183
+ }, {
7184
+ key: "isSalesCheckoutHandledByOsServer",
7185
+ value: function isSalesCheckoutHandledByOsServer(fetchUrl) {
7186
+ var _this$core2, _this$request;
7187
+ var server = (_this$core2 = this.core) === null || _this$core2 === void 0 ? void 0 : _this$core2.server;
7188
+ if (!server || typeof server.hasRoute !== 'function') return false;
7189
+ var requestBaseUrl = String(((_this$request = this.request) === null || _this$request === void 0 ? void 0 : _this$request.baseUrl) || '/shop').replace(/\/+$/, '');
7190
+ if (!requestBaseUrl.startsWith('/')) return false;
7191
+ var normalizedFetchUrl = fetchUrl.startsWith('/') ? fetchUrl : "/".concat(fetchUrl);
7192
+ var routePath = normalizedFetchUrl === requestBaseUrl || normalizedFetchUrl.startsWith("".concat(requestBaseUrl, "/")) ? normalizedFetchUrl : "".concat(requestBaseUrl).concat(normalizedFetchUrl);
7193
+ return server.hasRoute('post', routePath) === true;
7194
+ }
7195
+
6778
7196
  /**
6779
7197
  * 发送支付链接邮件。
6780
7198
  *
@@ -6916,8 +7334,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6916
7334
  allowUnresolvedSalesNotes: isSessionStorageHydrate
6917
7335
  });
6918
7336
  this.store.tempOrder = nextTempOrder;
7337
+ this.clearCustomerWalletRuntimeState();
6919
7338
  if (!isSessionStorageHydrate) {
6920
- _context50.next = 30;
7339
+ _context50.next = 31;
6921
7340
  break;
6922
7341
  }
6923
7342
  // 会话快照是未提交购物车,不应获得编辑订单的 saved/edit 标记与服务端基线。
@@ -6933,24 +7352,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6933
7352
  nextTempOrder.discount_list = restoredSessionDiscounts;
6934
7353
  this.store.summary = createEmptySummary();
6935
7354
  this.store.lastOrderInfo = undefined;
6936
- _context50.next = 23;
7355
+ _context50.next = 24;
6937
7356
  return (_this$store$discount24 = this.store.discount) === null || _this$store$discount24 === void 0 ? void 0 : _this$store$discount24.setOriginalDiscountList(cloneDeep(restoredSessionDiscounts));
6938
- case 23:
6939
- _context50.next = 25;
7357
+ case 24:
7358
+ _context50.next = 26;
6940
7359
  return (_this$store$discount25 = this.store.discount) === null || _this$store$discount25 === void 0 ? void 0 : _this$store$discount25.setDiscountList(cloneDeep(restoredSessionDiscounts));
6941
- case 25:
7360
+ case 26:
6942
7361
  if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
6943
- _context50.next = 28;
7362
+ _context50.next = 29;
6944
7363
  break;
6945
7364
  }
6946
- _context50.next = 28;
7365
+ _context50.next = 29;
6947
7366
  return this.recalculateSummary({
6948
7367
  createIfMissing: false
6949
7368
  });
6950
- case 28:
7369
+ case 29:
6951
7370
  this.persistTempOrder();
6952
7371
  return _context50.abrupt("return", nextTempOrder);
6953
- case 30:
7372
+ case 31:
6954
7373
  // Server list compatibility may synthesize order_id from external_sale_number; tempOrder must not.
6955
7374
  sourceLastOrderInfo = sourceRaw.lastOrderInfo || sourceRaw;
6956
7375
  isDraftOrder = Number(nextTempOrder.is_draft_order || 0) === 1;
@@ -7001,28 +7420,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7001
7420
  nextDiscounts = [].concat(_toConsumableArray(hydratedEditDiscounts), _toConsumableArray(retainedScanDiscounts));
7002
7421
  shouldSkipEmptyDiscountSync = nextDiscounts.length === 0 && currentDiscounts.length === 0;
7003
7422
  if (shouldSkipEmptyDiscountSync) {
7004
- _context50.next = 54;
7423
+ _context50.next = 55;
7005
7424
  break;
7006
7425
  }
7007
7426
  OrderModule.populateSavedAmounts(nextTempOrder.products, nextDiscounts);
7008
- _context50.next = 52;
7427
+ _context50.next = 53;
7009
7428
  return (_this$store$discount27 = this.store.discount) === null || _this$store$discount27 === void 0 ? void 0 : _this$store$discount27.setOriginalDiscountList(nextDiscounts);
7010
- case 52:
7011
- _context50.next = 54;
7429
+ case 53:
7430
+ _context50.next = 55;
7012
7431
  return (_this$store$discount28 = this.store.discount) === null || _this$store$discount28 === void 0 ? void 0 : _this$store$discount28.setDiscountList(nextDiscounts);
7013
- case 54:
7432
+ case 55:
7014
7433
  if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
7015
- _context50.next = 57;
7434
+ _context50.next = 58;
7016
7435
  break;
7017
7436
  }
7018
- _context50.next = 57;
7437
+ _context50.next = 58;
7019
7438
  return this.recalculateSummary({
7020
7439
  createIfMissing: false
7021
7440
  });
7022
- case 57:
7441
+ case 58:
7023
7442
  this.persistTempOrder();
7024
7443
  return _context50.abrupt("return", nextTempOrder);
7025
- case 59:
7444
+ case 60:
7026
7445
  case "end":
7027
7446
  return _context50.stop();
7028
7447
  }
@@ -7081,10 +7500,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7081
7500
  _step22;
7082
7501
  try {
7083
7502
  for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
7084
- var _product$metadata11;
7503
+ var _product$metadata13;
7085
7504
  var product = _step22.value;
7086
7505
  var productUid = getOrderCollectionUid('product', product);
7087
- var bookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_product$metadata11 = product.metadata) === null || _product$metadata11 === void 0 ? void 0 : _product$metadata11.booking_uid);
7506
+ var bookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_product$metadata13 = product.metadata) === null || _product$metadata13 === void 0 ? void 0 : _product$metadata13.booking_uid);
7088
7507
  if (!productUid || bookingUid === undefined || bookingUid === null || bookingUid === '') {
7089
7508
  continue;
7090
7509
  }
@@ -7142,7 +7561,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7142
7561
  }, {
7143
7562
  key: "normalizeTempOrderForRuntime",
7144
7563
  value: function normalizeTempOrderForRuntime(raw, options) {
7145
- var _this37 = this,
7564
+ var _this41 = this,
7146
7565
  _raw$_extend;
7147
7566
  var runtimeRaw = this.withoutSyntheticDraftOrderIdForRuntime(raw);
7148
7567
  var nextTempOrder = _objectSpread(_objectSpread({}, this.createDefaultTempOrderInstance()), runtimeRaw || {});
@@ -7167,12 +7586,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7167
7586
  nextTempOrder.holder = raw.holder && _typeof(raw.holder) === 'object' ? _objectSpread({}, raw.holder) : null;
7168
7587
  var rawProducts = Array.isArray(raw.products) ? raw.products : [];
7169
7588
  nextTempOrder.products = rawProducts.length > 0 ? rawProducts.map(function (p) {
7170
- return _this37.normalizeHydratedOrderProduct(p, {
7589
+ return _this41.normalizeHydratedOrderProduct(p, {
7171
7590
  makeEditMark: options === null || options === void 0 ? void 0 : options.makeEditMark
7172
7591
  });
7173
7592
  }) : [];
7174
7593
  nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map(function (b) {
7175
- var booking = _this37.normalizeHydratedBookingHolder(b || {});
7594
+ var booking = _this41.normalizeHydratedBookingHolder(b || {});
7176
7595
  return _objectSpread(_objectSpread({}, booking), {}, {
7177
7596
  is_all: normalizeBookingIsAll(booking),
7178
7597
  sub_type: normalizeBookingSubType(booking)
@@ -7222,15 +7641,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7222
7641
  _step24;
7223
7642
  try {
7224
7643
  for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
7225
- var _product$metadata12, _ref79, _ref80, _existed$origin, _rawProduct$metadata;
7644
+ var _product$metadata14, _ref94, _ref95, _existed$origin, _rawProduct$metadata;
7226
7645
  var _step24$value = _slicedToArray(_step24.value, 2),
7227
7646
  index = _step24$value[0],
7228
7647
  product = _step24$value[1];
7229
- var uid = (_product$metadata12 = product.metadata) === null || _product$metadata12 === void 0 ? void 0 : _product$metadata12.unique_identification_number;
7648
+ var uid = (_product$metadata14 = product.metadata) === null || _product$metadata14 === void 0 ? void 0 : _product$metadata14.unique_identification_number;
7230
7649
  if (!uid) continue;
7231
7650
  var existed = productsByUid[uid] && _typeof(productsByUid[uid]) === 'object' ? productsByUid[uid] : {};
7232
7651
  var rawProduct = rawProducts[index] && _typeof(rawProducts[index]) === 'object' ? rawProducts[index] : product;
7233
- var origin = (_ref79 = (_ref80 = (_existed$origin = existed.origin) !== null && _existed$origin !== void 0 ? _existed$origin : rawProduct._origin) !== null && _ref80 !== void 0 ? _ref80 : (_rawProduct$metadata = rawProduct.metadata) === null || _rawProduct$metadata === void 0 ? void 0 : _rawProduct$metadata.origin) !== null && _ref79 !== void 0 ? _ref79 : rawProduct;
7652
+ var origin = (_ref94 = (_ref95 = (_existed$origin = existed.origin) !== null && _existed$origin !== void 0 ? _existed$origin : rawProduct._origin) !== null && _ref95 !== void 0 ? _ref95 : (_rawProduct$metadata = rawProduct.metadata) === null || _rawProduct$metadata === void 0 ? void 0 : _rawProduct$metadata.origin) !== null && _ref94 !== void 0 ? _ref94 : rawProduct;
7234
7653
  var originSnapshot = cloneDeep(origin);
7235
7654
  var productOptionString = this.buildHydratedProductOptionString(rawProduct) || this.buildHydratedProductOptionString(product);
7236
7655
  if (productOptionString && originSnapshot && _typeof(originSnapshot) === 'object') {
@@ -7281,8 +7700,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7281
7700
  var bookingUidByProductUid = new Map();
7282
7701
  var productByUid = new Map();
7283
7702
  (tempOrder.products || []).forEach(function (product) {
7284
- var _product$metadata13;
7285
- var productUid = (product === null || product === void 0 || (_product$metadata13 = product.metadata) === null || _product$metadata13 === void 0 ? void 0 : _product$metadata13.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
7703
+ var _product$metadata15;
7704
+ var productUid = (product === null || product === void 0 || (_product$metadata15 = product.metadata) === null || _product$metadata15 === void 0 ? void 0 : _product$metadata15.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
7286
7705
  if (productUid !== undefined && productUid !== null && String(productUid) !== '') {
7287
7706
  productByUid.set(String(productUid), product);
7288
7707
  }
@@ -7303,8 +7722,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7303
7722
  bookingUidByProductUid.set(String(productUid), bookingUid);
7304
7723
  });
7305
7724
  (tempOrder.products || []).forEach(function (product) {
7306
- var _product$metadata14;
7307
- var productUid = (product === null || product === void 0 || (_product$metadata14 = product.metadata) === null || _product$metadata14 === void 0 ? void 0 : _product$metadata14.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
7725
+ var _product$metadata16;
7726
+ var productUid = (product === null || product === void 0 || (_product$metadata16 = product.metadata) === null || _product$metadata16 === void 0 ? void 0 : _product$metadata16.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
7308
7727
  if (productUid === undefined || productUid === null || String(productUid) === '') return;
7309
7728
  var bookingUid = bookingUidByProductUid.get(String(productUid));
7310
7729
  if (!bookingUid) return;
@@ -7359,10 +7778,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7359
7778
  }, {
7360
7779
  key: "normalizeHydratedProductOptionItem",
7361
7780
  value: function normalizeHydratedProductOptionItem(optionItem) {
7362
- var _ref81, _optionItem$num, _ref82, _optionItem$add_price;
7363
- var rawNum = (_ref81 = (_optionItem$num = optionItem === null || optionItem === void 0 ? void 0 : optionItem.num) !== null && _optionItem$num !== void 0 ? _optionItem$num : optionItem === null || optionItem === void 0 ? void 0 : optionItem.quantity) !== null && _ref81 !== void 0 ? _ref81 : 1;
7781
+ var _ref96, _optionItem$num, _ref97, _optionItem$add_price;
7782
+ var rawNum = (_ref96 = (_optionItem$num = optionItem === null || optionItem === void 0 ? void 0 : optionItem.num) !== null && _optionItem$num !== void 0 ? _optionItem$num : optionItem === null || optionItem === void 0 ? void 0 : optionItem.quantity) !== null && _ref96 !== void 0 ? _ref96 : 1;
7364
7783
  var parsedNum = Number(rawNum);
7365
- var rawPrice = (_ref82 = (_optionItem$add_price = optionItem === null || optionItem === void 0 ? void 0 : optionItem.add_price) !== null && _optionItem$add_price !== void 0 ? _optionItem$add_price : optionItem === null || optionItem === void 0 ? void 0 : optionItem.price) !== null && _ref82 !== void 0 ? _ref82 : 0;
7784
+ var rawPrice = (_ref97 = (_optionItem$add_price = optionItem === null || optionItem === void 0 ? void 0 : optionItem.add_price) !== null && _optionItem$add_price !== void 0 ? _optionItem$add_price : optionItem === null || optionItem === void 0 ? void 0 : optionItem.price) !== null && _ref97 !== void 0 ? _ref97 : 0;
7366
7785
  var parsedPrice = Number(rawPrice);
7367
7786
  var normalized = _objectSpread(_objectSpread({}, optionItem), {}, {
7368
7787
  option_group_item_id: optionItem === null || optionItem === void 0 ? void 0 : optionItem.option_group_item_id,
@@ -7379,7 +7798,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7379
7798
  }, {
7380
7799
  key: "normalizeHydratedOrderProduct",
7381
7800
  value: function normalizeHydratedOrderProduct(product, options) {
7382
- var _this38 = this;
7801
+ var _this42 = this;
7383
7802
  var row = _objectSpread({}, product || {});
7384
7803
  if (row.num === undefined && row.product_quantity !== undefined) {
7385
7804
  row.num = row.product_quantity;
@@ -7387,7 +7806,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7387
7806
  var productSku = ensureProductSku(row);
7388
7807
  row.product_sku = _objectSpread(_objectSpread({}, productSku), {}, {
7389
7808
  option: normalizeProductSkuOptions(productSku.option.map(function (optionItem) {
7390
- return _this38.normalizeHydratedProductOptionItem(optionItem || {});
7809
+ return _this42.normalizeHydratedProductOptionItem(optionItem || {});
7391
7810
  }))
7392
7811
  });
7393
7812
  delete row["product_".concat('option', "_item")];
@@ -7475,8 +7894,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7475
7894
  }, {
7476
7895
  key: "getVouchers",
7477
7896
  value: function getVouchers() {
7478
- var _this$store$tempOrder6;
7479
- return ((_this$store$tempOrder6 = this.store.tempOrder) === null || _this$store$tempOrder6 === void 0 ? void 0 : _this$store$tempOrder6.vouchers) || [];
7897
+ var _this$store$tempOrder8;
7898
+ return ((_this$store$tempOrder8 = this.store.tempOrder) === null || _this$store$tempOrder8 === void 0 ? void 0 : _this$store$tempOrder8.vouchers) || [];
7480
7899
  }
7481
7900
  }], [{
7482
7901
  key: "populateSavedAmounts",
@@ -7495,11 +7914,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
7495
7914
  targetMap.set(discountKey, (targetMap.get(discountKey) || new Decimal(0)).plus(amount));
7496
7915
  };
7497
7916
  var addProductDiscountAmount = function addProductDiscountAmount(discount, quantity, isPersistedProduct) {
7498
- var _discount$discount3, _discount$metadata;
7917
+ var _discount$discount3, _discount$metadata2;
7499
7918
  var discountKey = ((_discount$discount3 = discount.discount) === null || _discount$discount3 === void 0 ? void 0 : _discount$discount3.resource_id) || discount.id;
7500
7919
  if (discountKey == null) return;
7501
7920
  var qty = Number(quantity) || 1;
7502
- 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);
7921
+ var amount = new Decimal(discount.amount || 0).times(qty).plus(((_discount$metadata2 = discount.metadata) === null || _discount$metadata2 === void 0 ? void 0 : _discount$metadata2.product_discount_difference) || 0);
7503
7922
  addDiscountAmount(savedMap, discountKey, amount);
7504
7923
  addDiscountAmount(isPersistedProduct || discount.order_discount_id != null ? editModeSavedMap : runtimeSavedMap, discountKey, amount);
7505
7924
  };