@pisell/pisellos 2.2.267 → 2.2.268

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.
@@ -3,7 +3,7 @@ import { BaseModule } from '../BaseModule';
3
3
  import { OrderModuleAPI, CommitOrderParams, UpdateOrderBookingParams, UpdateOrderProductParams, UpdateOrderProductQuantityParams, CheckoutOrderParams, CancelOrderParams, ChangeBookingStatusParams } from './types';
4
4
  import { CartItem } from '../Cart/types';
5
5
  import { type SubmitPayloadEnhancer } from './utils';
6
- import type { OrderAmountSnapshot, AddProductBookingInput, OrderIdentitySnapshot, OrderPaymentSource, OrderSnapshot, OrderSyncState, SyncPaymentsToOrderParams, SyncPaymentsToOrderResult, SubmitSalesOrderParams, OrderProduct, OrderProductIdentity, OrderSummary, OrderTempOrder, OrderPaymentData, SendCustomerPayLinkParams, UpdateTempOrderCustomerInput, OrderCustomerPatch, OrderCustomerView, ReplaceTempOrderOptions, OrderPromotionEvaluator, OrderGiftSelectResolver, OrderUnfulfilledPromotion, OrderLastGiftActions } from './types';
6
+ import type { OrderAmountSnapshot, AddProductBookingInput, AddProductToOrderOptions, OrderIdentitySnapshot, OrderPaymentSource, OrderSnapshot, OrderSyncState, SyncPaymentsToOrderParams, SyncPaymentsToOrderResult, SubmitSalesOrderParams, OrderProduct, OrderProductIdentity, OrderSummary, OrderTempOrder, OrderPaymentData, SendCustomerPayLinkParams, UpdateTempOrderCustomerInput, OrderCustomerPatch, OrderCustomerView, ReplaceTempOrderOptions, OrderPromotionEvaluator, OrderGiftSelectResolver, OrderUnfulfilledPromotion, OrderLastGiftActions, RemoveProductsFromOrderOptions } from './types';
7
7
  import type { ICustomer } from '../AccountList/types';
8
8
  import type { Discount } from '../Discount/types';
9
9
  import { UnavailableReason } from '../Rules/types';
@@ -374,7 +374,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
374
374
  * await order.addProductToOrder({ product_id: 1, num: 3 }, { start_time: '10:00' });
375
375
  * // → tempOrder.products 新增 3 行,每行 num=1,bookings 3 条
376
376
  */
377
- addProductToOrder(product: Partial<OrderProduct> & OrderProductIdentity, booking?: AddProductBookingInput): Promise<OrderProduct[]>;
377
+ addProductToOrder(product: Partial<OrderProduct> & OrderProductIdentity, booking?: AddProductBookingInput, options?: AddProductToOrderOptions): Promise<OrderProduct[]>;
378
378
  /**
379
379
  * 批量添加商品行,所有行追加完成后只触发一次促销、折扣、summary 重算与持久化。
380
380
  *
@@ -412,8 +412,8 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
412
412
  * @example
413
413
  * await order.removeProductsFromOrder([identityA, identityB]);
414
414
  */
