@pisell/pisellos 2.3.172 → 2.3.174

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 (83) hide show
  1. package/dist/index.d.ts +0 -1
  2. package/dist/index.js +0 -1
  3. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +2 -1
  4. package/dist/model/strategy/adapter/promotion/evaluator.js +14 -8
  5. package/dist/modules/BookingContext/utils/productExtend.d.ts +5 -0
  6. package/dist/modules/BookingContext/utils/productExtend.js +61 -23
  7. package/dist/modules/Discount/index.js +0 -1
  8. package/dist/modules/OpenData/index.d.ts +1 -0
  9. package/dist/modules/OpenData/index.js +1 -0
  10. package/dist/modules/OpenData/salesSettings.d.ts +32 -0
  11. package/dist/modules/OpenData/salesSettings.js +80 -0
  12. package/dist/modules/OpenData/types.d.ts +13 -0
  13. package/dist/modules/Order/index.d.ts +3 -25
  14. package/dist/modules/Order/index.js +1313 -1772
  15. package/dist/modules/Order/types.d.ts +0 -7
  16. package/dist/modules/Order/utils/discountProductLineIdentity.js +2 -2
  17. package/dist/modules/ProductList/index.js +12 -33
  18. package/dist/modules/Rules/index.d.ts +0 -2
  19. package/dist/modules/Rules/index.js +21 -29
  20. package/dist/solution/BaseSales/index.d.ts +1 -16
  21. package/dist/solution/BaseSales/index.js +1325 -1511
  22. package/dist/solution/BookingTicket/index.d.ts +2 -2
  23. package/dist/solution/BookingTicket/index.js +108 -200
  24. package/dist/solution/BookingTicket/types.d.ts +2 -14
  25. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +1 -1
  26. package/dist/solution/BookingTicket/utils/addProductDecision.js +3 -4
  27. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +58 -94
  28. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +0 -1
  29. package/dist/solution/BookingTicket/utils/scan/handleScan.js +1 -2
  30. package/dist/solution/UnifiedBookingSales/index.d.ts +23 -2
  31. package/dist/solution/UnifiedBookingSales/index.js +923 -683
  32. package/dist/solution/UnifiedBookingSales/salesSettings.d.ts +16 -0
  33. package/dist/solution/UnifiedBookingSales/salesSettings.js +81 -0
  34. package/dist/utils/platform.d.ts +0 -2
  35. package/dist/utils/platform.js +0 -6
  36. package/lib/index.d.ts +0 -1
  37. package/lib/index.js +0 -12
  38. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +2 -1
  39. package/lib/model/strategy/adapter/promotion/evaluator.js +13 -7
  40. package/lib/modules/BookingContext/utils/productExtend.d.ts +5 -0
  41. package/lib/modules/BookingContext/utils/productExtend.js +36 -3
  42. package/lib/modules/Discount/index.js +0 -1
  43. package/lib/modules/OpenData/index.d.ts +1 -0
  44. package/lib/modules/OpenData/index.js +12 -0
  45. package/lib/modules/OpenData/salesSettings.d.ts +32 -0
  46. package/lib/modules/OpenData/salesSettings.js +70 -0
  47. package/lib/modules/OpenData/types.d.ts +13 -0
  48. package/lib/modules/Order/index.d.ts +3 -25
  49. package/lib/modules/Order/index.js +38 -192
  50. package/lib/modules/Order/types.d.ts +0 -7
  51. package/lib/modules/Order/utils/discountProductLineIdentity.js +1 -1
  52. package/lib/modules/ProductList/index.js +0 -15
  53. package/lib/modules/Rules/index.d.ts +0 -2
  54. package/lib/modules/Rules/index.js +0 -6
  55. package/lib/solution/BaseSales/index.d.ts +1 -16
  56. package/lib/solution/BaseSales/index.js +9 -89
  57. package/lib/solution/BookingTicket/index.d.ts +2 -2
  58. package/lib/solution/BookingTicket/index.js +2 -38
  59. package/lib/solution/BookingTicket/types.d.ts +2 -14
  60. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +1 -1
  61. package/lib/solution/BookingTicket/utils/addProductDecision.js +3 -4
  62. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +2 -14
  63. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +0 -1
  64. package/lib/solution/BookingTicket/utils/scan/handleScan.js +1 -2
  65. package/lib/solution/UnifiedBookingSales/index.d.ts +23 -2
  66. package/lib/solution/UnifiedBookingSales/index.js +131 -15
  67. package/lib/solution/UnifiedBookingSales/salesSettings.d.ts +16 -0
  68. package/lib/solution/UnifiedBookingSales/salesSettings.js +72 -0
  69. package/lib/utils/platform.d.ts +0 -2
  70. package/lib/utils/platform.js +0 -7
  71. package/package.json +1 -1
  72. package/dist/inventory/index.d.ts +0 -92
  73. package/dist/inventory/index.js +0 -509
  74. package/dist/modules/Order/utils/productVoucherGroups.d.ts +0 -15
  75. package/dist/modules/Order/utils/productVoucherGroups.js +0 -115
  76. package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +0 -10
  77. package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +0 -117
  78. package/lib/inventory/index.d.ts +0 -92
  79. package/lib/inventory/index.js +0 -287
  80. package/lib/modules/Order/utils/productVoucherGroups.d.ts +0 -15
  81. package/lib/modules/Order/utils/productVoucherGroups.js +0 -64
  82. package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +0 -10
  83. package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +0 -71
@@ -21,7 +21,6 @@ var _weighedProduct = require("./utils/weighedProduct");
21
21
  var _pickupTiming = require("./pickupTiming");
