@pisell/pisellos 2.2.186 → 2.2.188

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 (27) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  2. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +11 -4
  3. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +11 -4
  4. package/dist/modules/BookingContext/utils/orderLineDisplay.d.ts +1 -0
  5. package/dist/modules/BookingContext/utils/orderLineDisplay.js +36 -0
  6. package/dist/modules/Order/index.d.ts +4 -0
  7. package/dist/modules/Order/index.js +150 -50
  8. package/dist/modules/Rules/index.js +32 -21
  9. package/dist/solution/BaseSales/index.d.ts +1 -0
  10. package/dist/solution/BaseSales/index.js +45 -30
  11. package/dist/solution/BaseSales/utils/cartPromotion.js +31 -11
  12. package/dist/solution/BookingByStep/index.d.ts +1 -1
  13. package/dist/solution/BookingTicket/index.js +18 -4
  14. package/lib/model/strategy/adapter/promotion/index.js +0 -49
  15. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +5 -1
  16. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +4 -0
  17. package/lib/modules/BookingContext/utils/orderLineDisplay.d.ts +1 -0
  18. package/lib/modules/BookingContext/utils/orderLineDisplay.js +56 -0
  19. package/lib/modules/Order/index.d.ts +4 -0
  20. package/lib/modules/Order/index.js +97 -13
  21. package/lib/modules/Rules/index.js +88 -78
  22. package/lib/solution/BaseSales/index.d.ts +1 -0
  23. package/lib/solution/BaseSales/index.js +16 -1
  24. package/lib/solution/BaseSales/utils/cartPromotion.js +22 -1
  25. package/lib/solution/BookingByStep/index.d.ts +1 -1
  26. package/lib/solution/BookingTicket/index.js +19 -2
  27. package/package.json +1 -1
@@ -0,0 +1,56 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/modules/BookingContext/utils/orderLineDisplay.ts
20
+ var orderLineDisplay_exports = {};
21
+ __export(orderLineDisplay_exports, {
22
+ buildProductOptionStringFromOrderLine: () => buildProductOptionStringFromOrderLine
23
+ });
24
+ module.exports = __toCommonJS(orderLineDisplay_exports);
25
+ function pickDisplayText(value) {
26
+ if (value === void 0 || value === null)
27
+ return "";
28
+ if (typeof value === "string")
29
+ return value;
30
+ if (typeof value !== "object")
31
+ return String(value);
32
+ return value.auto || value.original || value.en || value["zh-CN"] || value["zh-HK"] || "";
33
+ }
34
+ function formatNamePair(group, item) {
35
+ const groupText = pickDisplayText(group);
36
+ const itemText = pickDisplayText(item);
37
+ if (groupText && itemText)
38
+ return `${groupText}:${itemText}`;
39
+ return groupText || itemText;
40
+ }
41
+ function buildProductOptionStringFromOrderLine(product) {
42
+ const segments = [];
43
+ const sku = (product == null ? void 0 : product.product_sku) || {};
44
+ if (Array.isArray(sku.variant)) {
45
+ for (const variant of sku.variant) {
46
+ const segment = formatNamePair(variant == null ? void 0 : variant.group, variant == null ? void 0 : variant.item);
47
+ if (segment)
48
+ segments.push(segment);
49
+ }
50
+ }
51
+ return segments.join(", ");
52
+ }
53
+ // Annotate the CommonJS export names for ESM import in node:
54
+ 0 && (module.exports = {
55
+ buildProductOptionStringFromOrderLine
56
+ });
@@ -312,7 +312,11 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
312
312
  recalcOnHydrate?: boolean;
313
313
  }): Promise<OrderTempOrder>;
314
314
  private normalizeTempOrderForRuntime;
315
+ private pickHydratedDisplayText;
316
+ private formatHydratedNamePair;
317
+ private buildHydratedProductOptionString;
315
318
  private normalizeHydratedProductOptionItem;
319
+ private mergeHydratedProductOptionDisplayFields;
316
320
  private resolveHydratedProductOptions;
317
321
  private normalizeHydratedOrderProduct;
318
322
  getLastOrderInfo(): Record<string, any> | undefined;
@@ -694,7 +694,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
694
694
  return (0, import_utils.mapPaymentItemsToOrderPayments)(payments, {
695
695
  includeVoided: false
696
696
  }).reduce((sum, payment) => {
697
- const amount = new import_decimal.default(payment.amount || 0);
697
+ const amount = new import_decimal.default(payment.amount || 0).minus(new import_decimal.default(payment.service_fee || 0));
698
698
  const rounding = new import_decimal.default(payment.rounding_amount || 0);
699
699
  return sum.plus(amount.minus(rounding));
700
700
  }, new import_decimal.default(0));