415
- removeProductsFromOrder(identities: OrderProductIdentity[]): Promise<OrderProduct[]>;
416
- removeProductFromOrder(identity: OrderProductIdentity): Promise<OrderProduct[]>;
415
+ removeProductsFromOrder(identities: OrderProductIdentity[], options?: RemoveProductsFromOrderOptions): Promise<OrderProduct[]>;
416
+ removeProductFromOrder(identity: OrderProductIdentity, options?: RemoveProductsFromOrderOptions): Promise<OrderProduct[]>;
417
417
  /**
418
418
  * 仅清空购物车行(products / bookings),不重置整单。
419
419
  * 用于「仅清空商品」;客户、备注、支付等协议字段保持不变。
@@ -468,7 +468,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
468
468
  generateIdempotencyToken(): string;
469
469
  syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
470
470
  createOrder(params: CommitOrderParams['query']): {
471
- type: "virtual" | "appointment_booking";
471
+ type: "appointment_booking" | "virtual";
472
472
  platform: string;
473
473
  sales_channel: string;
474
474
  order_sales_channel: string;
@@ -541,4 +541,4 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
541
541
  getOrderInfo(order_id: number): Promise<any>;
542
542
  getVouchers(): any[];
543
543
  }
544
- export type { UpdateOrderBookingParams, UpdateOrderProductParams, UpdateOrderProductQuantityParams, } from './types';
544
+ export type { AddProductToOrderOptions, RemoveProductsFromOrderOptions, UpdateOrderBookingParams, UpdateOrderProductParams, UpdateOrderProductQuantityParams, } from './types';
@@ -3676,13 +3676,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3676
3676
  }, {
3677
3677
  key: "appendProductLineToTempOrder",
3678
3678
  value: (function () {
3679
- var _appendProductLineToTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(tempOrder, product, booking) {
3679
+ var _appendProductLineToTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(tempOrder, product, booking, options) {
3680
3680
  var _normalizedIncoming$p,
3681
3681
  _normalizedIncoming$p2,
3682
3682
  _booking_uid,
3683
3683
  _metadata,
3684
3684
  _this23 = this;
3685
- var linked, productToAdd, incomingFingerprint, normalizedIncoming, isWeighingProduct, netWeight, incomingBookingUid, hasIncomingGoodPass, hasIncomingProductNote, hasIncomingBookingUid, shouldForceNewLine, matchedIndex, matchedProduct, existedFingerprint, shouldMerge, _targetProduct$metada, targetProduct, targetUid, normalizedProduct, nextNum, targetIsManualProductDiscount, nextDiscountList;
3685
+ var linked, productToAdd, incomingFingerprint, normalizedIncoming, isWeighingProduct, netWeight, incomingBookingUid, hasIncomingGoodPass, hasIncomingProductNote, hasIncomingBookingUid, shouldForceNewLine, matchedIndex, matchedProduct, existedFingerprint, shouldMerge, insertAtIndex, _targetProduct$metada, targetProduct, targetUid, normalizedProduct, nextNum, targetIsManualProductDiscount, nextDiscountList, mergedProduct;
3686
3686
  return _regeneratorRuntime().wrap(function _callee17$(_context19) {
3687
3687
  while (1) switch (_context19.prev = _context19.next) {
3688
3688
  case 0:
@@ -3757,8 +3757,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3757
3757
  booking_uid: linked.bookingUid
3758
3758
  });
3759
3759
  }
3760
- // tempOrder.products.push(normalizedIncoming);
3761
- tempOrder.products = [].concat(_toConsumableArray(tempOrder.products), [normalizedIncoming]);
3760
+ insertAtIndex = options === null || options === void 0 ? void 0 : options.insertAtIndex;
3761
+ if (Number.isInteger(insertAtIndex) && Number(insertAtIndex) >= 0 && Number(insertAtIndex) < tempOrder.products.length) {
3762
+ tempOrder.products = [].concat(_toConsumableArray(tempOrder.products.slice(0, insertAtIndex)), [normalizedIncoming], _toConsumableArray(tempOrder.products.slice(insertAtIndex)));
3763
+ } else {
3764
+ tempOrder.products = [].concat(_toConsumableArray(tempOrder.products), [normalizedIncoming]);
3765
+ }
3762
3766
  } else {
3763
3767
  targetProduct = matchedProduct;
3764
3768
  targetUid = (_targetProduct$metada = targetProduct.metadata) === null || _targetProduct$metada === void 0 ? void 0 : _targetProduct$metada.unique_identification_number;
@@ -3796,6 +3800,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3796
3800
  num: nextNum
3797
3801
  });
3798
3802
  this.captureProductRuntime(tempOrder, productToAdd, tempOrder.products[matchedIndex], targetUid);
3803
+ if (matchedIndex !== tempOrder.products.length - 1) {
3804
+ mergedProduct = tempOrder.products[matchedIndex];
3805
+ tempOrder.products = [].concat(_toConsumableArray(tempOrder.products.slice(0, matchedIndex)), _toConsumableArray(tempOrder.products.slice(matchedIndex + 1)), [mergedProduct]);
3806
+ }
3799
3807
  }
3800
3808
  if (linked) {
3801
3809
  tempOrder.bookings = [].concat(_toConsumableArray(tempOrder.bookings || []), [linked.booking]);
@@ -3806,7 +3814,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3806
3814
  }
3807
3815
  }, _callee17, this);
3808
3816
  }));
3809
- function appendProductLineToTempOrder(_x17, _x18, _x19) {
3817
+ function appendProductLineToTempOrder(_x17, _x18, _x19, _x20) {
3810
3818
  return _appendProductLineToTempOrder.apply(this, arguments);
3811
3819
  }
3812
3820
  return appendProductLineToTempOrder;
@@ -3822,61 +3830,74 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3822
3830
  }, {
3823
3831
  key: "addProductToOrder",
3824
3832
  value: (function () {
3825
- var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(product, booking) {
3826
- var tempOrder, _ref61, _productRecord$num, productRecord, splitCount, i, singleLine;
3833
+ var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(product, booking, options) {
3834
+ var tempOrder, insertAfterProductUid, anchorIndex, insertAtIndex, _ref61, _productRecord$num, productRecord, splitCount, i, singleLine;
3827
3835
  return _regeneratorRuntime().wrap(function _callee18$(_context20) {
3828
3836
  while (1) switch (_context20.prev = _context20.next) {
3829
3837
  case 0:
3830
3838
  tempOrder = this.ensureTempOrder();
3839
+ insertAfterProductUid = options === null || options === void 0 ? void 0 : options.insertAfterProductUid;
3840
+ anchorIndex = booking && insertAfterProductUid ? tempOrder.products.findIndex(function (line) {
3841
+ var _line$metadata;
3842
+ var uid = ((_line$metadata = line.metadata) === null || _line$metadata === void 0 ? void 0 : _line$metadata.unique_identification_number) || line.unique_identification_number;
3843
+ return uid !== undefined && uid !== null && String(uid) === String(insertAfterProductUid);
3844
+ }) : -1;
3845
+ insertAtIndex = anchorIndex >= 0 ? anchorIndex + 1 : undefined;
3831
3846
  if (!booking) {
3832
- _context20.next = 18;
3847
+ _context20.next = 22;
3833
3848
  break;
3834
3849
  }
3835
3850
  productRecord = product;
3836
3851
  splitCount = getSafeProductNum((_ref61 = (_productRecord$num = productRecord.num) !== null && _productRecord$num !== void 0 ? _productRecord$num : productRecord.product_quantity) !== null && _ref61 !== void 0 ? _ref61 : 1);
3837
3852
  if (!(splitCount > 1)) {
3838
- _context20.next = 18;
3853
+ _context20.next = 22;
3839
3854
  break;
3840
3855
  }
3841
3856
  i = 0;
3842
- case 6:
3857
+ case 9:
3843
3858
  if (!(i < splitCount)) {
3844
- _context20.next = 15;
3859
+ _context20.next = 19;
3845
3860
  break;
3846
3861
  }
3847
3862
  singleLine = cloneDeep(productRecord);
3848
3863
  singleLine.num = 1;
3849
3864
  delete singleLine.product_quantity;
3850
- _context20.next = 12;
3851
- return this.appendProductLineToTempOrder(tempOrder, singleLine, cloneDeep(booking));
3852
- case 12:
3865
+ _context20.next = 15;
3866
+ return this.appendProductLineToTempOrder(tempOrder, singleLine, cloneDeep(booking), {
3867
+ insertAtIndex: insertAtIndex
3868
+ });
3869
+ case 15:
3870
+ if (insertAtIndex !== undefined) insertAtIndex += 1;
3871
+ case 16:
3853
3872
  i += 1;
3854
- _context20.next = 6;
3873
+ _context20.next = 9;
3855
3874
  break;
3856
- case 15:
3857
- _context20.next = 17;
3875
+ case 19:
3876
+ _context20.next = 21;
3858
3877
  return this.finalizeProductOrderMutation(tempOrder);
3859
- case 17:
3878
+ case 21:
3860
3879
  return _context20.abrupt("return", tempOrder.products);
3861
- case 18:
3862
- _context20.next = 20;
3863
- return this.appendProductLineToTempOrder(tempOrder, product, booking);
3864
- case 20:
3865
- _context20.next = 22;
3866
- return this.finalizeProductOrderMutation(tempOrder);
3867
3880
  case 22:
3881
+ _context20.next = 24;
3882
+ return this.appendProductLineToTempOrder(tempOrder, product, booking, {
3883
+ insertAtIndex: insertAtIndex
3884
+ });
3885
+ case 24:
3886
+ _context20.next = 26;
3887
+ return this.finalizeProductOrderMutation(tempOrder);
3888
+ case 26:
3868
3889
  this.logInfo('addProductToOrder success', {
3869
3890
  product_id: product.product_id,
3870
3891
  with_booking: !!booking
3871
3892
  });
3872
3893
  return _context20.abrupt("return", tempOrder.products);
3873
- case 24:
3894
+ case 28:
3874
3895
  case "end":
3875
3896
  return _context20.stop();
3876
3897
  }
3877
3898
  }, _callee18, this);
3878
3899
  }));
3879
- function addProductToOrder(_x20, _x21) {
3900
+ function addProductToOrder(_x21, _x22, _x23) {
3880
3901
  return _addProductToOrder.apply(this, arguments);
3881
3902
  }
3882
3903
  return addProductToOrder;
@@ -3980,7 +4001,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3980
4001
  }
3981
4002
  }, _callee19, this, [[4, 32, 35, 38]]);
3982
4003
  }));
3983
- function addProductsToOrder(_x22, _x23) {
4004
+ function addProductsToOrder(_x24, _x25) {
3984
4005
  return _addProductsToOrder.apply(this, arguments);
3985
4006
  }
3986
4007
  return addProductsToOrder;
@@ -4255,7 +4276,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4255
4276
  }
4256
4277
  }, _callee20, this);
4257
4278
  }));
4258
- function updateOrderProduct(_x24) {
4279
+ function updateOrderProduct(_x26) {
4259
4280
  return _updateOrderProduct.apply(this, arguments);
4260
4281
  }
4261
4282
  return updateOrderProduct;
@@ -4299,7 +4320,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4299
4320
  }
4300
4321
  }, _callee21, this);
4301
4322
  }));
4302
- function updateOrderProducts(_x25) {
4323
+ function updateOrderProducts(_x27) {
4303
4324
  return _updateOrderProducts.apply(this, arguments);
4304
4325
  }
4305
4326
  return updateOrderProducts;
@@ -4375,7 +4396,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4375
4396
  }
4376
4397
  }, _callee22, this);
4377
4398
  }));
4378
- function updateOrderProductQuantity(_x26) {
4399
+ function updateOrderProductQuantity(_x28) {
4379
4400
  return _updateOrderProductQuantity.apply(this, arguments);
4380
4401
  }
4381
4402
  return updateOrderProductQuantity;
@@ -4440,7 +4461,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4440
4461
  }
4441
4462
  }, _callee23, this);
4442
4463
  }));
4443
- function finalizeAfterProductsMutation(_x27, _x28) {
4464
+ function finalizeAfterProductsMutation(_x29, _x30) {
4444
4465
  return _finalizeAfterProductsMutation.apply(this, arguments);
4445
4466
  }
4446
4467
  return finalizeAfterProductsMutation;
@@ -4455,9 +4476,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4455
4476
  }, {
4456
4477
  key: "removeProductsFromOrder",
4457
4478
  value: (function () {
4458
- var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(identities) {
4479
+ var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(identities, options) {
4459
4480
  var _this26 = this;
4460
- var tempOrder, productsBeforeRemove, bookingsBeforeRemove, matchedProducts, removedProducts, _i2, _removedProducts, product, linkedBookingUidsToRemove, _iterator21, _step21, _loop3;
4481
+ var tempOrder, productsBeforeRemove, bookingsBeforeRemove, preserveDisplayPosition, anchorIndex, productsAfterAnchor, matchedProducts, removedProducts, _i2, _removedProducts, product, linkedBookingUidsToRemove, _iterator21, _step21, _loop3, remainingProductIndex, remainingProduct, nextProduct, productsWithoutRemaining, nextProductIndex;
4461
4482
  return _regeneratorRuntime().wrap(function _callee24$(_context27) {
4462
4483
  while (1) switch (_context27.prev = _context27.next) {
4463
4484
  case 0:
@@ -4470,6 +4491,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4470
4491
  case 3:
4471
4492
  productsBeforeRemove = tempOrder.products || [];
4472
4493
  bookingsBeforeRemove = tempOrder.bookings || [];
4494
+ preserveDisplayPosition = options === null || options === void 0 ? void 0 : options.preserveDisplayPosition;
4495
+ anchorIndex = preserveDisplayPosition ? productsBeforeRemove.findIndex(function (item) {
4496
+ var _item$metadata6;
4497
+ var uid = ((_item$metadata6 = item.metadata) === null || _item$metadata6 === void 0 ? void 0 : _item$metadata6.unique_identification_number) || item.unique_identification_number;
4498
+ return uid !== undefined && uid !== null && String(uid) === String(preserveDisplayPosition.anchorProductUid);
4499
+ }) : -1;
4500
+ productsAfterAnchor = anchorIndex >= 0 ? productsBeforeRemove.slice(anchorIndex + 1) : [];
4473
4501
  matchedProducts = productsBeforeRemove.filter(function (item) {
4474
4502
  return identities.some(function (identity) {
4475
4503
  return isIdentityMatch(item, identity);
@@ -4489,7 +4517,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4489
4517
  }
4490
4518
  linkedBookingUidsToRemove = new Set();
4491
4519
  _iterator21 = _createForOfIteratorHelper(matchedProducts);
4492
- _context27.prev = 11;
4520
+ _context27.prev = 14;
4493
4521
  _loop3 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop3() {
4494
4522
  var _metadata11, _metadata12, _metadata13, _metadata14;
4495
4523
  var product, productUid, productBookingUid, isAddTimeProduct;
@@ -4524,56 +4552,72 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4524
4552
  }, _loop3);
4525
4553
  });
4526
4554
  _iterator21.s();
4527
- case 14:
4555
+ case 17:
4528
4556
  if ((_step21 = _iterator21.n()).done) {
4529
- _context27.next = 20;
4557
+ _context27.next = 23;
4530
4558
  break;
4531
4559
  }
4532
- return _context27.delegateYield(_loop3(), "t0", 16);
4533
- case 16:
4560
+ return _context27.delegateYield(_loop3(), "t0", 19);
4561
+ case 19:
4534
4562
  if (!_context27.t0) {
4535
- _context27.next = 18;
4563
+ _context27.next = 21;
4536
4564
  break;
4537
4565
  }
4538
- return _context27.abrupt("continue", 18);
4539
- case 18:
4540
- _context27.next = 14;
4566
+ return _context27.abrupt("continue", 21);
4567
+ case 21:
4568
+ _context27.next = 17;
4541
4569
  break;
4542
- case 20:
4543
- _context27.next = 25;
4570
+ case 23:
4571
+ _context27.next = 28;
4544
4572
  break;
4545
- case 22:
4546
- _context27.prev = 22;
4547
- _context27.t1 = _context27["catch"](11);
4548
- _iterator21.e(_context27.t1);
4549
4573
  case 25:
4550
4574
  _context27.prev = 25;
4551
- _iterator21.f();
4552
- return _context27.finish(25);
4575
+ _context27.t1 = _context27["catch"](14);
4576
+ _iterator21.e(_context27.t1);
4553
4577
  case 28:
4578
+ _context27.prev = 28;
4579
+ _iterator21.f();
4580
+ return _context27.finish(28);
4581
+ case 31:
4554
4582
  if (linkedBookingUidsToRemove.size > 0) {
4555
4583
  // 删除主预约商品时,同步移除挂在同一 booking_uid 下的加时商品,避免残留孤儿行。
4556
4584
  tempOrder.products = (tempOrder.products || []).filter(function (line) {
4557
- var _line$metadata, _line$metadata2, _line$metadata3;
4558
- var lineBookingUid = (line === null || line === void 0 || (_line$metadata = line.metadata) === null || _line$metadata === void 0 ? void 0 : _line$metadata.booking_uid) || (line === null || line === void 0 ? void 0 : line.booking_uid);
4559
- var isAddTimeProduct = (line === null || line === void 0 || (_line$metadata2 = line.metadata) === null || _line$metadata2 === void 0 ? void 0 : _line$metadata2.product_add_schedule_time) !== undefined && (line === null || line === void 0 || (_line$metadata3 = line.metadata) === null || _line$metadata3 === void 0 ? void 0 : _line$metadata3.product_add_schedule_time) !== null;
4585
+ var _line$metadata2, _line$metadata3, _line$metadata4;
4586
+ var lineBookingUid = (line === null || line === void 0 || (_line$metadata2 = line.metadata) === null || _line$metadata2 === void 0 ? void 0 : _line$metadata2.booking_uid) || (line === null || line === void 0 ? void 0 : line.booking_uid);
4587
+ var isAddTimeProduct = (line === null || line === void 0 || (_line$metadata3 = line.metadata) === null || _line$metadata3 === void 0 ? void 0 : _line$metadata3.product_add_schedule_time) !== undefined && (line === null || line === void 0 || (_line$metadata4 = line.metadata) === null || _line$metadata4 === void 0 ? void 0 : _line$metadata4.product_add_schedule_time) !== null;
4560
4588
  return !(isAddTimeProduct && lineBookingUid !== undefined && lineBookingUid !== null && linkedBookingUidsToRemove.has(String(lineBookingUid)));
4561
4589
  });
4562
4590
  }
4563
- _context27.next = 31;
4591
+ if (preserveDisplayPosition && anchorIndex >= 0) {
4592
+ remainingProductIndex = tempOrder.products.findIndex(function (item) {
4593
+ var _item$metadata7;
4594
+ var uid = ((_item$metadata7 = item.metadata) === null || _item$metadata7 === void 0 ? void 0 : _item$metadata7.unique_identification_number) || item.unique_identification_number;
4595
+ return uid !== undefined && uid !== null && String(uid) === String(preserveDisplayPosition.remainingProductUid);
4596
+ });
4597
+ if (remainingProductIndex >= 0) {
4598
+ remainingProduct = tempOrder.products[remainingProductIndex];
4599
+ nextProduct = productsAfterAnchor.find(function (item) {
4600
+ return tempOrder.products.includes(item);
4601
+ });
4602
+ productsWithoutRemaining = [].concat(_toConsumableArray(tempOrder.products.slice(0, remainingProductIndex)), _toConsumableArray(tempOrder.products.slice(remainingProductIndex + 1)));
4603
+ nextProductIndex = nextProduct ? productsWithoutRemaining.indexOf(nextProduct) : -1;
4604
+ tempOrder.products = nextProductIndex >= 0 ? [].concat(_toConsumableArray(productsWithoutRemaining.slice(0, nextProductIndex)), [remainingProduct], _toConsumableArray(productsWithoutRemaining.slice(nextProductIndex))) : [].concat(_toConsumableArray(productsWithoutRemaining), [remainingProduct]);
4605
+ }
4606
+ }
4607
+ _context27.next = 35;
4564
4608
  return this.finalizeAfterProductsMutation(tempOrder);
4565
- case 31:
4609
+ case 35:
4566
4610
  this.logInfo('removeProductsFromOrder success', {
4567
4611
  identities: identities
4568
4612
  });
4569
4613
  return _context27.abrupt("return", tempOrder.products);
4570
- case 33:
4614
+ case 37:
4571
4615
  case "end":
4572
4616
  return _context27.stop();
4573
4617
  }
4574
- }, _callee24, this, [[11, 22, 25, 28]]);
4618
+ }, _callee24, this, [[14, 25, 28, 31]]);
4575
4619
  }));
4576
- function removeProductsFromOrder(_x29) {
4620
+ function removeProductsFromOrder(_x31, _x32) {
4577
4621
  return _removeProductsFromOrder.apply(this, arguments);
4578
4622
  }
4579
4623
  return removeProductsFromOrder;
@@ -4581,18 +4625,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4581
4625
  }, {
4582
4626
  key: "removeProductFromOrder",
4583
4627
  value: function () {
4584
- var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(identity) {
4628
+ var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(identity, options) {
4585
4629
  return _regeneratorRuntime().wrap(function _callee25$(_context28) {
4586
4630
  while (1) switch (_context28.prev = _context28.next) {
4587
4631
  case 0:
4588
- return _context28.abrupt("return", this.removeProductsFromOrder([identity]));
4632
+ return _context28.abrupt("return", this.removeProductsFromOrder([identity], options));
4589
4633
  case 1:
4590
4634
  case "end":
4591
4635
  return _context28.stop();
4592
4636
  }
4593
4637
  }, _callee25, this);
4594
4638
  }));
4595
- function removeProductFromOrder(_x30) {
4639
+ function removeProductFromOrder(_x33, _x34) {
4596
4640
  return _removeProductFromOrder.apply(this, arguments);
4597
4641
  }
4598
4642
  return removeProductFromOrder;
@@ -4704,7 +4748,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4704
4748
  }
4705
4749
  }, _callee27, this);
4706
4750
  }));
4707
- function applyLocalPrintOrderNumbers(_x31) {
4751
+ function applyLocalPrintOrderNumbers(_x35) {
4708
4752
  return _applyLocalPrintOrderNumbers.apply(this, arguments);
4709
4753
  }
4710
4754
  return applyLocalPrintOrderNumbers;
@@ -4729,7 +4773,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4729
4773
  }
4730
4774
  }, _callee28, this);
4731
4775
  }));
4732
- function submitTempOrder(_x32) {
4776
+ function submitTempOrder(_x36) {
4733
4777
  return _submitTempOrder.apply(this, arguments);
4734
4778
  }
4735
4779
  return submitTempOrder;
@@ -4750,7 +4794,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4750
4794
  }
4751
4795
  }, _callee29, this);
4752
4796
  }));
4753
- function submitTempOrderAsync(_x33) {
4797
+ function submitTempOrderAsync(_x37) {
4754
4798
  return _submitTempOrderAsync.apply(this, arguments);
4755
4799
  }
4756
4800
  return submitTempOrderAsync;
@@ -4920,7 +4964,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4920
4964
  }
4921
4965
  }, _callee30, this, [[26, 33]]);
4922
4966
  }));
4923
- function runSubmitTempOrder(_x34) {
4967
+ function runSubmitTempOrder(_x38) {
4924
4968
  return _runSubmitTempOrder.apply(this, arguments);
4925
4969
  }
4926
4970
  return runSubmitTempOrder;
@@ -4947,7 +4991,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4947
4991
  }
4948
4992
  }, _callee31, this);
4949
4993
  }));
4950
- function markLocalOrderSynced(_x35, _x36) {
4994
+ function markLocalOrderSynced(_x39, _x40) {
4951
4995
  return _markLocalOrderSynced.apply(this, arguments);
4952
4996
  }
4953
4997
  return markLocalOrderSynced;
@@ -5079,7 +5123,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5079
5123
  }
5080
5124
  }, _callee32, this);
5081
5125
  }));
5082
- function syncPaymentsToOrder(_x37) {
5126
+ function syncPaymentsToOrder(_x41) {
5083
5127
  return _syncPaymentsToOrder.apply(this, arguments);
5084
5128
  }
5085
5129
  return syncPaymentsToOrder;
@@ -5199,7 +5243,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5199
5243
  }
5200
5244
  }, _callee33, this);
5201
5245
  }));
5202
- function submitOrder(_x38) {
5246
+ function submitOrder(_x42) {
5203
5247
  return _submitOrder.apply(this, arguments);
5204
5248
  }
5205
5249
  return submitOrder;
@@ -5238,7 +5282,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5238
5282
  }
5239
5283
  }, _callee34, this);
5240
5284
  }));
5241
- function cancelOrder(_x39) {
5285
+ function cancelOrder(_x43) {
5242
5286
  return _cancelOrder.apply(this, arguments);
5243
5287
  }
5244
5288
  return cancelOrder;
@@ -5282,7 +5326,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5282
5326
  }
5283
5327
  }, _callee35, this);
5284
5328
  }));
5285
- function changeBookingStatus(_x40) {
5329
+ function changeBookingStatus(_x44) {
5286
5330
  return _changeBookingStatus.apply(this, arguments);
5287
5331
  }
5288
5332
  return changeBookingStatus;
@@ -5429,7 +5473,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5429
5473
  }
5430
5474
  }, _callee36, this, [[4, 18]]);
5431
5475
  }));
5432
- function createOrderByCheckout(_x41) {
5476
+ function createOrderByCheckout(_x45) {
5433
5477
  return _createOrderByCheckout.apply(this, arguments);
5434
5478
  }
5435
5479
  return createOrderByCheckout;
@@ -5454,7 +5498,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5454
5498
  }
5455
5499
  }, _callee37, this);
5456
5500
  }));
5457
- function submitSalesOrder(_x42) {
5501
+ function submitSalesOrder(_x46) {
5458
5502
  return _submitSalesOrder.apply(this, arguments);
5459
5503
  }
5460
5504
  return submitSalesOrder;
@@ -5498,7 +5542,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5498
5542
  }
5499
5543
  }, _callee38, this);
5500
5544
  }));
5501
- function sendCustomerPayLink(_x43) {
5545
+ function sendCustomerPayLink(_x47) {
5502
5546
  return _sendCustomerPayLink.apply(this, arguments);
5503
5547
  }
5504
5548
  return sendCustomerPayLink;
@@ -5542,7 +5586,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5542
5586
  }
5543
5587
  }, _callee39, this);
5544
5588
  }));
5545
- function getSalesOrderByLookup(_x44) {
5589
+ function getSalesOrderByLookup(_x48) {
5546
5590
  return _getSalesOrderByLookup.apply(this, arguments);
5547
5591
  }
5548
5592
  return getSalesOrderByLookup;
@@ -5650,7 +5694,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5650
5694
  }
5651
5695
  }, _callee40, this);
5652
5696
  }));
5653
- function hydrateTempOrderFromRecord(_x45, _x46) {
5697
+ function hydrateTempOrderFromRecord(_x49, _x50) {
5654
5698
  return _hydrateTempOrderFromRecord.apply(this, arguments);
5655
5699
  }
5656
5700
  return hydrateTempOrderFromRecord;
@@ -6027,7 +6071,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6027
6071
  }
6028
6072
  }, _callee41, this);
6029
6073
  }));
6030
- function getOrderInfo(_x47) {
6074
+ function getOrderInfo(_x51) {
6031
6075
  return _getOrderInfo.apply(this, arguments);
6032
6076
  }
6033
6077
  return getOrderInfo;
@@ -319,6 +319,24 @@ export interface ReplaceTempOrderOptions {
319
319
  saveDraft?: boolean;
320
320
  }
321
321
  export type AddProductBookingInput = Record<string, any>;
322
+ /**
323
+ * 添加商品行时的顺序控制。
324
+ * 默认追加到 products 尾部;预约数量同步可插入到既有预约组的最新行之后,
325
+ * 避免步进器修改数量改变该组展示位置。
326
+ */
327
+ export interface AddProductToOrderOptions {
328
+ insertAfterProductUid?: string;
329
+ }
330
+ /**
331
+ * 删除商品后的可选位置保持策略。
332
+ * 预约合并行减量时仍删除最新真实行,再把剩余代表行移动到被删除代表行原位置。
333
+ */
334
+ export interface RemoveProductsFromOrderOptions {
335
+ preserveDisplayPosition?: {
336
+ remainingProductUid: string;
337
+ anchorProductUid: string;
338
+ };
339
+ }
322
340
  /** 更新购物车行:仅传 SKU 时命中同 SKU 第一行;多行同 SKU 须传 unique_identification_number / 选项指纹等 */
