@pisell/pisellos 2.2.187 → 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.
- package/dist/model/strategy/adapter/promotion/index.js +0 -9
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +11 -4
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +11 -4
- package/dist/modules/BookingContext/utils/orderLineDisplay.d.ts +1 -0
- package/dist/modules/BookingContext/utils/orderLineDisplay.js +36 -0
- package/dist/modules/Order/index.d.ts +4 -0
- package/dist/modules/Order/index.js +143 -47
- package/dist/modules/Rules/index.js +32 -21
- package/dist/solution/BaseSales/index.js +21 -20
- package/dist/solution/BaseSales/utils/cartPromotion.js +31 -11
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.js +18 -4
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +5 -1
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +4 -0
- package/lib/modules/BookingContext/utils/orderLineDisplay.d.ts +1 -0
- package/lib/modules/BookingContext/utils/orderLineDisplay.js +56 -0
- package/lib/modules/Order/index.d.ts +4 -0
- package/lib/modules/Order/index.js +90 -10
- package/lib/modules/Rules/index.js +88 -78
- package/lib/solution/BaseSales/index.js +1 -0
- package/lib/solution/BaseSales/utils/cartPromotion.js +22 -1
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.js +19 -2
- package/package.json +1 -1
|
@@ -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));
|
|
@@ -1564,7 +1564,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1564
1564
|
);
|
|
1565
1565
|
}
|
|
1566
1566
|
async updateOrderProduct(params) {
|
|
1567
|
-
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;
|
|
1568
1568
|
const {
|
|
1569
1569
|
product_id,
|
|
1570
1570
|
product_variant_id,
|
|
@@ -1624,7 +1624,20 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1624
1624
|
nextProduct.num = (0, import_utils3.getSafeProductNum)(nextProduct.num);
|
|
1625
1625
|
const callerUpdatesTopPrice = Object.prototype.hasOwnProperty.call(updates || {}, "selling_price") || Object.prototype.hasOwnProperty.call(updates || {}, "original_price");
|
|
1626
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;
|
|
1627
|
-
|
|
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) {
|
|
1628
1641
|
const existedMeta = nextProduct.metadata || {};
|
|
1629
1642
|
nextProduct.metadata = { ...existedMeta };
|
|
1630
1643
|
delete nextProduct.metadata.source_product_price;
|
|
@@ -1639,7 +1652,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1639
1652
|
normalizedProduct.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
|
|
1640
1653
|
normalizedProduct.discount_list
|
|
1641
1654
|
);
|
|
1642
|
-
const preservedBookingUid = nextProduct.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);
|
|
1643
1656
|
if (!booking && preservedBookingUid) {
|
|
1644
1657
|
normalizedProduct.booking_uid = preservedBookingUid;
|
|
1645
1658
|
normalizedProduct.metadata = {
|
|
@@ -1649,7 +1662,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1649
1662
|
}
|
|
1650
1663
|
if (booking) {
|
|
1651
1664
|
const productUid = String(
|
|
1652
|
-
((
|
|
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)()
|
|
1653
1666
|
);
|
|
1654
1667
|
normalizedProduct.metadata = {
|
|
1655
1668
|
...normalizedProduct.metadata || {},
|
|
@@ -1679,7 +1692,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
1679
1692
|
tempOrder,
|
|
1680
1693
|
updates,
|
|
1681
1694
|
tempOrder.products[productIndex],
|
|
1682
|
-
(
|
|
1695
|
+
(_p = tempOrder.products[productIndex].metadata) == null ? void 0 : _p.unique_identification_number
|
|
1683
1696
|
);
|
|
1684
1697
|
await this.applyPromotion();
|
|
1685
1698
|
this.applyDiscount();
|
|
@@ -2333,9 +2346,19 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2333
2346
|
const existed = productsByUid[uid] && typeof productsByUid[uid] === "object" ? productsByUid[uid] : {};
|
|
2334
2347
|
const rawProduct = rawProducts[index] && typeof rawProducts[index] === "object" ? rawProducts[index] : product;
|
|
2335
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
|
+
}
|
|
2336
2359
|
productsByUid[uid] = {
|
|
2337
2360
|
...existed,
|
|
2338
|
-
origin:
|
|
2361
|
+
origin: originSnapshot
|
|
2339
2362
|
};
|
|
2340
2363
|
}
|
|
2341
2364
|
tempOrderExtend.productsByUid = productsByUid;
|
|
@@ -2345,24 +2368,81 @@ var OrderModule = class extends import_BaseModule.BaseModule {
|
|
|
2345
2368
|
nextTempOrder.vouchers = raw.vouchers || [];
|
|
2346
2369
|
return nextTempOrder;
|
|
2347
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
|
+
}
|
|
2348
2399
|
normalizeHydratedProductOptionItem(optionItem) {
|
|
2349
2400
|
const rawNum = (optionItem == null ? void 0 : optionItem.num) ?? (optionItem == null ? void 0 : optionItem.quantity) ?? 1;
|
|
2350
2401
|
const parsedNum = Number(rawNum);
|
|
2351
2402
|
const rawPrice = (optionItem == null ? void 0 : optionItem.price) ?? (optionItem == null ? void 0 : optionItem.add_price) ?? 0;
|
|
2352
2403
|
const parsedPrice = Number(rawPrice);
|
|
2353
|
-
|
|
2404
|
+
const normalized = {
|
|
2354
2405
|
option_group_item_id: optionItem == null ? void 0 : optionItem.option_group_item_id,
|
|
2355
2406
|
option_group_id: optionItem == null ? void 0 : optionItem.option_group_id,
|
|
2356
2407
|
num: Number.isFinite(parsedNum) && parsedNum > 0 ? parsedNum : 1,
|
|
2357
2408
|
price: Number.isFinite(parsedPrice) ? parsedPrice : 0
|
|
2358
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
|
+
});
|
|
2359
2439
|
}
|
|
2360
2440
|
resolveHydratedProductOptions(row) {
|
|
2361
2441
|
var _a;
|
|
2442
|
+
const skuOptions = (_a = row.product_sku) == null ? void 0 : _a.option;
|
|
2362
2443
|
if (Array.isArray(row.product_option_item) && row.product_option_item.length > 0) {
|
|
2363
|
-
return row.product_option_item;
|
|
2444
|
+
return this.mergeHydratedProductOptionDisplayFields(row.product_option_item, skuOptions);
|
|
2364
2445
|
}
|
|
2365
|
-
const skuOptions = (_a = row.product_sku) == null ? void 0 : _a.option;
|
|
2366
2446
|
if (!Array.isArray(skuOptions))
|
|
2367
2447
|
return [];
|
|
2368
2448
|
return skuOptions.map(
|