@@ -719,12 +719,16 @@ var OrderModule = class extends import_BaseModule.BaseModule {
719
719
  }
720
720
  updateTempOrderPaymentStatus(tempOrder) {
721
721
  const paymentTotal = this.calculatePaymentTotal(tempOrder.payments || []);
722
+ const targetAmount = this.getPaymentTargetAmount();
723
+ if (targetAmount.lte(0)) {
724
+ tempOrder.payment_status = "paid";
725
+ return;
726
+ }
722
727
  if (paymentTotal.lte(0)) {
723
728
  tempOrder.payment_status = tempOrder.payment_status || "payment_processing";
724
729
  return;
725
730
  }
726
- const targetAmount = this.getPaymentTargetAmount();
727
- tempOrder.payment_status = targetAmount.gt(0) && paymentTotal.gte(targetAmount) ? "paid" : "partially_paid";
731
+ tempOrder.payment_status = paymentTotal.gte(targetAmount) ? "paid" : "partially_paid";
728
732
  }
729
733
  calculatePaidPaymentSummary(payments) {
730
734
  return (payments || []).reduce(
@@ -1560,7 +1564,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1560
1564
  );
1561
1565
  }
1562
1566
  async updateOrderProduct(params) {
1563
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1567
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
1564
1568
  const {
1565
1569
  product_id,
1566
1570
  product_variant_id,
@@ -1620,7 +1624,20 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1620
1624
  nextProduct.num = (0, import_utils3.getSafeProductNum)(nextProduct.num);
1621
1625
  const callerUpdatesTopPrice = Object.prototype.hasOwnProperty.call(updates || {}, "selling_price") || Object.prototype.hasOwnProperty.call(updates || {}, "original_price");
1622
1626
  const callerUpdatesMainMeta = ((_b = updates == null ? void 0 : updates.metadata) == null ? void 0 : _b.main_product_selling_price) !== void 0 || ((_c = updates == null ? void 0 : updates.metadata) == null ? void 0 : _c.main_product_original_price) !== void 0 || ((_d = updates == null ? void 0 : updates.metadata) == null ? void 0 : _d.source_product_price) !== void 0;
1623
- if (callerUpdatesTopPrice && !callerUpdatesMainMeta) {
1627
+ const isPersistedOrderLine = targetProduct.order_detail_id !== void 0 && targetProduct.order_detail_id !== null;
1628
+ const callerUpdatesManualPrice = ((_e = updates == null ? void 0 : updates.metadata) == null ? void 0 : _e.price_override) !== void 0 || ((_f = updates == null ? void 0 : updates.metadata) == null ? void 0 : _f.is_manual_discount) !== void 0 || ((_g = updates == null ? void 0 : updates.metadata) == null ? void 0 : _g.product_discount_reason) !== void 0 || Array.isArray(updates == null ? void 0 : updates.discount_list) && updates.discount_list.length > 0;
1629
+ if (isPersistedOrderLine && !callerUpdatesManualPrice) {
1630
+ nextProduct.selling_price = targetProduct.selling_price;
1631
+ nextProduct.original_price = targetProduct.original_price;
1632
+ nextProduct.payment_price = targetProduct.payment_price;
1633
+ nextProduct.metadata = {
1634
+ ...nextProduct.metadata || {},
1635
+ source_product_price: (_h = targetProduct.metadata) == null ? void 0 : _h.source_product_price,
1636
+ main_product_selling_price: (_i = targetProduct.metadata) == null ? void 0 : _i.main_product_selling_price,
1637
+ main_product_original_price: (_j = targetProduct.metadata) == null ? void 0 : _j.main_product_original_price,
1638
+ price_schema_version: (_k = targetProduct.metadata) == null ? void 0 : _k.price_schema_version
1639
+ };
1640
+ } else if (callerUpdatesTopPrice && !callerUpdatesMainMeta) {
1624
1641
  const existedMeta = nextProduct.metadata || {};
1625
1642
  nextProduct.metadata = { ...existedMeta };
1626
1643
  delete nextProduct.metadata.source_product_price;
@@ -1635,7 +1652,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1635
1652
  normalizedProduct.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
1636
1653
  normalizedProduct.discount_list
1637
1654
  );
1638
- const preservedBookingUid = nextProduct.booking_uid || ((_e = nextProduct.metadata) == null ? void 0 : _e.booking_uid) || targetProduct.booking_uid || ((_f = targetProduct.metadata) == null ? void 0 : _f.booking_uid);
1655
+ const preservedBookingUid = nextProduct.booking_uid || ((_l = nextProduct.metadata) == null ? void 0 : _l.booking_uid) || targetProduct.booking_uid || ((_m = targetProduct.metadata) == null ? void 0 : _m.booking_uid);
1639
1656
  if (!booking && preservedBookingUid) {
1640
1657
  normalizedProduct.booking_uid = preservedBookingUid;
1641
1658
  normalizedProduct.metadata = {
@@ -1645,7 +1662,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1645
1662
  }
1646
1663
  if (booking) {
1647
1664
  const productUid = String(
1648
- ((_g = normalizedProduct.metadata) == null ? void 0 : _g.unique_identification_number) || ((_h = targetProduct.metadata) == null ? void 0 : _h.unique_identification_number) || unique_identification_number || (0, import_utils.createUuidV4)()
1665
+ ((_n = normalizedProduct.metadata) == null ? void 0 : _n.unique_identification_number) || ((_o = targetProduct.metadata) == null ? void 0 : _o.unique_identification_number) || unique_identification_number || (0, import_utils.createUuidV4)()
1649
1666
  );
1650
1667
  normalizedProduct.metadata = {
1651
1668
  ...normalizedProduct.metadata || {},
@@ -1675,7 +1692,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1675
1692
  tempOrder,
1676
1693
  updates,
1677
1694
  tempOrder.products[productIndex],
1678
- (_i = tempOrder.products[productIndex].metadata) == null ? void 0 : _i.unique_identification_number
1695
+ (_p = tempOrder.products[productIndex].metadata) == null ? void 0 : _p.unique_identification_number
1679
1696
  );
1680
1697
  await this.applyPromotion();
1681
1698
  this.applyDiscount();
@@ -1945,7 +1962,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1945
1962
  );
1946
1963
  const paymentTotal = this.calculatePaymentTotal(mappedPayments);
1947
1964
  const targetAmount = this.getPaymentTargetAmount();
1948
- const isFullyPaid = targetAmount.lte(0) ? false : paymentTotal.gte(targetAmount);
1965
+ const isFullyPaid = targetAmount.lte(0) ? true : paymentTotal.gte(targetAmount);
1949
1966
  const paymentStatus = isFullyPaid ? params.paymentStatus || "paid" : "partially_paid";
1950
1967
  tempOrder.payments = mappedPayments;
1951
1968
  tempOrder.payment_status = paymentStatus;
@@ -2329,9 +2346,19 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2329
2346
  const existed = productsByUid[uid] && typeof productsByUid[uid] === "object" ? productsByUid[uid] : {};
2330
2347
  const rawProduct = rawProducts[index] && typeof rawProducts[index] === "object" ? rawProducts[index] : product;
2331
2348
  const origin = existed.origin ?? rawProduct._origin ?? ((_b = rawProduct.metadata) == null ? void 0 : _b.origin) ?? rawProduct;
2349
+ const originSnapshot = (0, import_lodash_es.cloneDeep)(origin);
2350
+ const productOptionString = this.buildHydratedProductOptionString(rawProduct) || this.buildHydratedProductOptionString(product);
2351
+ if (productOptionString && originSnapshot && typeof originSnapshot === "object") {
2352
+ if (originSnapshot.product_option_string === void 0) {
2353
+ originSnapshot.product_option_string = productOptionString;
2354
+ }
2355
+ if (originSnapshot.product_options_stirng === void 0) {
2356
+ originSnapshot.product_options_stirng = productOptionString;
2357
+ }
2358
+ }
2332
2359
  productsByUid[uid] = {
2333
2360
  ...existed,
2334
- origin: (0, import_lodash_es.cloneDeep)(origin)
2361
+ origin: originSnapshot
2335
2362
  };
2336
2363
  }
2337
2364
  tempOrderExtend.productsByUid = productsByUid;
@@ -2341,24 +2368,81 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2341
2368
  nextTempOrder.vouchers = raw.vouchers || [];
2342
2369
  return nextTempOrder;
2343
2370
  }
2371
+ pickHydratedDisplayText(value) {
2372
+ if (value === void 0 || value === null)
2373
+ return "";
2374
+ if (typeof value === "string")
2375
+ return value;
2376
+ if (typeof value !== "object")
2377
+ return String(value);
2378
+ return value.auto || value.original || value.en || value["zh-CN"] || value["zh-HK"] || "";
2379
+ }
2380
+ formatHydratedNamePair(group, item) {
2381
+ const groupText = this.pickHydratedDisplayText(group);
2382
+ const itemText = this.pickHydratedDisplayText(item);
2383
+ if (groupText && itemText)
2384
+ return `${groupText}:${itemText}`;
2385
+ return groupText || itemText;
2386
+ }
2387
+ buildHydratedProductOptionString(product) {
2388
+ const segments = [];
2389
+ const sku = (product == null ? void 0 : product.product_sku) || {};
2390
+ if (Array.isArray(sku.variant)) {
2391
+ for (const variant of sku.variant) {
2392
+ const segment = this.formatHydratedNamePair(variant == null ? void 0 : variant.group, variant == null ? void 0 : variant.item);
2393
+ if (segment)
2394
+ segments.push(segment);
2395
+ }
2396
+ }
2397
+ return segments.join(", ");
2398
+ }
2344
2399
  normalizeHydratedProductOptionItem(optionItem) {
2345
2400
  const rawNum = (optionItem == null ? void 0 : optionItem.num) ?? (optionItem == null ? void 0 : optionItem.quantity) ?? 1;
2346
2401
  const parsedNum = Number(rawNum);
2347
2402
  const rawPrice = (optionItem == null ? void 0 : optionItem.price) ?? (optionItem == null ? void 0 : optionItem.add_price) ?? 0;
2348
2403
  const parsedPrice = Number(rawPrice);
2349
- return {
2404
+ const normalized = {
2350
2405
  option_group_item_id: optionItem == null ? void 0 : optionItem.option_group_item_id,
2351
2406
  option_group_id: optionItem == null ? void 0 : optionItem.option_group_id,
2352
2407
  num: Number.isFinite(parsedNum) && parsedNum > 0 ? parsedNum : 1,
2353
2408
  price: Number.isFinite(parsedPrice) ? parsedPrice : 0
2354
2409
  };
2410
+ if ((optionItem == null ? void 0 : optionItem.name) !== void 0)
2411
+ normalized.name = optionItem.name;
2412
+ if ((optionItem == null ? void 0 : optionItem.group_name) !== void 0)
2413
+ normalized.group_name = optionItem.group_name;
2414
+ if ((optionItem == null ? void 0 : optionItem.id) !== void 0)
2415
+ normalized.id = optionItem.id;
2416
+ return normalized;
2417
+ }
2418
+ mergeHydratedProductOptionDisplayFields(options, skuOptions) {
2419
+ if (!Array.isArray(skuOptions) || skuOptions.length === 0)
2420
+ return options;
2421
+ const displayByItemId = /* @__PURE__ */ new Map();
2422
+ for (const option of skuOptions) {
2423
+ const key = option == null ? void 0 : option.option_group_item_id;
2424
+ if (key === void 0 || key === null || key === "")
2425
+ continue;
2426
+ displayByItemId.set(String(key), option);
2427
+ }
2428
+ return options.map((option) => {
2429
+ const display = displayByItemId.get(String((option == null ? void 0 : option.option_group_item_id) ?? ""));
2430
+ if (!display)
2431
+ return option;
2432
+ return {
2433
+ ...option,
2434
+ ...option.name === void 0 && display.name !== void 0 ? { name: display.name } : {},
2435
+ ...option.group_name === void 0 && display.group_name !== void 0 ? { group_name: display.group_name } : {},
2436
+ ...option.id === void 0 && display.id !== void 0 ? { id: display.id } : {}
2437
+ };
2438
+ });
2355
2439
  }
2356
2440
  resolveHydratedProductOptions(row) {
2357
2441
  var _a;
2442
+ const skuOptions = (_a = row.product_sku) == null ? void 0 : _a.option;
2358
2443
  if (Array.isArray(row.product_option_item) && row.product_option_item.length > 0) {
2359
- return row.product_option_item;
2444
+ return this.mergeHydratedProductOptionDisplayFields(row.product_option_item, skuOptions);
2360
2445
  }
2361
- const skuOptions = (_a = row.product_sku) == null ? void 0 : _a.option;
2362
2446
  if (!Array.isArray(skuOptions))
2363
2447
  return [];
2364
2448
  return skuOptions.map(