323
341
  export interface UpdateOrderProductParams {
324
342
  product_id: number | null;
@@ -685,15 +703,15 @@ export interface OrderModuleAPI {
685
703
  updateTempOrderCustomer: (customer: UpdateTempOrderCustomerInput) => OrderSnapshot['customer'];
686
704
  updateTempOrderBuzzer: (buzzer: string) => string;
687
705
  updateTempOrderContactsInfo: (contactsInfo: Record<string, any> | null) => Record<string, any> | null;
688
- addProductToOrder: (product: Partial<OrderProduct> & OrderProductIdentity, booking?: AddProductBookingInput) => Promise<OrderProduct[]>;
706
+ addProductToOrder: (product: Partial<OrderProduct> & OrderProductIdentity, booking?: AddProductBookingInput, options?: AddProductToOrderOptions) => Promise<OrderProduct[]>;
689
707
  updateOrderProduct: (params: UpdateOrderProductParams) => Promise<OrderProduct[]>;
690
708
  /** 批量更新购物车行,末尾仅触发一次促销重算与 summary 刷新 */
691
709
  updateOrderProducts: (paramsList: UpdateOrderProductParams[]) => Promise<OrderProduct[]>;
692
710
  updateOrderProductQuantity: (params: UpdateOrderProductQuantityParams) => Promise<OrderProduct[]>;
693
711
  updateOrderBooking: (params: UpdateOrderBookingParams) => any[];
694
- removeProductFromOrder: (identity: OrderProductIdentity) => Promise<OrderProduct[]>;
712
+ removeProductFromOrder: (identity: OrderProductIdentity, options?: RemoveProductsFromOrderOptions) => Promise<OrderProduct[]>;
695
713
  /** 批量删除购物车行,末尾仅触发一次促销重算与 summary 刷新 */
696
- removeProductsFromOrder: (identities: OrderProductIdentity[]) => Promise<OrderProduct[]>;
714
+ removeProductsFromOrder: (identities: OrderProductIdentity[], options?: RemoveProductsFromOrderOptions) => Promise<OrderProduct[]>;
697
715
  /** @deprecated no-op;OrderModule 不再负责 tempOrder localStorage 持久化。 */
698
716
  persistTempOrder: () => void;
699
717
  /**
@@ -63,6 +63,17 @@ export var OrderHooks = /*#__PURE__*/function (OrderHooks) {
63
63
  * 清空时整个 payload 为 null。
64
64
  */
65
65
 
66
+ /**
67
+ * 添加商品行时的顺序控制。
68
+ * 默认追加到 products 尾部;预约数量同步可插入到既有预约组的最新行之后,
69
+ * 避免步进器修改数量改变该组展示位置。
70
+ */
71
+
72
+ /**
73
+ * 删除商品后的可选位置保持策略。
74
+ * 预约合并行减量时仍删除最新真实行,再把剩余代表行移动到被删除代表行原位置。
75
+ */
76
+
66
77
  /** 更新购物车行:仅传 SKU 时命中同 SKU 第一行;多行同 SKU 须传 unique_identification_number / 选项指纹等 */
67
78
 
68
79
  /** 仅更新购物车行数量;行定位语义与 updateOrderProduct / removeProductFromOrder 保持一致 */
@@ -2,7 +2,7 @@ import { Module, ModuleOptions, PisellCore } from '../../types';
2
2
  import { BaseModule } from '../../modules/BaseModule';
3
3
  import { BaseSalesOrderProduct, BaseSalesOrderProductIdentity, BaseSalesPaymentStatus, BaseSalesUpdateOrderProductQuantityParams, BaseSalesCalculateProductBookingPriceParams, BaseSalesPriceRecalculationContextChange, BaseSalesProductBookingPriceResult, BaseSalesQuotationCustomerScopeInfo, BaseSalesScanCodeResult } from './types';
4
4
  import { OrderModule } from '../../modules/Order';
5
- import type { AddProductBookingInput, LoadSalesDetailParams, OrderPaymentData, OrderPaymentSource, SendCustomerPayLinkParams, SyncPaymentsToOrderParams, SyncPaymentsToOrderResult, UpdateTempOrderCustomerInput, UpdateOrderBookingParams, UpdateOrderProductParams, OrderTempOrder, OrderSummary, OrderPromotionEvaluator, OrderGiftSelectResolver, OrderUnfulfilledPromotion, OrderLastGiftActions } from '../../modules/Order/types';
5
+ import type { AddProductBookingInput, AddProductToOrderOptions, LoadSalesDetailParams, OrderPaymentData, OrderPaymentSource, SendCustomerPayLinkParams, SyncPaymentsToOrderParams, SyncPaymentsToOrderResult, UpdateTempOrderCustomerInput, UpdateOrderBookingParams, UpdateOrderProductParams, OrderTempOrder, OrderSummary, OrderPromotionEvaluator, OrderGiftSelectResolver, OrderUnfulfilledPromotion, OrderLastGiftActions, RemoveProductsFromOrderOptions } from '../../modules/Order/types';
6
6
  import type { SubmitPayloadEnhancer } from '../../modules/Order/utils';
7
7
  import type { Discount } from '../../modules/Discount/types';
8
8
  import { RequestPlugin, WindowPlugin } from '../../plugins';
@@ -315,7 +315,7 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
315
315
  getQuotationCustomerScopeInfo(): BaseSalesQuotationCustomerScopeInfo;
316
316
  shouldRecalculateProductBookingPricesForContextChange(params: BaseSalesPriceRecalculationContextChange): boolean;
317
317
  calculateProductBookingPrices(paramsList: BaseSalesCalculateProductBookingPriceParams[]): Promise<BaseSalesProductBookingPriceResult[]>;
318
- addProductToOrder(product: Partial<BaseSalesOrderProduct> & BaseSalesOrderProductIdentity, booking?: AddProductBookingInput): Promise<import("../../modules/Order/types").OrderProduct[]>;
318
+ addProductToOrder(product: Partial<BaseSalesOrderProduct> & BaseSalesOrderProductIdentity, booking?: AddProductBookingInput, options?: AddProductToOrderOptions): Promise<import("../../modules/Order/types").OrderProduct[]>;
319
319
  updateOrderProduct(params: UpdateOrderProductParams): Promise<import("../../modules/Order/types").OrderProduct[]>;
320
320
  updateOrderProducts(paramsList: UpdateOrderProductParams[]): Promise<import("../../modules/Order/types").OrderProduct[]>;
321
321
  updateOrderProductQuantity(params: BaseSalesUpdateOrderProductQuantityParams): Promise<import("../../modules/Order/types").OrderProduct[]>;
@@ -331,8 +331,8 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
331
331
  * @example
332
332
  * await baseSales.removeProductsFromOrder([identityA, identityB]);
333
333
  */
334
- removeProductsFromOrder(identities: BaseSalesOrderProductIdentity[]): Promise<import("../../modules/Order/types").OrderProduct[]>;
335
- removeProductFromOrder(identity: BaseSalesOrderProductIdentity): Promise<import("../../modules/Order/types").OrderProduct[]>;
334
+ removeProductsFromOrder(identities: BaseSalesOrderProductIdentity[], options?: RemoveProductsFromOrderOptions): Promise<import("../../modules/Order/types").OrderProduct[]>;
335
+ removeProductFromOrder(identity: BaseSalesOrderProductIdentity, options?: RemoveProductsFromOrderOptions): Promise<import("../../modules/Order/types").OrderProduct[]>;
336
336
  /**
337
337
  * 注入促销评估器到底层 OrderModule。
338
338
  *