22
22
  var _dayjs = _interopRequireDefault(require("dayjs"));
23
23
  var _availability = require("../Discount/availability");
24
- var _productVoucherGroups = require("./utils/productVoucherGroups");
25
24
  var _osPrivatePayload = require("../../utils/os-private-payload");
26
25
  var _salesNotes = require("./salesNotes");
27
26
  var _paymentUtils = require("./payment-utils");
@@ -148,66 +147,6 @@ class OrderModule extends _BaseModule.BaseModule {
148
147
  rulesHooksOverride;
149
148
  moduleHooksOverride;
150
149
  orderHooks;
151
- cartCommandQueue = Promise.resolve();
152
- queueCartCommand(run) {
153
- if (!this.orderHooks?.onBeforeCartCommit && !this.store.tempOrder?._extend?.productVoucherGroups?.length) return run();
154
- const pending = this.cartCommandQueue.then(run, run);
155
- this.cartCommandQueue = pending.catch(() => undefined);
156
- return pending;
157
- }
158
-
159
- /** Use the exact Order normalizers/merge rules on a private draft, not a second projection. */
160
- beginCartMutation() {
161
- const current = this.ensureTempOrder();
162
- const guard = this.orderHooks?.onBeforeCartCommit;
163
- if (!guard && !current._extend?.productVoucherGroups?.length) return {
164
- draft: current,
165
- commit: undefined
166
- };
167
- const before = (0, _lodashEs.cloneDeep)(current);
168
- const draft = (0, _lodashEs.cloneDeep)(current);
169
- return {
170
- draft,
171
- commit: async options => {
172
- if (options?.isCurrentOrder && !options.isCurrentOrder()) return current;
173
- (0, _productVoucherGroups.validateProductVoucherGroups)(draft, this.getDiscountList(), before);
174
- await guard?.({
175
- currentItems: (0, _lodashEs.cloneDeep)(before.products),
176
- proposedItems: (0, _lodashEs.cloneDeep)(draft.products)
177
- });
178
- if (options?.isCurrentOrder && !options.isCurrentOrder()) return current;
179
- if (this.store.tempOrder !== current || guard !== this.orderHooks?.onBeforeCartCommit || !(0, _lodashEs.isEqual)(current, before)) {
180
- throw Object.assign(new Error('The cart changed. Please try again.'), {
181
- code: 'SALES_GUARD_REJECTED'
182
- });
183
- }
184
- // Recheck synchronous order/availability guards after async inventory validation.
185
- options?.beforeCommit?.();
186
- Object.assign(current, draft);
187
- return current;
188
- }
189
- };
190
- }
191
-
192
- /** Serializes checkout preparation with local cart commands; hydration remains outside this guard. */
193
- async prepareCheckout(prepare) {
194
- const run = async () => {
195
- const order = this.ensureTempOrder();
196
- (0, _productVoucherGroups.validateProductVoucherGroups)(order, this.getDiscountList(), undefined, true);
197
- const items = (0, _lodashEs.cloneDeep)(order.products);
198
- const result = await prepare(items);
199
- if (this.store.tempOrder !== order || !(0, _lodashEs.isEqual)(order.products, items)) {
200
- throw Object.assign(new Error('The cart changed. Please try again.'), {
201
- code: 'SALES_GUARD_REJECTED'
202
- });
203
- }
204
- (0, _productVoucherGroups.validateProductVoucherGroups)(order, this.getDiscountList(), undefined, true);
205
- return result;
206
- };
207
- const pending = this.cartCommandQueue.then(run, run);
208
- this.cartCommandQueue = pending.catch(() => undefined);
209
- return pending;
210
- }
211
150
  otherParams;
212
151
  // ─── 促销/赠品 ────────────────────────────────────
213
152
  /** 评估器引用;由 SalesSdkProvider 注入,未注入时 applyPromotion 静默跳过 */
@@ -495,11 +434,8 @@ class OrderModule extends _BaseModule.BaseModule {
495
434
  * @example
496
435
  * orderModule.updateOtherParams({ cacheId: 'cache-2', channel: 'pos' });
497
436
  */
498
- updateOtherParams(params, options) {
437
+ updateOtherParams(params) {
499
438
  const otherParams = params || {};
500
- if (options && Object.prototype.hasOwnProperty.call(options, 'hooks')) {
501
- this.moduleHooksOverride = options.hooks;
502
- }
503
439
  this.syncSessionStorageOptions(otherParams);
504
440
  this.salesSummaryModuleName = otherParams.salesSummaryModuleName;
505
441
  this.rulesHooksOverride = otherParams.rules?.hooks;
@@ -606,26 +542,6 @@ class OrderModule extends _BaseModule.BaseModule {
606
542
  hooks: this.rulesHooksOverride || this.createDefaultRulesHooks()
607
543
  });
608
544
  this.store.rules = rules;
609
- rules.setDiscountScope((product, discount) => (0, _productVoucherGroups.allowsProductVoucher)(this.store.tempOrder, product, discount));
610
- }
611
- setProductVoucherGroups(groups) {
612
- const order = this.ensureTempOrder();
613
- const ids = new Set();
614
- const keys = new Set();
615
- const known = new Map(this.getDiscountList().map(discount => [String(discount.id), discount]));
616
- for (const group of groups) {
617
- if (!group.key || keys.has(group.key)) throw (0, _productVoucherGroups.voucherGroupError)();
618
- keys.add(group.key);
619
- for (const id of group.discountIds) {
620
- const discount = known.get(String(id));
621
- if (!discount || (discount.tag || discount.type) !== 'good_pass' || ids.has(String(id))) throw (0, _productVoucherGroups.voucherGroupError)();
622
- ids.add(String(id));
623
- }
624
- }
625
- this.ensureExtend(order).productVoucherGroups = (0, _lodashEs.cloneDeep)(groups);
626
- }
627
- validateProductVoucherSelection() {
628
- (0, _productVoucherGroups.validateProductVoucherGroups)(this.ensureTempOrder(), this.getDiscountList(), undefined, true);
629
545
  }
630
546
  createDefaultRulesHooks() {
631
547
  return (0, _utils.createDefaultOrderRulesHooks)(() => this.store.tempOrder?.bookings || [], () => this.store.tempOrder?.holder_relations);
@@ -788,7 +704,7 @@ class OrderModule extends _BaseModule.BaseModule {
788
704
  apply: false
789
705
  });
790
706
  }
791
- async scanCode(code, customerId, options) {
707
+ async scanCode(code, customerId) {
792
708
  const beforeCommit = this.createCartIntentCommitGuard('scan_promotion');
793
709
  if (this.isActiveVirtualSettlementOrder(this.store.tempOrder)) {
794
710
  return {
@@ -800,22 +716,16 @@ class OrderModule extends _BaseModule.BaseModule {
800
716
  unavailableReason: _types2.UnavailableReason.ProductNotApplicable
801
717
  };
802
718
  }
803
- const scanOrderKey = this.getDiscountConfigOrderIdentityKey(this.store.tempOrder);
804
719
  const resultDiscountWithReason = (await this.store.discount?.batchSearch(code, {
805
720
  customerId
806
721
  })) || {
807
722
  discountList: [],
808
723
  unavailableReasonKey: null
809
724
  };
810
- if (scanOrderKey !== this.getDiscountConfigOrderIdentityKey(this.store.tempOrder)) {
811
- throw Object.assign(new Error('The scan session ended.'), {
812
- code: 'SALES_GUARD_REJECTED'
813
- });
814
- }
815
725
  const {
726
+ discountList: resultDiscountList,
816
727
  unavailableReasonKey
817
728
  } = resultDiscountWithReason;
818
- const resultDiscountList = resultDiscountWithReason.discountList.filter(discount => !options?.productVouchersOnly || (discount.tag || discount.type) === 'good_pass');
819
729
  const rulesModule = this.store.rules;
820
730
  if (!rulesModule) {
821
731
  return {
@@ -842,7 +752,7 @@ class OrderModule extends _BaseModule.BaseModule {
842
752
  isScan: true
843
753
  }));
844
754
  const currentSelected = this.getDiscountList().filter(n => n.isSelected);
845
- if (currentSelected.length && (options?.productVouchersOnly ? withScanList.every(scanned => currentSelected.some(selected => selected.id === scanned.id)) : currentSelected.some(n => withScanList.some(m => m.id === n.id)))) {
755
+ if (currentSelected.length && currentSelected.some(n => withScanList.some(m => m.id === n.id))) {
846
756
  beforeCommit();
847
757
  await this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
848
758
  return {
@@ -2359,12 +2269,8 @@ class OrderModule extends _BaseModule.BaseModule {
2359
2269
  ...existed,
2360
2270
  ...(origin !== undefined ? {
2361
2271
  origin
2362
- } : {}),
2363
- ...(rawProduct._productVoucherGroupKey ? {
2364
- productVoucherGroupKey: rawProduct._productVoucherGroupKey
2365
2272
  } : {})
2366
2273
  };
2367
- delete normalizedProduct._productVoucherGroupKey;
2368
2274
  delete normalizedProduct._origin;
2369
2275
  delete normalizedProduct.unique_identification_number;
2370
2276
  }
@@ -3690,7 +3596,6 @@ class OrderModule extends _BaseModule.BaseModule {
3690
3596
  const isIncomingCustomItem = productToAdd.metadata?.origin?.isCustomItem === true || productToAdd._origin?.isCustomItem === true;
3691
3597
  const shouldForceNewLine = disableMerge || !!booking || hasIncomingGoodPass || isIncomingPersistedEntitlementPass || hasIncomingBookingUid || hasIncomingHolder || isIncomingCustomItem || isWeighingProduct;
3692
3598
  const matchedIndex = shouldForceNewLine ? -1 : tempOrder.products.findIndex(item => {
3693
- if ((0, _productVoucherGroups.productVoucherGroupKey)(tempOrder, item) !== productToAdd._productVoucherGroupKey) return false;
3694
3599
  if (this.hasGoodPassDiscount(item)) return false;
3695
3600
  if ((0, _holderRelations.getProductHolderRelations)(tempOrder, item).length > 0 || (0, _utils.hasAssignedHolderId)(item.metadata?.holder_id)) return false;
3696
3601
  const isRuntimeEntitlementPass = this.isRuntimeEntitlementAppend(item, tempOrder);
@@ -3874,37 +3779,16 @@ class OrderModule extends _BaseModule.BaseModule {
3874
3779
  * // → tempOrder.products 新增 3 行,每行 num=1,bookings 3 条
3875
3780
  */
3876
3781
  async addProductToOrder(product, booking, options) {
3877
- return this.queueCartCommand(() => this.addProductToOrderDraft(product, booking, options));
3878
- }
3879
- async addProductToOrderDraft(product, booking, options) {
3880
3782
  const availabilityCommitGuard = options?.availabilityCommitGuard;
3881
3783
  availabilityCommitGuard?.();
3882
3784
  const liveTempOrder = this.ensureTempOrder();
3883
3785
  const beforeCommit = this.createCartIntentCommitGuard('add_product', liveTempOrder);
3884
- const mutation = this.beginCartMutation();
3885
- // 库存/商品券校验与自动预约共用草稿,全部门禁通过后才发布完整批次。
3886
- const tempOrder = availabilityCommitGuard && !mutation.commit ? (0, _lodashEs.cloneDeep)(liveTempOrder) : mutation.draft;
3887
- const beforeAppend = mutation.commit ? undefined : beforeCommit;
3786
+ // 自动预约在草稿上准备完整批次,避免拆票期间暴露半成品,或在失败时
3787
+ // 用整单快照回滚而抹掉其他入口的并发修改。人工路径保持原有写入行为。
3788
+ const tempOrder = availabilityCommitGuard ? (0, _lodashEs.cloneDeep)(liveTempOrder) : liveTempOrder;
3888
3789
  const guardedMutationFields = ['products', 'bookings', 'notes', '_extend', 'metadata', 'currency_code', 'currency_symbol', 'currency_format'];
3889
3790
  const readGuardedMutationFields = order => Object.fromEntries(guardedMutationFields.map(key => [key, order[key]]));
3890
3791
  const guardedMutationBaseline = availabilityCommitGuard ? (0, _lodashEs.cloneDeep)(readGuardedMutationFields(liveTempOrder)) : null;
3891
- const beforePublish = () => {
3892
- availabilityCommitGuard?.();
3893
- beforeCommit();
3894
- // 调用方的结构 revision 可能不包括备注、价格或结算元数据。
3895
- if (availabilityCommitGuard && !(0, _lodashEs.isEqual)(readGuardedMutationFields(liveTempOrder), guardedMutationBaseline)) {
3896
- throw Object.assign(new Error('预约加购期间订单已变化,请重新选择'), {
3897
- code: 'AVAILABILITY_SELECTION_STALE'
3898
- });
3899
- }
3900
- };
3901
- if (options?.productVoucherGroupKey) {
3902
- if (!tempOrder._extend?.productVoucherGroups?.some(group => group.key === options.productVoucherGroupKey)) throw (0, _productVoucherGroups.voucherGroupError)();
3903
- product = {
3904
- ...product,
3905
- _productVoucherGroupKey: options.productVoucherGroupKey
3906
- };
3907
- }
3908
3792
  const salesNoteDrafts = (options?.salesNotes || []).map(draft => ({
3909
3793
  note_type: String(draft.note_type || '').trim(),
3910
3794
  text: {
@@ -3978,7 +3862,7 @@ class OrderModule extends _BaseModule.BaseModule {
3978
3862
  const committedProduct = await this.appendProductLineToTempOrder(tempOrder, splitLine.product, splitLine.booking, {
3979
3863
  insertAtIndex,
3980
3864
  disableMerge: options?.disableMerge,
3981
- beforeCommit: beforeAppend
3865
+ beforeCommit
3982
3866
  });
3983
3867
  availabilityCommitGuard?.();
3984
3868
  attachSalesNoteDrafts(committedProduct);
@@ -3988,7 +3872,7 @@ class OrderModule extends _BaseModule.BaseModule {
3988
3872
  const committedProduct = await this.appendProductLineToTempOrder(tempOrder, product, (0, _lodashEs.cloneDeep)(booking), {
3989
3873
  insertAtIndex,
3990
3874
  disableMerge: options?.disableMerge,
3991
- beforeCommit: beforeAppend
3875
+ beforeCommit
3992
3876
  });
3993
3877
  availabilityCommitGuard?.();
3994
3878
  attachSalesNoteDrafts(committedProduct);
@@ -3997,17 +3881,21 @@ class OrderModule extends _BaseModule.BaseModule {
3997
3881
  const committedProduct = await this.appendProductLineToTempOrder(tempOrder, product, undefined, {
3998
3882
  insertAtIndex,
3999
3883
  disableMerge: options?.disableMerge,
4000
- beforeCommit: beforeAppend
3884
+ beforeCommit
4001
3885
  });
4002
3886
  availabilityCommitGuard?.();
4003
3887
  attachSalesNoteDrafts(committedProduct);
4004
3888
  }
4005
- if (mutation.commit) {
4006
- await mutation.commit({
4007
- beforeCommit: beforePublish
4008
- });
4009
- } else if (availabilityCommitGuard) {
4010
- beforePublish();
3889
+ if (availabilityCommitGuard) {
3890
+ availabilityCommitGuard();
3891
+ beforeCommit();
3892
+ // 调用方的结构 revision 可能不包括备注、价格或结算元数据。
3893
+ // 本次会覆盖的字段也要保持原值,不能让草稿覆盖并发编辑。
3894
+ if (!(0, _lodashEs.isEqual)(readGuardedMutationFields(liveTempOrder), guardedMutationBaseline)) {
3895
+ throw Object.assign(new Error('预约加购期间订单已变化,请重新选择'), {
3896
+ code: 'AVAILABILITY_SELECTION_STALE'
3897
+ });
3898
+ }
4011
3899
  // 从最后一次门禁到真正新增之间不再 await。只发布本次新增会改写的
4012
3900
  // 字段;其余订单字段继续使用 live 对象,外部持有的订单引用也不变。
4013
3901
  Object.assign(liveTempOrder, readGuardedMutationFields(tempOrder));
@@ -4055,14 +3943,9 @@ class OrderModule extends _BaseModule.BaseModule {
4055
3943
  * ]);
4056
3944
  */
4057
3945
  async addProductsToOrder(items, options) {
4058
- return this.queueCartCommand(() => this.addProductsToOrderDraft(items, options));
4059
- }
4060
- async addProductsToOrderDraft(items, options) {
4061
- const mutation = this.beginCartMutation();
4062
- let tempOrder = mutation.draft;
3946
+ const tempOrder = this.ensureTempOrder();
4063
3947
  if (!Array.isArray(items) || items.length === 0) return tempOrder.products;
4064
- const beforeCommit = this.createCartIntentCommitGuard('add_product');
4065
- const beforeAppend = mutation.commit ? undefined : beforeCommit;
3948
+ const beforeCommit = this.createCartIntentCommitGuard('add_product', tempOrder);
4066
3949
  for (const item of items || []) {
4067
3950
  const {
4068
3951
  product,
@@ -4076,7 +3959,7 @@ class OrderModule extends _BaseModule.BaseModule {
4076
3959
  for (let i = 0; i < splitCount; i += 1) {
4077
3960
  const splitLine = this.createSplitBookingLine(productRecord, booking, i, splitCount);
4078
3961
  const appendResult = this.appendProductLineToTempOrder(tempOrder, splitLine.product, splitLine.booking, {
4079
- beforeCommit: beforeAppend
3962
+ beforeCommit
4080
3963
  });
4081
3964
  if (appendResult) await appendResult;
4082
3965
  }
@@ -4084,13 +3967,10 @@ class OrderModule extends _BaseModule.BaseModule {
4084
3967
  }
4085
3968
  }
4086
3969
  const appendResult = this.appendProductLineToTempOrder(tempOrder, product, booking, {
4087
- beforeCommit: beforeAppend
3970
+ beforeCommit
4088
3971
  });
4089
3972
  if (appendResult) await appendResult;
4090
3973
  }
4091
- if (mutation.commit) tempOrder = await mutation.commit({
4092
- beforeCommit
4093
- });
4094
3974
  await this.finalizeProductOrderMutation(tempOrder, options);
4095
3975
  this.logInfo('addProductsToOrder success', {
4096
3976
  itemsCount: items.length
@@ -4434,18 +4314,12 @@ class OrderModule extends _BaseModule.BaseModule {
4434
4314
  return tempOrder.products[productIndex].metadata?.unique_identification_number;
4435
4315
  }
4436
4316
  async updateOrderProduct(params) {
4437
- return this.queueCartCommand(() => this.updateOrderProductDraft(params));
4438
- }
4439
- async updateOrderProductDraft(params) {
4440
- const mutation = this.beginCartMutation();
4441
- let tempOrder = mutation.draft;
4442
- const beforeCommit = this.isRestrictedCartProductUpdate(tempOrder, params) ? this.createCartIntentCommitGuard('update_product') : undefined;
4443
- if (!mutation.commit) beforeCommit?.();
4317
+ const tempOrder = this.ensureTempOrder();
4318
+ if (this.isRestrictedCartProductUpdate(tempOrder, params)) {
4319
+ this.createCartIntentCommitGuard('update_product', tempOrder)();
4320
+ }
4444
4321
  const reapplyWeighedDiscountProductUids = [];
4445
4322
  const updatedProductUid = this.applyOrderProductUpdateToTempOrder(tempOrder, params, reapplyWeighedDiscountProductUids);
4446
- if (mutation.commit) tempOrder = await mutation.commit({
4447
- beforeCommit
4448
- });
4449
4323
  const promotionPayload = await this.evaluatePromotion();
4450
4324
  this.applyDiscount({
4451
4325
  reapplyWeighedDiscountProductUids,
@@ -4463,16 +4337,13 @@ class OrderModule extends _BaseModule.BaseModule {
4463
4337
  return tempOrder.products;
4464
4338
  }
4465
4339
  async updateOrderProducts(paramsList) {
4466
- return this.queueCartCommand(() => this.updateOrderProductsDraft(paramsList));
4467
- }
4468
- async updateOrderProductsDraft(paramsList) {
4469
- const mutation = this.beginCartMutation();
4470
- let tempOrder = mutation.draft;
4340
+ const tempOrder = this.ensureTempOrder();
4471
4341
  if (!paramsList.length) {
4472
4342
  return tempOrder.products;
4473
4343
  }
4474
- const beforeCommit = paramsList.some(params => this.isRestrictedCartProductUpdate(tempOrder, params)) ? this.createCartIntentCommitGuard('update_product') : undefined;
4475
- if (!mutation.commit) beforeCommit?.();
4344
+ if (paramsList.some(params => this.isRestrictedCartProductUpdate(tempOrder, params))) {
4345
+ this.createCartIntentCommitGuard('update_product', tempOrder)();
4346
+ }
4476
4347
  const reapplyWeighedDiscountProductUids = [];
4477
4348
  const reapplyBookingDiscountProductUids = paramsList.reduce((acc, params) => {
4478
4349
  const updatedProductUid = this.applyOrderProductUpdateToTempOrder(tempOrder, params, reapplyWeighedDiscountProductUids);
@@ -4482,9 +4353,6 @@ class OrderModule extends _BaseModule.BaseModule {
4482
4353
  }
4483
4354
  return acc;
4484
4355
  }, []);
4485
- if (mutation.commit) tempOrder = await mutation.commit({
4486
- beforeCommit
4487
- });
4488
4356
  await this.finalizeAfterProductsMutation(tempOrder, {
4489
4357
  reapplyWeighedDiscountProductUids,
4490
4358
  reapplyBookingDiscountProductUids: reapplyBookingDiscountProductUids.length ? reapplyBookingDiscountProductUids : undefined
@@ -4495,9 +4363,6 @@ class OrderModule extends _BaseModule.BaseModule {
4495
4363
  return tempOrder.products;
4496
4364
  }
4497
4365
  async updateOrderProductQuantity(params, options) {
4498
- return this.queueCartCommand(() => this.updateOrderProductQuantityDraft(params, options));
4499
- }
4500
- async updateOrderProductQuantityDraft(params, options) {
4501
4366
  const isCurrentOrder = options?.isCurrentOrder;
4502
4367
  if (isCurrentOrder && !isCurrentOrder()) return this.store.tempOrder?.products || [];
4503
4368
  const {
@@ -4509,8 +4374,7 @@ class OrderModule extends _BaseModule.BaseModule {
4509
4374
  product_sku,
4510
4375
  product_bundle
4511
4376
  } = params;
4512
- const mutation = this.beginCartMutation();
4513
- let tempOrder = mutation.draft;
4377
+ const tempOrder = this.ensureTempOrder();
4514
4378
  this.repairDuplicateProductLineIdentities(tempOrder);
4515
4379
  const identityLookup = {
4516
4380
  product_id,
@@ -4566,16 +4430,11 @@ class OrderModule extends _BaseModule.BaseModule {
4566
4430
  throw new _virtualSettlement.VirtualCurrencyBalanceError(balance.toFixed(2), requiredAmount.toFixed(2));
4567
4431
  }
4568
4432
  }
4569
- const beforeCommit = normalizedProduct.num > targetProduct.num ? this.createCartIntentCommitGuard('increase_quantity') : undefined;
4570
- if (!mutation.commit) beforeCommit?.();
4433
+ if (normalizedProduct.num > targetProduct.num) {
4434
+ this.createCartIntentCommitGuard('increase_quantity', tempOrder)();
4435
+ }
4571
4436
  if (isCurrentOrder && !isCurrentOrder()) return tempOrder.products;
4572
4437
  tempOrder.products[productIndex] = normalizedProduct;
4573
- if (mutation.commit) {
4574
- tempOrder = await mutation.commit({
4575
- beforeCommit,
4576
- isCurrentOrder
4577
- });
4578
- }
4579
4438
  if (isCurrentOrder) {
4580
4439
  await this.finalizeProductOrderMutation(tempOrder, {
4581
4440
  skipEditDiscountConfigRefresh: true,
@@ -4659,13 +4518,9 @@ class OrderModule extends _BaseModule.BaseModule {
4659
4518
  * await order.removeProductsFromOrder([identityA, identityB]);
4660
4519
  */
4661
4520
  async removeProductsFromOrder(identities, options) {
4662
- return this.queueCartCommand(() => this.removeProductsFromOrderDraft(identities, options));
4663
- }
4664
- async removeProductsFromOrderDraft(identities, options) {
4665
4521
  const isCurrentOrder = options?.isCurrentOrder;
4666
4522
  if (isCurrentOrder && !isCurrentOrder()) return this.store.tempOrder?.products || [];
4667
- const mutation = this.beginCartMutation();
4668
- let tempOrder = mutation.draft;
4523
+ const tempOrder = this.ensureTempOrder();
4669
4524
  if (!identities.length) {
4670
4525
  return tempOrder.products;
4671
4526
  }
@@ -4733,9 +4588,6 @@ class OrderModule extends _BaseModule.BaseModule {
4733
4588
  }
4734
4589
  (0, _holderRelations.removeProductHolderRelations)(tempOrder, productsBeforeRemove.filter(product => !tempOrder.products.includes(product)));
4735
4590
  this.removeSalesNotesForMissingProductLines(tempOrder);
4736
- if (mutation.commit) tempOrder = await mutation.commit({
4737
- isCurrentOrder
4738
- });
4739
4591
  if (isCurrentOrder) {
4740
4592
  await this.finalizeProductOrderMutation(tempOrder, {
4741
4593
  skipEditDiscountConfigRefresh: true,
@@ -4758,11 +4610,7 @@ class OrderModule extends _BaseModule.BaseModule {
4758
4610
  * 普通整单 note 保持不变;以商品行为主体的 Sales Notes 同步删除。
4759
4611
  */
4760
4612
  async clearOrderCartLines() {
4761
- return this.queueCartCommand(() => this.clearOrderCartLinesDraft());
4762
- }
4763
- async clearOrderCartLinesDraft() {
4764
- const mutation = this.beginCartMutation();
4765
- let tempOrder = mutation.draft;
4613
+ const tempOrder = this.ensureTempOrder();
4766
4614
  this.ensureSalesNotesLoadedForMutation(tempOrder);
4767
4615
  (0, _holderRelations.removeProductHolderRelations)(tempOrder, tempOrder.products);
4768
4616
  tempOrder.products = [];
@@ -4776,7 +4624,6 @@ class OrderModule extends _BaseModule.BaseModule {
4776
4624
  productsByUid: {}
4777
4625
  };
4778
4626
  }
4779
- if (mutation.commit) tempOrder = await mutation.commit();
4780
4627
  const promotionPayload = await this.evaluatePromotion();
4781
4628
  this.applyDiscount();
4782
4629
  this.sanitizeTempOrderProducts(tempOrder);
@@ -4915,7 +4762,6 @@ class OrderModule extends _BaseModule.BaseModule {
4915
4762
  async runSubmitTempOrder(params) {
4916
4763
  const tempOrder = this.ensureTempOrder();
4917
4764
  if ((0, _localEftposState.requiresLocalPaymentRefresh)(tempOrder)) throw new Error(_localEftposState.PAYMENT_REFRESH_MESSAGE);
4918
- (0, _productVoucherGroups.validateProductVoucherGroups)(tempOrder, this.getDiscountList(), undefined, true);
4919
4765
  this.prepareVirtualSettlementTempOrder(tempOrder);
4920
4766
  const isOnlineStorePlatform = this.isOnlineStorePlatform();
4921
4767
  const shouldConfirmPendingVoucherPayments = params?.confirmPendingVoucherPayments !== false;
@@ -457,8 +457,6 @@ export type AddProductBookingInput = Record<string, any>;
457
457
  * 避免步进器修改数量改变该组展示位置。
458
458
  */
459
459
  export interface AddProductToOrderOptions {
460
- /** Associates a selection with an existing runtime voucher group. */
461
- productVoucherGroupKey?: string;
462
460
  insertAfterProductUid?: string;
463
461
  /** 新增商品行插入 products 首位,优先于 insertAfterProductUid。 */
464
462
  insertAtStart?: boolean;
@@ -559,11 +557,6 @@ export interface OrderHooksConfig {
559
557
  beforeCartIntentCommit?: (context: OrderCartIntentCommitContext) => void;
560
558
  /** Captures tenant/business runtime identity for asynchronous cart intents. */
561
559
  getCartIntentScope?: () => unknown;
562
- /** Awaited before a local cart draft is published. Reject to leave the live order unchanged. */
563
- onBeforeCartCommit?: (context: {
564
- currentItems: readonly OrderProduct[];
565
- proposedItems: readonly OrderProduct[];
566
- }) => void | Promise<void>;
567
560
  onBeforeMergeProductToOrder?: (context: OrderProductMergeDecisionContext) => OrderProductMergeDecisionResult | Promise<OrderProductMergeDecisionResult>;
568
561
  }
569
562
  /**
@@ -241,7 +241,7 @@ function consolidateDiscountFreeProductLines(tempOrder) {
241
241
  bundle_selling_price: String(bundle?.bundle_selling_price ?? '')
242
242
  }))
243
243
  });
244
- const mergeKey = [discountSplitOriginUid, productUid ? tempOrder._extend?.productsByUid?.[productUid]?.productVoucherGroupKey ?? '' : '', product.product_id, product.product_variant_id ?? 0, fingerprint, priceSignature].join('#');
244
+ const mergeKey = [discountSplitOriginUid, product.product_id, product.product_variant_id ?? 0, fingerprint, priceSignature].join('#');
245
245
  const matchedIndex = productIndexByKey.get(mergeKey);
246
246
 
247
247
  // 当前拆分来源 + 商品结构组合第一次出现时,保留该行作为回并目标。
@@ -66,13 +66,7 @@ class ProductList extends _BaseModule.BaseModule {
66
66
  * productList.updateOtherParams({ channel: 'pos' });
67
67
  */
68
68
  updateOtherParams(params) {
69
- const previousScope = this.otherParams.catalogScopeKey;
70
69
  this.otherParams = params || {};
71
- if (previousScope !== this.otherParams.catalogScopeKey && (previousScope || this.otherParams.catalogScopeKey)) {
72
- this.store.list = [];
73
- this.rawProductPriceSources.clear();
74
- this.core.effects.emit(`${this.name}:changed`, this.store.list);
75
- }
76
70
  }
77
71
  async storeChange(path, value) {
78
72
  // No longer needed - products are stored as plain objects instead of Product instances
@@ -107,12 +101,6 @@ class ProductList extends _BaseModule.BaseModule {
107
101
  status = 'published',
108
102
  strategy_context
109
103
  } = {}, options) {
110
- const scope = this.otherParams.catalogScopeKey;
111
- const assertScope = () => {
112
- if (scope !== this.otherParams.catalogScopeKey) throw Object.assign(new Error('Product catalog context changed'), {
113
- name: 'AbortError'
114
- });
115
- };
116
104
  // // 如果 schedule_ids 为空,则需要尝试从 schedule 模块里获取
117
105
  // if (!schedule_ids?.length) {
118
106
  // const schedule_ids_data = this.store.schedule
@@ -192,7 +180,6 @@ class ProductList extends _BaseModule.BaseModule {
192
180
  const handledByOsServer = (0, _clientDataVariants.isProductQueryHandledByOsServer)(this.core, this.request);
193
181
  const originalCallback = options?.callback;
194
182
  const subscriptionCallback = typeof originalCallback === 'function' ? async result => {
195
- if (scope !== this.otherParams.catalogScopeKey) return;
196
183
  const callbackList = result?.data?.list;
197
184
  if (!Array.isArray(callbackList)) {
198
185
  originalCallback(result);
@@ -210,7 +197,6 @@ class ProductList extends _BaseModule.BaseModule {
210
197
  queryPayload,
211
198
  handledByOsServer
212
199
  });
213
- assertScope();
214
200
  await this.addProduct(products);
215
201
  originalCallback(handledByOsServer ? result : {
216
202
  ...result,
@@ -226,7 +212,6 @@ class ProductList extends _BaseModule.BaseModule {
226
212
  subscriberId: options?.subscriberId,
227
213
  customToast: () => {}
228
214
  });
229
- assertScope();
230
215
  if (!handledByOsServer && Array.isArray(productsData.data.list)) {
231
216
  this.replaceRawProductQueryResult(productsData.data.list, product_ids);
232
217
  }
@@ -9,8 +9,6 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
9
9
  private store;
10
10
  window: WindowPlugin;
11
11
  private hooks;
12
- private discountScope?;
13
- setDiscountScope(scope: (product: any, discount: Discount) => boolean): void;
14
12
  constructor(name?: string, version?: string);
15
13
  initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
16
14
  setRulesList(rulesList: Rules[]): Promise<void>;
@@ -22,10 +22,6 @@ class RulesModule extends _BaseModule.BaseModule {
22
22
  store;
23
23
  window; // WindowPlugin 实例
24
24
  hooks;
25
- discountScope;
26
- setDiscountScope(scope) {
27
- this.discountScope = scope;
28
- }
29
25
  constructor(name, version) {
30
26
  super(name, version);
31
27
  this.hooks = {};
@@ -749,7 +745,6 @@ class RulesModule extends _BaseModule.BaseModule {
749
745
 
750
746
  // 辅助函数:检查商品是否对某个折扣卡可用
751
747
  const checkItemApplicableForDiscount = (flatItem, discount) => {
752
- if (this.discountScope && !this.discountScope(flatItem.originProduct, discount)) return false;
753
748
  if (discount.config?.isAvailable === false) return false;
754
749
  if (isCardBlockedByPromotion(flatItem, discount)) return false;
755
750
  let product;
@@ -1161,7 +1156,6 @@ class RulesModule extends _BaseModule.BaseModule {
1161
1156
 
1162
1157
  // 找到适用于此商品的所有优惠券,仅考虑isSelected不为false的优惠券
1163
1158
  const applicableDiscounts = sortedDiscountList.filter(discount => {
1164
- if (this.discountScope && !this.discountScope(originProduct, discount)) return false;
1165
1159
  if (this.isItemRewardProductDiscount(product)) return false;
1166
1160
  if (isCardBlockedByPromotion(flatItem, discount)) return false;
1167
1161
  // 🔥 检查策略可用性(针对全额抵扣卡和折扣卡)
@@ -1,4 +1,3 @@
1
- import { InventoryController, type CheckoutRuntimeSnapshot } from '../../inventory';
2
1
  import { Module, ModuleOptions, PisellCore } from '../../types';
3
2
  import { BaseModule } from '../../modules/BaseModule';
4
3
  import { type LocalEftposFinalization } from '../../modules/Order/localEftposState';
@@ -53,8 +52,6 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
53
52
  protected appPlugin: AppPlugin;
54
53
  protected store: BaseSalesState;
55
54
  protected otherParams: Record<string, any>;
56
- getInventory(): InventoryController | undefined;
57
- prepareCheckout(signal?: AbortSignal): Promise<CheckoutRuntimeSnapshot | undefined>;
58
55
  protected cacheId: string | undefined;
59
56
  /**
60
57
  * 由已在初始化阶段解析过设备短号的业务解决方案写入。
@@ -197,7 +194,6 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
197
194
  * 可覆盖此方法并把未识别的 name 委托给 `super.createSubModule(name)`。
198
195
  */
199
196
  protected createSubModule(moduleName: string): Module | null;
200
- private inventoryOrderHooks?;
201
197
  protected getSubModuleHooks(moduleName: string): any;
202
198
  /**
203
199
  * 构造传给 BaseSales 子模块的完整运行态参数,保证初始化和后续同步语义一致。
@@ -235,11 +231,7 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
235
231
  private isActiveVirtualSettlementOrder;
236
232
  private isHistoricalVirtualSettlementOrder;
237
233
  private syncAppDataToTempOrder;
238
- private initialization?;
239
- /** Hosts can await readiness without changing Core's synchronous registration API. */
240
- whenInitialized(): Promise<void>;
241
234
  initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
242
- private initializeSalesRuntime;
243
235
  destroy(): Promise<void>;
244
236
  /**
245
237
  * 加载销售订单到统一 tempOrder 工作区。
@@ -348,9 +340,7 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
348
340
  discountList: Discount[];
349
341
  originalDiscountList?: Discount[];
350
342
  }): Promise<void>;
351
- scanPromotionCode(code: string, customerId?: number, options?: {
352
- productVouchersOnly?: boolean;
353
- }): Promise<BaseSalesScanCodeResult>;
343
+ scanPromotionCode(code: string, customerId?: number): Promise<BaseSalesScanCodeResult>;
354
344
  setDiscountSelected(params: {
355
345
  discountId: number;
356
346
  isSelected: boolean;
@@ -535,11 +525,6 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
535
525
  private hasSmartPricingStrategies;
536
526
  shouldRecalculateProductBookingPricesForContextChange(params: BaseSalesPriceRecalculationContextChange): boolean;
537
527
  calculateProductBookingPrices(paramsList: BaseSalesCalculateProductBookingPriceParams[]): Promise<BaseSalesProductBookingPriceResult[]>;
538
- setProductVoucherGroups(groups: Array<{
539
- key: string;
540
- discountIds: Array<number | string>;
541
- }>): void;
542
- validateProductVoucherSelection(): void;
543
528
  addProductToOrder(product: Partial<BaseSalesOrderProduct> & BaseSalesOrderProductIdentity, booking?: AddProductBookingInput, options?: AddProductToOrderOptions): Promise<import("../../modules/Order/types").OrderProduct[]>;
544
529
  updateOrderProduct(params: UpdateOrderProductParams): Promise<import("../../modules/Order/types").OrderProduct[]>;
545
530
  updateOrderProducts(paramsList: UpdateOrderProductParams[]): Promise<import("../../modules/Order/types").OrderProduct[]>;