@pisell/pisellos 2.2.244 → 2.2.246
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/evaluator.js +3 -2
- package/dist/model/strategy/adapter/walletPass/utils.js +7 -4
- package/dist/modules/BookingContext/index.d.ts +48 -0
- package/dist/modules/BookingContext/index.js +566 -0
- package/dist/modules/BookingContext/types.d.ts +102 -0
- package/dist/modules/BookingContext/types.js +51 -0
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +284 -0
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +148 -0
- package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +76 -0
- package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +218 -0
- package/dist/modules/BookingContext/utils/flexible.d.ts +28 -0
- package/dist/modules/BookingContext/utils/flexible.js +56 -0
- package/dist/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
- package/dist/modules/BookingContext/utils/formatResourceList.js +38 -0
- package/dist/modules/BookingContext/utils/index.d.ts +11 -0
- package/dist/modules/BookingContext/utils/index.js +11 -0
- package/dist/modules/BookingContext/utils/noResource.d.ts +13 -0
- package/dist/modules/BookingContext/utils/noResource.js +77 -0
- package/dist/modules/BookingContext/utils/orderLineDisplay.d.ts +1 -0
- package/dist/modules/BookingContext/utils/orderLineDisplay.js +36 -0
- package/dist/modules/BookingContext/utils/productExtend.d.ts +72 -0
- package/dist/modules/BookingContext/utils/productExtend.js +339 -0
- package/dist/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
- package/dist/modules/BookingContext/utils/resourceErrors.js +74 -0
- package/dist/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
- package/dist/modules/BookingContext/utils/resourceSelection.js +24 -0
- package/dist/modules/BookingContext/utils/resources.d.ts +80 -0
- package/dist/modules/BookingContext/utils/resources.js +486 -0
- package/dist/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
- package/dist/modules/BookingContext/utils/serviceTimes.js +151 -0
- package/dist/modules/BookingContext/utils/timeSlices.d.ts +42 -0
- package/dist/modules/BookingContext/utils/timeSlices.js +100 -0
- package/dist/modules/Cart/utils/cartProduct.js +24 -3
- package/dist/modules/Cart/utils/changePrice.js +11 -11
- package/dist/modules/Customer/index.d.ts +20 -0
- package/dist/modules/Customer/index.js +172 -83
- package/dist/modules/Customer/types.d.ts +2 -0
- package/dist/modules/Discount/index.d.ts +1 -1
- package/dist/modules/Discount/index.js +13 -6
- package/dist/modules/Discount/types.d.ts +1 -0
- package/dist/modules/OpenData/index.d.ts +8 -0
- package/dist/modules/OpenData/index.js +37 -17
- package/dist/modules/Order/index.d.ts +277 -18
- package/dist/modules/Order/index.js +3581 -779
- package/dist/modules/Order/types.d.ts +286 -31
- package/dist/modules/Order/types.js +38 -0
- package/dist/modules/Order/utils/manualProductDiscount.d.ts +106 -0
- package/dist/modules/Order/utils/manualProductDiscount.js +210 -0
- package/dist/modules/Order/utils.d.ts +147 -5
- package/dist/modules/Order/utils.js +750 -104
- package/dist/modules/Payment/index.d.ts +10 -13
- package/dist/modules/Payment/index.js +467 -837
- package/dist/modules/Payment/types.d.ts +2 -0
- package/dist/modules/Payment/utils.js +2 -1
- package/dist/modules/Payment/walletpass.js +41 -25
- package/dist/modules/ProductList/index.d.ts +16 -12
- package/dist/modules/ProductList/index.js +133 -59
- package/dist/modules/ProductList/types.d.ts +14 -0
- package/dist/modules/Quotation/index.d.ts +0 -1
- package/dist/modules/Quotation/index.js +25 -22
- package/dist/modules/Rules/index.d.ts +4 -0
- package/dist/modules/Rules/index.js +97 -70
- package/dist/modules/Rules/types.d.ts +1 -0
- package/dist/modules/SalesSummary/index.d.ts +8 -25
- package/dist/modules/SalesSummary/index.js +86 -35
- package/dist/modules/SalesSummary/types.d.ts +4 -1
- package/dist/modules/SalesSummary/utils.d.ts +2 -25
- package/dist/modules/SalesSummary/utils.js +794 -162
- package/dist/modules/Schedule/index.d.ts +7 -0
- package/dist/modules/Schedule/index.js +24 -2
- package/dist/modules/Summary/index.js +4 -3
- package/dist/modules/SurchargeList/index.d.ts +16 -0
- package/dist/modules/SurchargeList/index.js +162 -0
- package/dist/modules/SurchargeList/types.d.ts +11 -0
- package/dist/modules/SurchargeList/types.js +1 -0
- package/dist/modules/index.d.ts +2 -0
- package/dist/modules/index.js +3 -1
- package/dist/plugins/request.d.ts +1 -0
- package/dist/server/index.d.ts +204 -1
- package/dist/server/index.js +3654 -922
- package/dist/server/modules/index.d.ts +2 -0
- package/dist/server/modules/index.js +2 -0
- package/dist/server/modules/order/index.d.ts +120 -3
- package/dist/server/modules/order/index.js +1762 -448
- package/dist/server/modules/order/types.d.ts +32 -3
- package/dist/server/modules/order/types.js +8 -0
- package/dist/server/modules/order/utils/filterBookings.js +26 -3
- package/dist/server/modules/order/utils/filterOrders.js +23 -8
- package/dist/server/modules/payment/index.d.ts +28 -0
- package/dist/server/modules/payment/index.js +305 -0
- package/dist/server/modules/payment/types.d.ts +9 -0
- package/dist/server/modules/payment/types.js +1 -0
- package/dist/server/modules/products/index.d.ts +34 -7
- package/dist/server/modules/products/index.js +631 -317
- package/dist/server/modules/resource/index.d.ts +2 -0
- package/dist/server/modules/resource/index.js +29 -3
- package/dist/server/modules/schedule/index.d.ts +4 -4
- package/dist/server/modules/schedule/index.js +111 -88
- package/dist/server/test.json +713 -0
- package/dist/server/utils/small-ticket.d.ts +71 -0
- package/dist/server/utils/small-ticket.js +840 -0
- package/dist/solution/BaseSales/index.d.ts +133 -10
- package/dist/solution/BaseSales/index.js +1950 -447
- package/dist/solution/BaseSales/types.d.ts +82 -6
- package/dist/solution/BaseSales/types.js +5 -4
- package/dist/solution/BaseSales/utils/cartPromotion.d.ts +287 -0
- package/dist/solution/BaseSales/utils/cartPromotion.js +1438 -0
- package/dist/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
- package/dist/solution/BaseSales/utils/quotationPrice.js +237 -0
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -0
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +105 -24
- package/dist/solution/BaseSales/utils.d.ts +1 -1
- package/dist/solution/BaseSales/utils.js +62 -21
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +271 -11
- package/dist/solution/BookingTicket/index.js +1777 -242
- package/dist/solution/BookingTicket/types.d.ts +118 -1
- package/dist/solution/BookingTicket/types.js +41 -2
- package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +117 -0
- package/dist/solution/BookingTicket/utils/addProductDecision.js +346 -0
- package/dist/solution/BookingTicket/utils/addTimeAvailability.d.ts +35 -0
- package/dist/solution/BookingTicket/utils/addTimeAvailability.js +95 -0
- package/dist/solution/BookingTicket/utils/bookingStatus.d.ts +40 -0
- package/dist/solution/BookingTicket/utils/bookingStatus.js +70 -0
- package/dist/solution/BookingTicket/utils/cartView.d.ts +9 -1
- package/dist/solution/BookingTicket/utils/cartView.js +94 -7
- package/dist/solution/BookingTicket/utils/exampleData.d.ts +123 -0
- package/dist/solution/BookingTicket/utils/exampleData.js +183 -0
- package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +185 -0
- package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.js +438 -0
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +36 -0
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +400 -0
- package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +32 -0
- package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +56 -0
- package/dist/solution/BookingTicket/utils/scan/index.d.ts +5 -0
- package/dist/solution/BookingTicket/utils/scan/index.js +20 -8
- package/dist/solution/BookingTicket/utils/scan/scanProductValues.d.ts +21 -0
- package/dist/solution/BookingTicket/utils/scan/scanProductValues.js +150 -0
- package/dist/solution/BookingTicket/utils/sessionCatalogStale.d.ts +23 -0
- package/dist/solution/BookingTicket/utils/sessionCatalogStale.js +78 -0
- package/dist/solution/Checkout/index.d.ts +1 -0
- package/dist/solution/Checkout/index.js +10 -9
- package/dist/solution/RegisterAndLogin/config.js +2 -10
- package/dist/solution/ScanOrder/index.d.ts +9 -3
- package/dist/solution/ScanOrder/index.js +241 -134
- package/dist/solution/ScanOrder/types.d.ts +9 -5
- package/dist/solution/ScanOrder/types.js +2 -3
- package/dist/solution/ScanOrder/utils.d.ts +1 -1
- package/dist/solution/ScanOrder/utils.js +84 -22
- package/dist/solution/VenueBooking/index.d.ts +5 -2
- package/dist/solution/VenueBooking/index.js +110 -59
- package/dist/solution/VenueBooking/sales-section-4-annotated.json +0 -2
- package/dist/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
- package/dist/solution/VenueBooking/utils/slotMerge.js +10 -0
- package/dist/types/index.d.ts +10 -0
- package/lib/model/strategy/adapter/promotion/evaluator.js +2 -1
- package/lib/model/strategy/adapter/promotion/index.js +49 -0
- package/lib/model/strategy/adapter/walletPass/utils.js +3 -2
- package/lib/modules/BookingContext/index.d.ts +48 -0
- package/lib/modules/BookingContext/index.js +368 -0
- package/lib/modules/BookingContext/types.d.ts +102 -0
- package/lib/modules/BookingContext/types.js +34 -0
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +276 -0
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +154 -0
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +76 -0
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +201 -0
- package/lib/modules/BookingContext/utils/flexible.d.ts +28 -0
- package/lib/modules/BookingContext/utils/flexible.js +80 -0
- package/lib/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
- package/lib/modules/BookingContext/utils/formatResourceList.js +50 -0
- package/lib/modules/BookingContext/utils/index.d.ts +11 -0
- package/lib/modules/BookingContext/utils/index.js +43 -0
- package/lib/modules/BookingContext/utils/noResource.d.ts +13 -0
- package/lib/modules/BookingContext/utils/noResource.js +90 -0
- package/lib/modules/BookingContext/utils/orderLineDisplay.d.ts +1 -0
- package/lib/modules/BookingContext/utils/orderLineDisplay.js +56 -0
- package/lib/modules/BookingContext/utils/productExtend.d.ts +72 -0
- package/lib/modules/BookingContext/utils/productExtend.js +283 -0
- package/lib/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
- package/lib/modules/BookingContext/utils/resourceErrors.js +80 -0
- package/lib/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
- package/lib/modules/BookingContext/utils/resourceSelection.js +46 -0
- package/lib/modules/BookingContext/utils/resources.d.ts +80 -0
- package/lib/modules/BookingContext/utils/resources.js +377 -0
- package/lib/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
- package/lib/modules/BookingContext/utils/serviceTimes.js +162 -0
- package/lib/modules/BookingContext/utils/timeSlices.d.ts +42 -0
- package/lib/modules/BookingContext/utils/timeSlices.js +124 -0
- package/lib/modules/Cart/utils/cartProduct.js +20 -3
- package/lib/modules/Cart/utils/changePrice.js +12 -20
- package/lib/modules/Customer/index.d.ts +20 -0
- package/lib/modules/Customer/index.js +64 -11
- package/lib/modules/Customer/types.d.ts +2 -0
- package/lib/modules/Discount/index.d.ts +1 -1
- package/lib/modules/Discount/index.js +9 -1
- package/lib/modules/Discount/types.d.ts +1 -0
- package/lib/modules/OpenData/index.d.ts +8 -0
- package/lib/modules/OpenData/index.js +19 -5
- package/lib/modules/Order/index.d.ts +277 -18
- package/lib/modules/Order/index.js +2317 -337
- package/lib/modules/Order/types.d.ts +286 -31
- package/lib/modules/Order/types.js +1 -0
- package/lib/modules/Order/utils/manualProductDiscount.d.ts +106 -0
- package/lib/modules/Order/utils/manualProductDiscount.js +206 -0
- package/lib/modules/Order/utils.d.ts +147 -5
- package/lib/modules/Order/utils.js +615 -46
- package/lib/modules/Payment/index.d.ts +10 -13
- package/lib/modules/Payment/index.js +18 -150
- package/lib/modules/Payment/types.d.ts +2 -0
- package/lib/modules/Payment/utils.js +2 -1
- package/lib/modules/Payment/walletpass.js +16 -3
- package/lib/modules/ProductList/index.d.ts +16 -12
- package/lib/modules/ProductList/index.js +41 -4
- package/lib/modules/ProductList/types.d.ts +14 -0
- package/lib/modules/Quotation/index.d.ts +0 -1
- package/lib/modules/Quotation/index.js +19 -16
- package/lib/modules/Rules/index.d.ts +4 -0
- package/lib/modules/Rules/index.js +137 -120
- package/lib/modules/Rules/types.d.ts +1 -0
- package/lib/modules/SalesSummary/index.d.ts +8 -25
- package/lib/modules/SalesSummary/index.js +30 -4
- package/lib/modules/SalesSummary/types.d.ts +4 -1
- package/lib/modules/SalesSummary/utils.d.ts +2 -25
- package/lib/modules/SalesSummary/utils.js +645 -91
- package/lib/modules/Schedule/index.d.ts +7 -0
- package/lib/modules/Schedule/index.js +17 -1
- package/lib/modules/Summary/index.js +5 -4
- package/lib/modules/SurchargeList/index.d.ts +16 -0
- package/lib/modules/SurchargeList/index.js +89 -0
- package/lib/modules/SurchargeList/types.d.ts +11 -0
- package/lib/modules/SurchargeList/types.js +17 -0
- package/lib/modules/index.d.ts +2 -0
- package/lib/modules/index.js +5 -1
- package/lib/plugins/request.d.ts +1 -0
- package/lib/server/index.d.ts +204 -1
- package/lib/server/index.js +1891 -59
- package/lib/server/modules/index.d.ts +2 -0
- package/lib/server/modules/index.js +3 -0
- package/lib/server/modules/order/index.d.ts +120 -3
- package/lib/server/modules/order/index.js +887 -94
- package/lib/server/modules/order/types.d.ts +32 -3
- package/lib/server/modules/order/utils/filterBookings.js +24 -5
- package/lib/server/modules/order/utils/filterOrders.js +15 -6
- package/lib/server/modules/payment/index.d.ts +28 -0
- package/lib/server/modules/payment/index.js +192 -0
- package/lib/server/modules/payment/types.d.ts +9 -0
- package/lib/server/modules/payment/types.js +17 -0
- package/lib/server/modules/products/index.d.ts +34 -7
- package/lib/server/modules/products/index.js +189 -54
- package/lib/server/modules/resource/index.d.ts +2 -0
- package/lib/server/modules/resource/index.js +27 -3
- package/lib/server/modules/schedule/index.d.ts +4 -4
- package/lib/server/modules/schedule/index.js +47 -40
- package/lib/server/test.json +713 -0
- package/lib/server/utils/small-ticket.d.ts +71 -0
- package/lib/server/utils/small-ticket.js +800 -0
- package/lib/solution/BaseSales/index.d.ts +133 -10
- package/lib/solution/BaseSales/index.js +1111 -63
- package/lib/solution/BaseSales/types.d.ts +82 -6
- package/lib/solution/BaseSales/types.js +3 -1
- package/lib/solution/BaseSales/utils/cartPromotion.d.ts +287 -0
- package/lib/solution/BaseSales/utils/cartPromotion.js +992 -0
- package/lib/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
- package/lib/solution/BaseSales/utils/quotationPrice.js +277 -0
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -0
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +106 -18
- package/lib/solution/BaseSales/utils.d.ts +1 -1
- package/lib/solution/BaseSales/utils.js +54 -10
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +271 -11
- package/lib/solution/BookingTicket/index.js +922 -29
- package/lib/solution/BookingTicket/types.d.ts +118 -1
- package/lib/solution/BookingTicket/types.js +11 -0
- package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +117 -0
- package/lib/solution/BookingTicket/utils/addProductDecision.js +318 -0
- package/lib/solution/BookingTicket/utils/addTimeAvailability.d.ts +35 -0
- package/lib/solution/BookingTicket/utils/addTimeAvailability.js +125 -0
- package/lib/solution/BookingTicket/utils/bookingStatus.d.ts +40 -0
- package/lib/solution/BookingTicket/utils/bookingStatus.js +44 -2
- package/lib/solution/BookingTicket/utils/cartView.d.ts +9 -1
- package/lib/solution/BookingTicket/utils/cartView.js +61 -6
- package/lib/solution/BookingTicket/utils/exampleData.d.ts +123 -0
- package/lib/solution/BookingTicket/utils/exampleData.js +0 -0
- package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +185 -0
- package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +254 -0
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +36 -0
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +169 -0
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +32 -0
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +51 -0
- package/lib/solution/BookingTicket/utils/scan/index.d.ts +5 -0
- package/lib/solution/BookingTicket/utils/scan/index.js +17 -3
- package/lib/solution/BookingTicket/utils/scan/scanProductValues.d.ts +21 -0
- package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +127 -0
- package/lib/solution/BookingTicket/utils/sessionCatalogStale.d.ts +23 -0
- package/lib/solution/BookingTicket/utils/sessionCatalogStale.js +85 -0
- package/lib/solution/Checkout/index.d.ts +1 -0
- package/lib/solution/Checkout/index.js +1 -2
- package/lib/solution/RegisterAndLogin/config.js +2 -10
- package/lib/solution/ScanOrder/index.d.ts +9 -3
- package/lib/solution/ScanOrder/index.js +153 -70
- package/lib/solution/ScanOrder/types.d.ts +9 -5
- package/lib/solution/ScanOrder/utils.d.ts +1 -1
- package/lib/solution/ScanOrder/utils.js +83 -17
- package/lib/solution/VenueBooking/index.d.ts +5 -2
- package/lib/solution/VenueBooking/index.js +54 -17
- package/lib/solution/VenueBooking/sales-section-4-annotated.json +0 -2
- package/lib/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
- package/lib/solution/VenueBooking/utils/slotMerge.js +10 -0
- package/lib/types/index.d.ts +10 -0
- package/package.json +1 -1
- package/dist/solution/Checkout/appointmentDemo.json +0 -1
- package/lib/solution/Checkout/appointmentDemo.json +0 -1
|
@@ -0,0 +1,992 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/solution/BaseSales/utils/cartPromotion.ts
|
|
30
|
+
var cartPromotion_exports = {};
|
|
31
|
+
__export(cartPromotion_exports, {
|
|
32
|
+
appendPromotionTags: () => appendPromotionTags,
|
|
33
|
+
buildConsolidateKeyForPromotion: () => buildConsolidateKeyForPromotion,
|
|
34
|
+
calculateUnfulfilledPromotions: () => calculateUnfulfilledPromotions,
|
|
35
|
+
extractProductMatchIdentifiersFromStrategyConfig: () => extractProductMatchIdentifiersFromStrategyConfig,
|
|
36
|
+
getOrderProductBasePrice: () => getOrderProductBasePrice,
|
|
37
|
+
getOrderProductOriginalPriceForPromotion: () => getOrderProductOriginalPriceForPromotion,
|
|
38
|
+
getOrderProductUid: () => getOrderProductUid,
|
|
39
|
+
mergeIdenticalPromotionCartLines: () => mergeIdenticalPromotionCartLines,
|
|
40
|
+
processCartPromotion: () => processCartPromotion,
|
|
41
|
+
resolveStrategyEligibleProducts: () => resolveStrategyEligibleProducts,
|
|
42
|
+
resolveStrategyRequiredQuantity: () => resolveStrategyRequiredQuantity
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(cartPromotion_exports);
|
|
45
|
+
var import_decimal = __toESM(require("decimal.js"));
|
|
46
|
+
var import_lodash_es = require("lodash-es");
|
|
47
|
+
var import_utils = require("../../../modules/Order/utils");
|
|
48
|
+
var import_utils2 = require("../../ScanOrder/utils");
|
|
49
|
+
function getOrderProductBasePrice(product) {
|
|
50
|
+
const metadata = (product == null ? void 0 : product.metadata) || {};
|
|
51
|
+
const optionSum = (0, import_utils.sumOptionUnitPrice)((0, import_utils.getProductSkuOptions)(product)).toNumber();
|
|
52
|
+
if (metadata.source_product_price !== void 0) {
|
|
53
|
+
const v2 = Number(metadata.source_product_price);
|
|
54
|
+
return Number.isFinite(v2) ? v2 : 0;
|
|
55
|
+
}
|
|
56
|
+
if (metadata.main_product_original_price !== void 0) {
|
|
57
|
+
const v2 = Number(metadata.main_product_original_price) - optionSum;
|
|
58
|
+
return Number.isFinite(v2) ? v2 : 0;
|
|
59
|
+
}
|
|
60
|
+
const v = Number((product == null ? void 0 : product.original_price) ?? (product == null ? void 0 : product.selling_price) ?? 0);
|
|
61
|
+
return Number.isFinite(v) ? v : 0;
|
|
62
|
+
}
|
|
63
|
+
function getOrderProductOriginalPriceForPromotion(product) {
|
|
64
|
+
var _a;
|
|
65
|
+
const metadata = (product == null ? void 0 : product.metadata) || {};
|
|
66
|
+
const optionSum = (0, import_utils.sumOptionUnitPrice)((0, import_utils.getProductSkuOptions)(product)).toNumber();
|
|
67
|
+
if (metadata.main_product_original_price !== void 0 && metadata.main_product_original_price !== null && metadata.main_product_original_price !== "") {
|
|
68
|
+
const v = Number(metadata.main_product_original_price) - optionSum;
|
|
69
|
+
if (Number.isFinite(v) && v >= 0)
|
|
70
|
+
return v;
|
|
71
|
+
}
|
|
72
|
+
const promoOriginal = (_a = metadata._promotion) == null ? void 0 : _a.originalPrice;
|
|
73
|
+
if (promoOriginal !== void 0 && promoOriginal !== null && promoOriginal !== "") {
|
|
74
|
+
const v = Number(promoOriginal);
|
|
75
|
+
if (Number.isFinite(v) && v >= 0)
|
|
76
|
+
return v;
|
|
77
|
+
}
|
|
78
|
+
return getOrderProductBasePrice(product);
|
|
79
|
+
}
|
|
80
|
+
function updatePromotionDiscountList(item, promotionDiscount) {
|
|
81
|
+
let discountList = Array.isArray(item.discount_list) ? [...item.discount_list] : [];
|
|
82
|
+
discountList = discountList.filter((d) => (d == null ? void 0 : d.type) !== "promotion");
|
|
83
|
+
if (promotionDiscount) {
|
|
84
|
+
discountList.push({
|
|
85
|
+
type: "promotion",
|
|
86
|
+
amount: promotionDiscount.amount,
|
|
87
|
+
discount: {
|
|
88
|
+
original_amount: promotionDiscount.original_amount,
|
|
89
|
+
fixed_amount: promotionDiscount.fixed_amount,
|
|
90
|
+
title: promotionDiscount.title,
|
|
91
|
+
resource_id: ""
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
if (discountList.length > 0) {
|
|
96
|
+
item.discount_list = discountList;
|
|
97
|
+
} else {
|
|
98
|
+
delete item.discount_list;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
var X_ITEMS_FOR_Y_PRICE = "X_ITEMS_FOR_Y_PRICE";
|
|
102
|
+
function applyPromoUnitPriceToLine(item, input) {
|
|
103
|
+
const metadata = item.metadata || (item.metadata = {});
|
|
104
|
+
const optionSum = (0, import_utils.sumOptionUnitPrice)((0, import_utils.getProductSkuOptions)(item)).toNumber();
|
|
105
|
+
const promoUnitPrice = new import_decimal.default(Number(input.promoUnitPrice) || 0).toDecimalPlaces(2).toFixed(2);
|
|
106
|
+
const mainSelling = new import_decimal.default(Number(promoUnitPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
|
|
107
|
+
const catalogSource = new import_decimal.default(input.originalBasePrice).toDecimalPlaces(2).toFixed(2);
|
|
108
|
+
metadata.source_product_price = catalogSource;
|
|
109
|
+
metadata.main_product_original_price = new import_decimal.default(Number(catalogSource) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
|
|
110
|
+
metadata.main_product_selling_price = mainSelling;
|
|
111
|
+
metadata.price_schema_version = 2;
|
|
112
|
+
item.selling_price = (0, import_utils.composeLinePrice)({
|
|
113
|
+
mainPrice: mainSelling,
|
|
114
|
+
bundle: item.product_bundle
|
|
115
|
+
});
|
|
116
|
+
item.original_price = (0, import_utils.composeLinePrice)({
|
|
117
|
+
mainPrice: metadata.main_product_original_price,
|
|
118
|
+
bundle: item.product_bundle,
|
|
119
|
+
useOriginalBundle: true
|
|
120
|
+
});
|
|
121
|
+
const discountAmount = new import_decimal.default(input.originalBasePrice).minus(Number(promoUnitPrice) || 0).toDecimalPlaces(2).toFixed(2);
|
|
122
|
+
if (Number(catalogSource) !== Number(promoUnitPrice)) {
|
|
123
|
+
updatePromotionDiscountList(item, {
|
|
124
|
+
title: input.strategyTitle || "",
|
|
125
|
+
amount: discountAmount,
|
|
126
|
+
original_amount: catalogSource,
|
|
127
|
+
fixed_amount: discountAmount
|
|
128
|
+
});
|
|
129
|
+
} else {
|
|
130
|
+
updatePromotionDiscountList(item, null);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function getPromotionActionType(promotion) {
|
|
134
|
+
var _a, _b;
|
|
135
|
+
if (promotion == null ? void 0 : promotion.actionType)
|
|
136
|
+
return String(promotion.actionType);
|
|
137
|
+
const actions = (_a = promotion == null ? void 0 : promotion.strategyMetadata) == null ? void 0 : _a.actions;
|
|
138
|
+
if (Array.isArray(actions) && ((_b = actions[0]) == null ? void 0 : _b.type))
|
|
139
|
+
return String(actions[0].type);
|
|
140
|
+
return void 0;
|
|
141
|
+
}
|
|
142
|
+
function resolveXItemsExpectedUnitPrice(promotion, sourceCartNum) {
|
|
143
|
+
if (getPromotionActionType(promotion) !== X_ITEMS_FOR_Y_PRICE)
|
|
144
|
+
return void 0;
|
|
145
|
+
const detail = promotion == null ? void 0 : promotion.actionDetail;
|
|
146
|
+
const x = Number(detail == null ? void 0 : detail.x);
|
|
147
|
+
const y = Number(detail == null ? void 0 : detail.price);
|
|
148
|
+
if (!Number.isFinite(x) || x <= 0 || !Number.isFinite(y))
|
|
149
|
+
return void 0;
|
|
150
|
+
if (sourceCartNum < x)
|
|
151
|
+
return void 0;
|
|
152
|
+
return Number(new import_decimal.default(y).div(x).toDecimalPlaces(2).toFixed(2));
|
|
153
|
+
}
|
|
154
|
+
function mergeIdenticalPromotionCartLines(products) {
|
|
155
|
+
var _a, _b, _c, _d;
|
|
156
|
+
if (!Array.isArray(products) || products.length <= 1) {
|
|
157
|
+
return [...products || []];
|
|
158
|
+
}
|
|
159
|
+
const merged = [];
|
|
160
|
+
const indexByKey = /* @__PURE__ */ new Map();
|
|
161
|
+
for (const line of products) {
|
|
162
|
+
if (getGiftInfo(line)) {
|
|
163
|
+
merged.push(line);
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
const promotion = (_a = line == null ? void 0 : line.metadata) == null ? void 0 : _a._promotion;
|
|
167
|
+
if (!(promotion == null ? void 0 : promotion.inPromotion) || !promotion.strategyId) {
|
|
168
|
+
merged.push(line);
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
const fingerprint = (0, import_utils2.buildProductLineFingerprint)(
|
|
172
|
+
(0, import_utils.getProductSkuOptions)(line),
|
|
173
|
+
line.product_bundle
|
|
174
|
+
);
|
|
175
|
+
const unitPrice = String(
|
|
176
|
+
((_b = line.metadata) == null ? void 0 : _b.source_product_price) ?? line.selling_price ?? ""
|
|
177
|
+
);
|
|
178
|
+
const promoUnitPrice = String(
|
|
179
|
+
promotion.finalPrice ?? ((_c = line.metadata) == null ? void 0 : _c.main_product_selling_price) ?? ""
|
|
180
|
+
);
|
|
181
|
+
const noteSignature = getProductLineNoteSignature(line);
|
|
182
|
+
const bookingUid = (line == null ? void 0 : line.booking_uid) ?? ((_d = line == null ? void 0 : line.metadata) == null ? void 0 : _d.booking_uid);
|
|
183
|
+
const orderDetailId = (line == null ? void 0 : line.order_detail_id) ?? (line == null ? void 0 : line.orderDetailId);
|
|
184
|
+
const mergeKey = [
|
|
185
|
+
line.product_id,
|
|
186
|
+
line.product_variant_id ?? 0,
|
|
187
|
+
fingerprint,
|
|
188
|
+
noteSignature,
|
|
189
|
+
bookingUid ? String(bookingUid) : "",
|
|
190
|
+
orderDetailId !== void 0 && orderDetailId !== null && orderDetailId !== "" ? String(orderDetailId) : "",
|
|
191
|
+
promotion.strategyId,
|
|
192
|
+
unitPrice,
|
|
193
|
+
promoUnitPrice
|
|
194
|
+
].join("#");
|
|
195
|
+
const hitIndex = indexByKey.get(mergeKey);
|
|
196
|
+
if (hitIndex === void 0) {
|
|
197
|
+
indexByKey.set(mergeKey, merged.length);
|
|
198
|
+
merged.push(line);
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
const target = merged[hitIndex];
|
|
202
|
+
target.num = (0, import_utils2.getSafeProductNum)(Number(target.num || 0) + Number(line.num || 0));
|
|
203
|
+
}
|
|
204
|
+
return merged;
|
|
205
|
+
}
|
|
206
|
+
function dedupePromotionProcessedLines(lines) {
|
|
207
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
208
|
+
if (!Array.isArray(lines) || lines.length <= 1)
|
|
209
|
+
return [...lines || []];
|
|
210
|
+
const passthrough = [];
|
|
211
|
+
const buckets = /* @__PURE__ */ new Map();
|
|
212
|
+
for (const line of lines) {
|
|
213
|
+
const promo = (_a = line == null ? void 0 : line.metadata) == null ? void 0 : _a._promotion;
|
|
214
|
+
const originalUid = String(line._originalProductUid || getOrderProductUid(line) || "");
|
|
215
|
+
if (!(promo == null ? void 0 : promo.inPromotion) || !originalUid) {
|
|
216
|
+
passthrough.push(line);
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
const group = buckets.get(originalUid) || [];
|
|
220
|
+
group.push(line);
|
|
221
|
+
buckets.set(originalUid, group);
|
|
222
|
+
}
|
|
223
|
+
const promotionDelta = (line) => {
|
|
224
|
+
var _a2;
|
|
225
|
+
const promo = (_a2 = line.metadata) == null ? void 0 : _a2._promotion;
|
|
226
|
+
const original = Number(promo == null ? void 0 : promo.originalPrice);
|
|
227
|
+
const final = Number(promo == null ? void 0 : promo.finalPrice);
|
|
228
|
+
if (!Number.isFinite(original) || !Number.isFinite(final))
|
|
229
|
+
return 0;
|
|
230
|
+
return Math.abs(original - final);
|
|
231
|
+
};
|
|
232
|
+
const deduped = [...passthrough];
|
|
233
|
+
for (const [originalUid, group] of buckets) {
|
|
234
|
+
if (group.length === 1) {
|
|
235
|
+
deduped.push(group[0]);
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
const sourceCartNum = Math.max(
|
|
239
|
+
...group.map((line) => Number(line._sourceCartNum || line.num || 0))
|
|
240
|
+
);
|
|
241
|
+
const pricingLines = group.filter((line) => promotionDelta(line) > 0);
|
|
242
|
+
const xItemsLines = (pricingLines.length ? pricingLines : group).filter(
|
|
243
|
+
(line) => {
|
|
244
|
+
var _a2;
|
|
245
|
+
return getPromotionActionType((_a2 = line.metadata) == null ? void 0 : _a2._promotion) === X_ITEMS_FOR_Y_PRICE;
|
|
246
|
+
}
|
|
247
|
+
);
|
|
248
|
+
const pool = xItemsLines.length ? xItemsLines : pricingLines.length ? pricingLines : group;
|
|
249
|
+
let winner = pool[0];
|
|
250
|
+
const expectedUnit = resolveXItemsExpectedUnitPrice(
|
|
251
|
+
(_b = winner.metadata) == null ? void 0 : _b._promotion,
|
|
252
|
+
sourceCartNum
|
|
253
|
+
);
|
|
254
|
+
if (expectedUnit != null && pool.length > 1) {
|
|
255
|
+
winner = pool.reduce((best, line) => {
|
|
256
|
+
var _a2, _b2, _c2, _d2;
|
|
257
|
+
const bestDiff = Math.abs(Number((_b2 = (_a2 = best.metadata) == null ? void 0 : _a2._promotion) == null ? void 0 : _b2.finalPrice) - expectedUnit);
|
|
258
|
+
const lineDiff = Math.abs(Number((_d2 = (_c2 = line.metadata) == null ? void 0 : _c2._promotion) == null ? void 0 : _d2.finalPrice) - expectedUnit);
|
|
259
|
+
return lineDiff < bestDiff ? line : best;
|
|
260
|
+
}, pool[0]);
|
|
261
|
+
} else if (pool.length > 1 && !expectedUnit) {
|
|
262
|
+
winner = pool.reduce((best, line) => {
|
|
263
|
+
var _a2, _b2, _c2, _d2, _e2, _f2;
|
|
264
|
+
const bestFinal = Number((_b2 = (_a2 = best.metadata) == null ? void 0 : _a2._promotion) == null ? void 0 : _b2.finalPrice);
|
|
265
|
+
const lineFinal = Number((_d2 = (_c2 = line.metadata) == null ? void 0 : _c2._promotion) == null ? void 0 : _d2.finalPrice);
|
|
266
|
+
const original = Number((_f2 = (_e2 = line.metadata) == null ? void 0 : _e2._promotion) == null ? void 0 : _f2.originalPrice);
|
|
267
|
+
if (Number.isFinite(original) && lineFinal >= original && bestFinal >= original) {
|
|
268
|
+
return lineFinal < bestFinal ? line : best;
|
|
269
|
+
}
|
|
270
|
+
return promotionDelta(line) > promotionDelta(best) ? line : best;
|
|
271
|
+
}, pool[0]);
|
|
272
|
+
}
|
|
273
|
+
const winnerIsXItems = getPromotionActionType((_c = winner.metadata) == null ? void 0 : _c._promotion) === X_ITEMS_FOR_Y_PRICE;
|
|
274
|
+
if (winnerIsXItems) {
|
|
275
|
+
const xItemsGroupLines = group.filter(
|
|
276
|
+
(line) => {
|
|
277
|
+
var _a2;
|
|
278
|
+
return getPromotionActionType((_a2 = line.metadata) == null ? void 0 : _a2._promotion) === X_ITEMS_FOR_Y_PRICE;
|
|
279
|
+
}
|
|
280
|
+
);
|
|
281
|
+
const evaluatedPromoQty = xItemsGroupLines.reduce(
|
|
282
|
+
(sum, line) => sum + Number(line.num || 0),
|
|
283
|
+
0
|
|
284
|
+
);
|
|
285
|
+
winner.num = (0, import_utils2.getSafeProductNum)(evaluatedPromoQty || winner.num || 1);
|
|
286
|
+
} else {
|
|
287
|
+
winner.num = (0, import_utils2.getSafeProductNum)(sourceCartNum || winner.num || 1);
|
|
288
|
+
}
|
|
289
|
+
const recomputeUnit = resolveXItemsExpectedUnitPrice(
|
|
290
|
+
(_d = winner.metadata) == null ? void 0 : _d._promotion,
|
|
291
|
+
sourceCartNum
|
|
292
|
+
);
|
|
293
|
+
if (recomputeUnit != null) {
|
|
294
|
+
const promo = winner.metadata._promotion;
|
|
295
|
+
applyPromoUnitPriceToLine(winner, {
|
|
296
|
+
promoUnitPrice: recomputeUnit,
|
|
297
|
+
originalBasePrice: Number(promo.originalPrice),
|
|
298
|
+
strategyTitle: (_e = promo.strategyMetadata) == null ? void 0 : _e.name
|
|
299
|
+
});
|
|
300
|
+
promo.finalPrice = recomputeUnit;
|
|
301
|
+
}
|
|
302
|
+
for (const line of group) {
|
|
303
|
+
const giftInfo = (_g = (_f = line.metadata) == null ? void 0 : _f._promotion) == null ? void 0 : _g.giftInfo;
|
|
304
|
+
if (giftInfo && ((_h = winner.metadata) == null ? void 0 : _h._promotion) && !winner.metadata._promotion.giftInfo) {
|
|
305
|
+
winner.metadata._promotion.giftInfo = giftInfo;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
deduped.push(winner);
|
|
309
|
+
}
|
|
310
|
+
return deduped;
|
|
311
|
+
}
|
|
312
|
+
function getOrderProductUid(product) {
|
|
313
|
+
var _a;
|
|
314
|
+
return String(
|
|
315
|
+
((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.unique_identification_number) ?? (product == null ? void 0 : product.unique_identification_number) ?? ""
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
function getGiftInfo(product) {
|
|
319
|
+
var _a;
|
|
320
|
+
return ((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a._giftInfo) || (product == null ? void 0 : product._giftInfo) || null;
|
|
321
|
+
}
|
|
322
|
+
function getProductLineNoteSignature(product) {
|
|
323
|
+
const note = product == null ? void 0 : product.note;
|
|
324
|
+
if (typeof note !== "string")
|
|
325
|
+
return "";
|
|
326
|
+
const normalizedNote = note.trim();
|
|
327
|
+
if (!normalizedNote)
|
|
328
|
+
return "";
|
|
329
|
+
const uid = getOrderProductUid(product);
|
|
330
|
+
return uid ? `note:${uid}` : `note:${normalizedNote}`;
|
|
331
|
+
}
|
|
332
|
+
function isPersistedGeneratedVoucher(product) {
|
|
333
|
+
const orderDetailId = (product == null ? void 0 : product.order_detail_id) ?? (product == null ? void 0 : product.orderDetailId);
|
|
334
|
+
if (orderDetailId === void 0 || orderDetailId === null || orderDetailId === "") {
|
|
335
|
+
return false;
|
|
336
|
+
}
|
|
337
|
+
const metadata = (product == null ? void 0 : product.metadata) || {};
|
|
338
|
+
return (product == null ? void 0 : product.extension_type) === "product_voucher" || metadata.parent_order_detail_id !== void 0 || metadata.gift_card_type !== void 0;
|
|
339
|
+
}
|
|
340
|
+
function getProductBundleForEvaluator(product) {
|
|
341
|
+
const bundles = Array.isArray(product == null ? void 0 : product.product_bundle) ? product.product_bundle : [];
|
|
342
|
+
return bundles.map((b) => ({
|
|
343
|
+
product_id: (b == null ? void 0 : b.bundle_product_id) ?? (b == null ? void 0 : b._bundle_product_id) ?? (b == null ? void 0 : b.product_id),
|
|
344
|
+
product_variant_id: (b == null ? void 0 : b.bundle_variant_id) ?? (b == null ? void 0 : b.product_variant_id) ?? 0,
|
|
345
|
+
quantity: Number((b == null ? void 0 : b.num) ?? (b == null ? void 0 : b.quantity) ?? 1) || 1,
|
|
346
|
+
price: Number((b == null ? void 0 : b.bundle_selling_price) ?? (b == null ? void 0 : b.price) ?? 0) || 0,
|
|
347
|
+
original_price: Number((b == null ? void 0 : b.original_price) ?? (b == null ? void 0 : b.product_price) ?? (b == null ? void 0 : b.price) ?? 0) || 0,
|
|
348
|
+
id: (b == null ? void 0 : b.bundle_id) ?? (b == null ? void 0 : b.id) ?? 0,
|
|
349
|
+
_bundle_product_id: (b == null ? void 0 : b._bundle_product_id) ?? (b == null ? void 0 : b.bundle_product_id) ?? (b == null ? void 0 : b.product_id)
|
|
350
|
+
}));
|
|
351
|
+
}
|
|
352
|
+
function buildConsolidateKeyForPromotion(item) {
|
|
353
|
+
var _a;
|
|
354
|
+
const fingerprint = (0, import_utils2.buildProductLineFingerprint)(
|
|
355
|
+
(0, import_utils.getProductSkuOptions)(item),
|
|
356
|
+
item.product_bundle
|
|
357
|
+
);
|
|
358
|
+
const noteSignature = getProductLineNoteSignature(item);
|
|
359
|
+
const bookingUid = (item == null ? void 0 : item.booking_uid) ?? ((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.booking_uid);
|
|
360
|
+
const orderDetailId = (item == null ? void 0 : item.order_detail_id) ?? (item == null ? void 0 : item.orderDetailId);
|
|
361
|
+
if (orderDetailId !== void 0 && orderDetailId !== null && orderDetailId !== "") {
|
|
362
|
+
return [
|
|
363
|
+
item.product_id,
|
|
364
|
+
item.product_variant_id ?? 0,
|
|
365
|
+
fingerprint,
|
|
366
|
+
noteSignature,
|
|
367
|
+
String(orderDetailId)
|
|
368
|
+
].join("#");
|
|
369
|
+
}
|
|
370
|
+
if (bookingUid !== void 0 && bookingUid !== null && String(bookingUid) !== "") {
|
|
371
|
+
return [
|
|
372
|
+
item.product_id,
|
|
373
|
+
item.product_variant_id ?? 0,
|
|
374
|
+
fingerprint,
|
|
375
|
+
noteSignature,
|
|
376
|
+
String(bookingUid)
|
|
377
|
+
].join("#");
|
|
378
|
+
}
|
|
379
|
+
return [
|
|
380
|
+
item.product_id,
|
|
381
|
+
item.product_variant_id ?? 0,
|
|
382
|
+
fingerprint,
|
|
383
|
+
noteSignature
|
|
384
|
+
].join("#");
|
|
385
|
+
}
|
|
386
|
+
function consolidateMainProductsForPromotion(entries) {
|
|
387
|
+
var _a, _b;
|
|
388
|
+
if (!Array.isArray(entries) || entries.length <= 1) {
|
|
389
|
+
return [...entries || []];
|
|
390
|
+
}
|
|
391
|
+
const groups = /* @__PURE__ */ new Map();
|
|
392
|
+
for (const { item, originalListIndex } of entries) {
|
|
393
|
+
const key = buildConsolidateKeyForPromotion(item);
|
|
394
|
+
const wasInPromotion = ((_b = (_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a._promotion) == null ? void 0 : _b.inPromotion) === true;
|
|
395
|
+
const existing = groups.get(key);
|
|
396
|
+
if (!existing) {
|
|
397
|
+
const mergedItem = (0, import_lodash_es.cloneDeep)(item);
|
|
398
|
+
const metadata = mergedItem.metadata || {};
|
|
399
|
+
delete metadata._promotion;
|
|
400
|
+
mergedItem.metadata = metadata;
|
|
401
|
+
if (Array.isArray(mergedItem.product_bundle)) {
|
|
402
|
+
for (const bundle of mergedItem.product_bundle) {
|
|
403
|
+
if (bundle && typeof bundle === "object")
|
|
404
|
+
delete bundle._promotion;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
if (wasInPromotion) {
|
|
408
|
+
mergedItem._wasInPromotionBeforeConsolidate = true;
|
|
409
|
+
}
|
|
410
|
+
groups.set(key, { item: mergedItem, originalListIndex });
|
|
411
|
+
continue;
|
|
412
|
+
}
|
|
413
|
+
existing.item.num = (0, import_utils2.getSafeProductNum)(
|
|
414
|
+
Number(existing.item.num || 0) + Number(item.num || 0)
|
|
415
|
+
);
|
|
416
|
+
if (wasInPromotion) {
|
|
417
|
+
existing.item._wasInPromotionBeforeConsolidate = true;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
return Array.from(groups.values());
|
|
421
|
+
}
|
|
422
|
+
function splitXItemsPromoLinesByGroup(lines, strategyActionMap) {
|
|
423
|
+
var _a;
|
|
424
|
+
const result = [];
|
|
425
|
+
for (const line of lines) {
|
|
426
|
+
const promo = (_a = line == null ? void 0 : line.metadata) == null ? void 0 : _a._promotion;
|
|
427
|
+
if (!(promo == null ? void 0 : promo.inPromotion) || !promo.strategyId) {
|
|
428
|
+
result.push(line);
|
|
429
|
+
continue;
|
|
430
|
+
}
|
|
431
|
+
if (getPromotionActionType(promo) !== X_ITEMS_FOR_Y_PRICE) {
|
|
432
|
+
result.push(line);
|
|
433
|
+
continue;
|
|
434
|
+
}
|
|
435
|
+
const actionMeta = strategyActionMap.get(promo.strategyId);
|
|
436
|
+
const detail = (actionMeta == null ? void 0 : actionMeta.actionDetail) ?? promo.actionDetail;
|
|
437
|
+
const x = Number(detail == null ? void 0 : detail.x);
|
|
438
|
+
const num = Number(line.num || 0);
|
|
439
|
+
const isCumulative = (detail == null ? void 0 : detail.cumulative) !== false;
|
|
440
|
+
if (!isCumulative || !Number.isFinite(x) || x <= 0 || num <= x || num % x !== 0) {
|
|
441
|
+
result.push(line);
|
|
442
|
+
continue;
|
|
443
|
+
}
|
|
444
|
+
const groupCount = num / x;
|
|
445
|
+
for (let i = 0; i < groupCount; i++) {
|
|
446
|
+
const splitLine = (0, import_lodash_es.cloneDeep)(line);
|
|
447
|
+
splitLine.num = (0, import_utils2.getSafeProductNum)(x);
|
|
448
|
+
splitLine.metadata = {
|
|
449
|
+
...splitLine.metadata || {},
|
|
450
|
+
unique_identification_number: (0, import_utils.createUuidV4)()
|
|
451
|
+
};
|
|
452
|
+
result.push(splitLine);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
return result;
|
|
456
|
+
}
|
|
457
|
+
function generateNumericId() {
|
|
458
|
+
return Math.floor(Math.random() * 1e9) + Date.now();
|
|
459
|
+
}
|
|
460
|
+
function convertToPromotionProduct(product, index) {
|
|
461
|
+
const metadata = (product == null ? void 0 : product.metadata) || {};
|
|
462
|
+
const numericId = generateNumericId();
|
|
463
|
+
const originalItem = product;
|
|
464
|
+
return {
|
|
465
|
+
id: numericId,
|
|
466
|
+
product_id: Number((product == null ? void 0 : product.product_id) ?? 0) || 0,
|
|
467
|
+
product_variant_id: Number((product == null ? void 0 : product.product_variant_id) ?? 0) || 0,
|
|
468
|
+
name: metadata.product_name || (product == null ? void 0 : product.title) || "",
|
|
469
|
+
price: getOrderProductOriginalPriceForPromotion(product),
|
|
470
|
+
quantity: Number((product == null ? void 0 : product.num) ?? 1) || 1,
|
|
471
|
+
bundle: getProductBundleForEvaluator(product),
|
|
472
|
+
_originalItem: originalItem,
|
|
473
|
+
_originalId: getOrderProductUid(product),
|
|
474
|
+
_originalIndex: index
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
function calculateGiftActions(gifts, existingGifts) {
|
|
478
|
+
var _a, _b, _c;
|
|
479
|
+
const toAdd = [];
|
|
480
|
+
const toReduce = [];
|
|
481
|
+
const toRemove = [];
|
|
482
|
+
const existingByStrategy = /* @__PURE__ */ new Map();
|
|
483
|
+
for (const gift of existingGifts) {
|
|
484
|
+
const strategyId = (_a = getGiftInfo(gift)) == null ? void 0 : _a.strategyId;
|
|
485
|
+
if (!strategyId)
|
|
486
|
+
continue;
|
|
487
|
+
const existing = existingByStrategy.get(strategyId);
|
|
488
|
+
const qty = Number((gift == null ? void 0 : gift.num) ?? 1) || 1;
|
|
489
|
+
if (existing) {
|
|
490
|
+
existing.items.push(gift);
|
|
491
|
+
existing.totalQuantity += qty;
|
|
492
|
+
} else {
|
|
493
|
+
existingByStrategy.set(strategyId, { items: [gift], totalQuantity: qty });
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
const processedStrategyIds = /* @__PURE__ */ new Set();
|
|
497
|
+
for (const giftInfo of gifts) {
|
|
498
|
+
const { strategyId, strategyName, giftCount, giftOptions, sourceProductIds } = giftInfo;
|
|
499
|
+
processedStrategyIds.add(strategyId);
|
|
500
|
+
const existing = existingByStrategy.get(strategyId);
|
|
501
|
+
const existingCount = (existing == null ? void 0 : existing.totalQuantity) ?? 0;
|
|
502
|
+
const diff = giftCount - existingCount;
|
|
503
|
+
if (diff > 0) {
|
|
504
|
+
const lastEvaluated = (_c = getGiftInfo((_b = existing == null ? void 0 : existing.items) == null ? void 0 : _b[0])) == null ? void 0 : _c.lastEvaluatedGiftCount;
|
|
505
|
+
const strategyChanged = lastEvaluated === void 0 || giftCount !== lastEvaluated;
|
|
506
|
+
if (strategyChanged) {
|
|
507
|
+
toAdd.push({
|
|
508
|
+
strategyId,
|
|
509
|
+
strategyName,
|
|
510
|
+
giftCount: diff,
|
|
511
|
+
giftOptions,
|
|
512
|
+
sourceProductIds
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
} else if (diff < 0) {
|
|
516
|
+
let remaining = Math.abs(diff);
|
|
517
|
+
const reduceItems = [];
|
|
518
|
+
const removeIds = [];
|
|
519
|
+
const reversed = [...(existing == null ? void 0 : existing.items) || []].reverse();
|
|
520
|
+
for (const giftItem of reversed) {
|
|
521
|
+
if (remaining <= 0)
|
|
522
|
+
break;
|
|
523
|
+
const uid = getOrderProductUid(giftItem);
|
|
524
|
+
const qty = Number((giftItem == null ? void 0 : giftItem.num) ?? 1) || 1;
|
|
525
|
+
if (qty <= remaining) {
|
|
526
|
+
removeIds.push(uid);
|
|
527
|
+
remaining -= qty;
|
|
528
|
+
} else {
|
|
529
|
+
reduceItems.push({ uid, currentQuantity: qty, newQuantity: qty - remaining });
|
|
530
|
+
remaining = 0;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
if (reduceItems.length > 0)
|
|
534
|
+
toReduce.push({ strategyId, items: reduceItems });
|
|
535
|
+
toRemove.push(...removeIds);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
for (const [strategyId, existing] of existingByStrategy) {
|
|
539
|
+
if (processedStrategyIds.has(strategyId))
|
|
540
|
+
continue;
|
|
541
|
+
for (const giftItem of existing.items) {
|
|
542
|
+
toRemove.push(getOrderProductUid(giftItem));
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
return { toAdd, toReduce, toRemove };
|
|
546
|
+
}
|
|
547
|
+
function extractProductMatchIdentifiersFromStrategyConfig(strategyConfig) {
|
|
548
|
+
var _a;
|
|
549
|
+
const rules = (_a = strategyConfig == null ? void 0 : strategyConfig.conditions) == null ? void 0 : _a.rules;
|
|
550
|
+
if (!Array.isArray(rules))
|
|
551
|
+
return [];
|
|
552
|
+
for (const rule of rules) {
|
|
553
|
+
if ((rule == null ? void 0 : rule.field) === "productIdAndVariantId" && ((rule == null ? void 0 : rule.operator) === "product_match" || (rule == null ? void 0 : rule.operator) === "object_in") && Array.isArray(rule == null ? void 0 : rule.value)) {
|
|
554
|
+
return rule.value.map((item) => ({
|
|
555
|
+
product_id: Number(item == null ? void 0 : item.product_id) || 0,
|
|
556
|
+
product_variant_id: Number(item == null ? void 0 : item.product_variant_id) || 0
|
|
557
|
+
})).filter((item) => item.product_id > 0);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
return [];
|
|
561
|
+
}
|
|
562
|
+
function resolveStrategyRequiredQuantity(matched) {
|
|
563
|
+
const preset = Number(matched.requiredQuantity);
|
|
564
|
+
if (Number.isFinite(preset) && preset > 0)
|
|
565
|
+
return preset;
|
|
566
|
+
const detail = matched.actionDetail || {};
|
|
567
|
+
if (matched.actionType === "X_ITEMS_FOR_Y_PRICE") {
|
|
568
|
+
return Number(detail.x) || 2;
|
|
569
|
+
}
|
|
570
|
+
if (matched.actionType === "BUY_X_GET_Y_FREE") {
|
|
571
|
+
return Number(detail.buyQuantity) || 1;
|
|
572
|
+
}
|
|
573
|
+
return 1;
|
|
574
|
+
}
|
|
575
|
+
function resolveStrategyEligibleProducts(matched) {
|
|
576
|
+
if (Array.isArray(matched.eligibleProducts) && matched.eligibleProducts.length > 0) {
|
|
577
|
+
return matched.eligibleProducts;
|
|
578
|
+
}
|
|
579
|
+
return extractProductMatchIdentifiersFromStrategyConfig(matched.strategyConfig);
|
|
580
|
+
}
|
|
581
|
+
function calculateUnfulfilledPromotions(processedProducts, applicableStrategiesResult, mainProducts) {
|
|
582
|
+
var _a, _b;
|
|
583
|
+
const unfulfilledMap = /* @__PURE__ */ new Map();
|
|
584
|
+
for (let i = 0; i < processedProducts.length; i++) {
|
|
585
|
+
const product = processedProducts[i];
|
|
586
|
+
const promotion = (_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a._promotion;
|
|
587
|
+
if (!promotion || promotion.inPromotion !== false)
|
|
588
|
+
continue;
|
|
589
|
+
const strategyId = promotion.strategyId;
|
|
590
|
+
if (!strategyId)
|
|
591
|
+
continue;
|
|
592
|
+
const lookupUid = String(
|
|
593
|
+
(product == null ? void 0 : product._originalProductUid) ?? ((_b = product == null ? void 0 : product.metadata) == null ? void 0 : _b.unique_identification_number) ?? ""
|
|
594
|
+
);
|
|
595
|
+
const originalIndex = mainProducts.findIndex(
|
|
596
|
+
(item) => getOrderProductUid(item) === lookupUid
|
|
597
|
+
);
|
|
598
|
+
if (originalIndex === -1)
|
|
599
|
+
continue;
|
|
600
|
+
const strategyData = applicableStrategiesResult[originalIndex];
|
|
601
|
+
if (!strategyData || !strategyData.hasApplicableStrategy)
|
|
602
|
+
continue;
|
|
603
|
+
const matched = strategyData.applicableStrategies.find(
|
|
604
|
+
(s) => s.strategyId === strategyId
|
|
605
|
+
);
|
|
606
|
+
if (!matched)
|
|
607
|
+
continue;
|
|
608
|
+
const quantity = Number((product == null ? void 0 : product.num) ?? 1) || 1;
|
|
609
|
+
if (unfulfilledMap.has(strategyId)) {
|
|
610
|
+
unfulfilledMap.get(strategyId).currentQuantity += quantity;
|
|
611
|
+
} else {
|
|
612
|
+
unfulfilledMap.set(strategyId, {
|
|
613
|
+
strategyId,
|
|
614
|
+
strategyName: matched.strategyName,
|
|
615
|
+
actionType: matched.actionType,
|
|
616
|
+
currentQuantity: quantity,
|
|
617
|
+
requiredQuantity: resolveStrategyRequiredQuantity(matched),
|
|
618
|
+
needQuantity: 0,
|
|
619
|
+
eligibleProducts: resolveStrategyEligibleProducts(matched),
|
|
620
|
+
strategyMetadata: matched.strategyMetadata,
|
|
621
|
+
display: matched.display
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
const result = [];
|
|
626
|
+
for (const data of unfulfilledMap.values()) {
|
|
627
|
+
const needQuantity = data.requiredQuantity - data.currentQuantity;
|
|
628
|
+
if (needQuantity > 0) {
|
|
629
|
+
result.push({ ...data, needQuantity });
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
return result;
|
|
633
|
+
}
|
|
634
|
+
function appendPromotionTags(products, evaluator) {
|
|
635
|
+
if (!Array.isArray(products) || products.length === 0 || !evaluator) {
|
|
636
|
+
return products || [];
|
|
637
|
+
}
|
|
638
|
+
const evaluatorInput = products.map((item, index) => ({
|
|
639
|
+
id: index,
|
|
640
|
+
product_id: Number((item == null ? void 0 : item.id) ?? (item == null ? void 0 : item.product_id) ?? 0) || 0,
|
|
641
|
+
product_variant_id: Number((item == null ? void 0 : item.product_variant_id) ?? 0) || 0,
|
|
642
|
+
name: (item == null ? void 0 : item.title) || (item == null ? void 0 : item.name) || "",
|
|
643
|
+
price: Number((item == null ? void 0 : item.price) ?? 0) || 0,
|
|
644
|
+
quantity: Number((item == null ? void 0 : item.quantity) ?? 1) || 1,
|
|
645
|
+
bundle: []
|
|
646
|
+
}));
|
|
647
|
+
const strategies = evaluator.getProductsApplicableStrategies(
|
|
648
|
+
{ products: evaluatorInput },
|
|
649
|
+
false
|
|
650
|
+
);
|
|
651
|
+
return products.map((item, index) => {
|
|
652
|
+
const data = strategies[index];
|
|
653
|
+
const tags = [];
|
|
654
|
+
if (data == null ? void 0 : data.hasApplicableStrategy) {
|
|
655
|
+
for (const strategy of data.applicableStrategies) {
|
|
656
|
+
if (strategy.display) {
|
|
657
|
+
tags.push({
|
|
658
|
+
text: strategy.display.text,
|
|
659
|
+
type: strategy.display.type,
|
|
660
|
+
strategyId: strategy.strategyId
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
if (tags.length === 0) {
|
|
666
|
+
const { _promotionTags, ...rest } = item;
|
|
667
|
+
return rest;
|
|
668
|
+
}
|
|
669
|
+
return { ...item, _promotionTags: tags };
|
|
670
|
+
});
|
|
671
|
+
}
|
|
672
|
+
function processCartPromotion(list, evaluator, options) {
|
|
673
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
674
|
+
const empty = {
|
|
675
|
+
products: Array.isArray(list) ? [...list] : [],
|
|
676
|
+
totalDiscount: 0,
|
|
677
|
+
gifts: [],
|
|
678
|
+
giftActions: { toAdd: [], toReduce: [], toRemove: [] },
|
|
679
|
+
unfulfilledPromotions: []
|
|
680
|
+
};
|
|
681
|
+
if (!list || list.length === 0 || !evaluator)
|
|
682
|
+
return empty;
|
|
683
|
+
const mainProductsWithIndex = [];
|
|
684
|
+
const existingGiftsWithIndex = [];
|
|
685
|
+
const editProductsWithIndex = [];
|
|
686
|
+
for (let i = 0; i < list.length; i++) {
|
|
687
|
+
const item = list[i];
|
|
688
|
+
const giftInfo = getGiftInfo(item);
|
|
689
|
+
if (isPersistedGeneratedVoucher(item)) {
|
|
690
|
+
editProductsWithIndex.push({ item, originalListIndex: i });
|
|
691
|
+
} else if (giftInfo) {
|
|
692
|
+
existingGiftsWithIndex.push({ item, originalListIndex: i });
|
|
693
|
+
} else if ((item == null ? void 0 : item.booking_id) !== void 0 && (item == null ? void 0 : item.booking_id) !== null && item.booking_id !== 0 && item.booking_id !== "0") {
|
|
694
|
+
editProductsWithIndex.push({ item, originalListIndex: i });
|
|
695
|
+
} else {
|
|
696
|
+
mainProductsWithIndex.push({ item, originalListIndex: i });
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
const consolidatedMainProductsWithIndex = consolidateMainProductsForPromotion(
|
|
700
|
+
mainProductsWithIndex
|
|
701
|
+
);
|
|
702
|
+
const mainProducts = consolidatedMainProductsWithIndex.map((x) => x.item);
|
|
703
|
+
const existingGifts = existingGiftsWithIndex.map((x) => x.item);
|
|
704
|
+
if (mainProducts.length === 0) {
|
|
705
|
+
const editProducts = editProductsWithIndex.map((x) => x.item);
|
|
706
|
+
if (existingGifts.length > 0) {
|
|
707
|
+
const toRemove = [];
|
|
708
|
+
for (const gift of existingGifts) {
|
|
709
|
+
const uid = getOrderProductUid(gift);
|
|
710
|
+
if (uid)
|
|
711
|
+
toRemove.push(uid);
|
|
712
|
+
}
|
|
713
|
+
return {
|
|
714
|
+
products: editProducts,
|
|
715
|
+
totalDiscount: 0,
|
|
716
|
+
gifts: [],
|
|
717
|
+
giftActions: { toAdd: [], toReduce: [], toRemove },
|
|
718
|
+
unfulfilledPromotions: []
|
|
719
|
+
};
|
|
720
|
+
}
|
|
721
|
+
return {
|
|
722
|
+
...empty,
|
|
723
|
+
products: editProducts.length > 0 ? editProducts : [...list]
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
const promotionProducts = [];
|
|
727
|
+
const originalItemMap = /* @__PURE__ */ new Map();
|
|
728
|
+
const productsForStrategies = consolidatedMainProductsWithIndex.map(({ item }, i) => {
|
|
729
|
+
var _a2;
|
|
730
|
+
return {
|
|
731
|
+
id: i,
|
|
732
|
+
product_id: Number((item == null ? void 0 : item.product_id) ?? 0) || 0,
|
|
733
|
+
product_variant_id: Number((item == null ? void 0 : item.product_variant_id) ?? 0) || 0,
|
|
734
|
+
name: ((_a2 = item == null ? void 0 : item.metadata) == null ? void 0 : _a2.product_name) || (item == null ? void 0 : item.title) || "",
|
|
735
|
+
price: getOrderProductBasePrice(item),
|
|
736
|
+
quantity: Number((item == null ? void 0 : item.num) ?? 1) || 1,
|
|
737
|
+
bundle: getProductBundleForEvaluator(item)
|
|
738
|
+
};
|
|
739
|
+
});
|
|
740
|
+
for (let i = 0; i < consolidatedMainProductsWithIndex.length; i++) {
|
|
741
|
+
const { item, originalListIndex } = consolidatedMainProductsWithIndex[i];
|
|
742
|
+
const promotionProduct = convertToPromotionProduct(item, originalListIndex);
|
|
743
|
+
promotionProducts.push(promotionProduct);
|
|
744
|
+
originalItemMap.set(promotionProduct.id, { item, index: originalListIndex });
|
|
745
|
+
}
|
|
746
|
+
const applicableStrategiesResult = evaluator.getProductsApplicableStrategies({
|
|
747
|
+
products: productsForStrategies,
|
|
748
|
+
channel: options == null ? void 0 : options.channel
|
|
749
|
+
});
|
|
750
|
+
const strategyActionMap = /* @__PURE__ */ new Map();
|
|
751
|
+
for (const row of applicableStrategiesResult || []) {
|
|
752
|
+
for (const strategy of (row == null ? void 0 : row.applicableStrategies) || []) {
|
|
753
|
+
if (!(strategy == null ? void 0 : strategy.strategyId))
|
|
754
|
+
continue;
|
|
755
|
+
strategyActionMap.set(strategy.strategyId, {
|
|
756
|
+
actionType: strategy.actionType,
|
|
757
|
+
actionDetail: strategy.actionDetail
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
const result = evaluator.evaluateCartWithPricing({
|
|
762
|
+
products: promotionProducts,
|
|
763
|
+
channel: options == null ? void 0 : options.channel
|
|
764
|
+
});
|
|
765
|
+
const strategySourceProductIds = /* @__PURE__ */ new Map();
|
|
766
|
+
for (const priced of result.products) {
|
|
767
|
+
if (priced.inPromotion && priced.strategyId) {
|
|
768
|
+
const sourceId = priced.originalId ?? priced.id;
|
|
769
|
+
const originalData = originalItemMap.get(sourceId);
|
|
770
|
+
if (originalData) {
|
|
771
|
+
const uid = getOrderProductUid(originalData.item);
|
|
772
|
+
if (!uid)
|
|
773
|
+
continue;
|
|
774
|
+
const arr = strategySourceProductIds.get(priced.strategyId) || [];
|
|
775
|
+
if (!arr.includes(uid))
|
|
776
|
+
arr.push(uid);
|
|
777
|
+
strategySourceProductIds.set(priced.strategyId, arr);
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
const extendedGifts = result.gifts.map((gift) => ({
|
|
782
|
+
...gift,
|
|
783
|
+
sourceProductIds: strategySourceProductIds.get(gift.strategyId) || []
|
|
784
|
+
}));
|
|
785
|
+
const strategyGiftInfoMap = /* @__PURE__ */ new Map();
|
|
786
|
+
for (const gift of extendedGifts)
|
|
787
|
+
strategyGiftInfoMap.set(gift.strategyId, gift);
|
|
788
|
+
const strategyGiftInfoOwner = /* @__PURE__ */ new Map();
|
|
789
|
+
const processedProducts = [];
|
|
790
|
+
for (const priced of result.products) {
|
|
791
|
+
const rawSourceId = priced.originalId ?? priced.id;
|
|
792
|
+
const sourceId = Number(rawSourceId);
|
|
793
|
+
const originalData = Number.isFinite(sourceId) ? originalItemMap.get(sourceId) : void 0;
|
|
794
|
+
if (!originalData)
|
|
795
|
+
continue;
|
|
796
|
+
const { item: originalItem, index: originalIndex } = originalData;
|
|
797
|
+
const pricedProductId = Number(priced.product_id ?? 0);
|
|
798
|
+
const originalProductId = Number(originalItem.product_id ?? 0);
|
|
799
|
+
if (pricedProductId > 0 && originalProductId > 0 && pricedProductId !== originalProductId) {
|
|
800
|
+
continue;
|
|
801
|
+
}
|
|
802
|
+
const newItem = (0, import_lodash_es.cloneDeep)(originalItem);
|
|
803
|
+
const metadata = newItem.metadata || {};
|
|
804
|
+
const sourceCartNum = (0, import_utils2.getSafeProductNum)(originalItem.num);
|
|
805
|
+
newItem._sourceCartNum = sourceCartNum;
|
|
806
|
+
const wasInPromotion = ((_a = metadata._promotion) == null ? void 0 : _a.inPromotion) === true || originalItem._wasInPromotionBeforeConsolidate === true;
|
|
807
|
+
delete metadata._promotion;
|
|
808
|
+
if (Array.isArray(newItem.product_bundle)) {
|
|
809
|
+
for (const b of newItem.product_bundle) {
|
|
810
|
+
if (b && typeof b === "object")
|
|
811
|
+
delete b._promotion;
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
const originalBasePrice = getOrderProductOriginalPriceForPromotion(originalItem);
|
|
815
|
+
const shouldModifyPrice = priced.inPromotion || wasInPromotion;
|
|
816
|
+
const priceUnchangedPromo = priced.inPromotion && Number(priced.finalPrice) === Number(originalBasePrice);
|
|
817
|
+
if (shouldModifyPrice) {
|
|
818
|
+
if (priced.inPromotion && !priceUnchangedPromo) {
|
|
819
|
+
const promoUnitPrice = new import_decimal.default(priced.finalPrice).toDecimalPlaces(2).toFixed(2);
|
|
820
|
+
applyPromoUnitPriceToLine(newItem, {
|
|
821
|
+
promoUnitPrice,
|
|
822
|
+
originalBasePrice,
|
|
823
|
+
strategyTitle: (_b = priced.strategyMetadata) == null ? void 0 : _b.name
|
|
824
|
+
});
|
|
825
|
+
} else {
|
|
826
|
+
const optionSum = (0, import_utils.sumOptionUnitPrice)((0, import_utils.getProductSkuOptions)(newItem)).toNumber();
|
|
827
|
+
const sourceRestore = new import_decimal.default(originalBasePrice).toDecimalPlaces(2).toFixed(2);
|
|
828
|
+
const mainRestore = new import_decimal.default(Number(sourceRestore) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
|
|
829
|
+
metadata.source_product_price = sourceRestore;
|
|
830
|
+
metadata.main_product_selling_price = mainRestore;
|
|
831
|
+
metadata.price_schema_version = 2;
|
|
832
|
+
newItem.selling_price = (0, import_utils.composeLinePrice)({
|
|
833
|
+
mainPrice: mainRestore,
|
|
834
|
+
bundle: newItem.product_bundle
|
|
835
|
+
});
|
|
836
|
+
updatePromotionDiscountList(newItem, null);
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
newItem.num = priced.isSplit ? (0, import_utils2.getSafeProductNum)(priced.quantity) : sourceCartNum;
|
|
840
|
+
if (priced.isSplit) {
|
|
841
|
+
metadata.unique_identification_number = (0, import_utils.createUuidV4)();
|
|
842
|
+
}
|
|
843
|
+
if (priced.strategyId) {
|
|
844
|
+
const actionMeta = strategyActionMap.get(priced.strategyId);
|
|
845
|
+
const promotionInfo = {
|
|
846
|
+
strategyId: priced.strategyId,
|
|
847
|
+
strategyMetadata: priced.strategyMetadata,
|
|
848
|
+
inPromotion: priced.inPromotion,
|
|
849
|
+
originalPrice: originalBasePrice,
|
|
850
|
+
finalPrice: priced.finalPrice,
|
|
851
|
+
actionType: actionMeta == null ? void 0 : actionMeta.actionType,
|
|
852
|
+
actionDetail: actionMeta == null ? void 0 : actionMeta.actionDetail
|
|
853
|
+
};
|
|
854
|
+
const bundleIdx = priced.matchedBundleIndex;
|
|
855
|
+
if (bundleIdx !== void 0 && Array.isArray(newItem.product_bundle) && newItem.product_bundle[bundleIdx]) {
|
|
856
|
+
newItem.product_bundle[bundleIdx]._promotion = promotionInfo;
|
|
857
|
+
} else {
|
|
858
|
+
metadata._promotion = promotionInfo;
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
newItem.metadata = metadata;
|
|
862
|
+
if (priced.inPromotion && priced.strategyId) {
|
|
863
|
+
const gift = strategyGiftInfoMap.get(priced.strategyId);
|
|
864
|
+
if (gift && Array.isArray(gift.giftOptions) && gift.giftOptions.length > 0 && !strategyGiftInfoOwner.has(priced.strategyId)) {
|
|
865
|
+
const giftInfoData = {
|
|
866
|
+
strategyName: gift.strategyName,
|
|
867
|
+
giftCount: gift.giftCount,
|
|
868
|
+
giftOptions: gift.giftOptions
|
|
869
|
+
};
|
|
870
|
+
const bundleIdx = priced.matchedBundleIndex;
|
|
871
|
+
if (bundleIdx !== void 0 && Array.isArray(newItem.product_bundle) && ((_c = newItem.product_bundle[bundleIdx]) == null ? void 0 : _c._promotion)) {
|
|
872
|
+
newItem.product_bundle[bundleIdx]._promotion.giftInfo = giftInfoData;
|
|
873
|
+
} else if (metadata._promotion) {
|
|
874
|
+
metadata._promotion.giftInfo = giftInfoData;
|
|
875
|
+
}
|
|
876
|
+
strategyGiftInfoOwner.set(
|
|
877
|
+
priced.strategyId,
|
|
878
|
+
getOrderProductUid(newItem)
|
|
879
|
+
);
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
newItem._sortIndex = originalIndex;
|
|
883
|
+
newItem._sortSubIndex = priced.inPromotion ? 0 : 1;
|
|
884
|
+
newItem._originalProductUid = getOrderProductUid(originalItem);
|
|
885
|
+
processedProducts.push(newItem);
|
|
886
|
+
}
|
|
887
|
+
for (const { item, originalListIndex } of existingGiftsWithIndex) {
|
|
888
|
+
const next = item;
|
|
889
|
+
next._sortIndex = originalListIndex;
|
|
890
|
+
next._sortSubIndex = 0;
|
|
891
|
+
const strategyId = (_d = getGiftInfo(next)) == null ? void 0 : _d.strategyId;
|
|
892
|
+
if (strategyId) {
|
|
893
|
+
const latest = strategyGiftInfoMap.get(strategyId);
|
|
894
|
+
const owner = strategyGiftInfoOwner.get(strategyId);
|
|
895
|
+
if (latest && ((_e = next.metadata) == null ? void 0 : _e._giftInfo)) {
|
|
896
|
+
next.metadata._giftInfo.sourceProductIds = latest.sourceProductIds;
|
|
897
|
+
}
|
|
898
|
+
if (owner && ((_f = next.metadata) == null ? void 0 : _f._giftInfo)) {
|
|
899
|
+
next.metadata._giftInfo.sourceProductId = owner;
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
processedProducts.push(next);
|
|
903
|
+
}
|
|
904
|
+
for (const { item, originalListIndex } of editProductsWithIndex) {
|
|
905
|
+
const next = item;
|
|
906
|
+
next._sortIndex = originalListIndex;
|
|
907
|
+
next._sortSubIndex = 0;
|
|
908
|
+
processedProducts.push(next);
|
|
909
|
+
}
|
|
910
|
+
processedProducts.sort((a, b) => {
|
|
911
|
+
if (a._sortIndex !== b._sortIndex)
|
|
912
|
+
return a._sortIndex - b._sortIndex;
|
|
913
|
+
return a._sortSubIndex - b._sortSubIndex;
|
|
914
|
+
});
|
|
915
|
+
const dedupedPromotionLines = dedupePromotionProcessedLines(processedProducts);
|
|
916
|
+
processedProducts.splice(0, processedProducts.length, ...dedupedPromotionLines);
|
|
917
|
+
const mergedPromotionLines = mergeIdenticalPromotionCartLines(processedProducts);
|
|
918
|
+
processedProducts.splice(0, processedProducts.length, ...mergedPromotionLines);
|
|
919
|
+
const splitPromoLines = splitXItemsPromoLinesByGroup(processedProducts, strategyActionMap);
|
|
920
|
+
processedProducts.splice(0, processedProducts.length, ...splitPromoLines);
|
|
921
|
+
for (const product of processedProducts) {
|
|
922
|
+
const metadata = product.metadata || {};
|
|
923
|
+
if (metadata._promotion)
|
|
924
|
+
continue;
|
|
925
|
+
if (getGiftInfo(product))
|
|
926
|
+
continue;
|
|
927
|
+
const lookupUid = String(product._originalProductUid ?? getOrderProductUid(product));
|
|
928
|
+
const originalIndex = mainProducts.findIndex(
|
|
929
|
+
(item) => getOrderProductUid(item) === lookupUid
|
|
930
|
+
);
|
|
931
|
+
if (originalIndex === -1)
|
|
932
|
+
continue;
|
|
933
|
+
const strategyData = applicableStrategiesResult[originalIndex];
|
|
934
|
+
if (!strategyData || !strategyData.hasApplicableStrategy)
|
|
935
|
+
continue;
|
|
936
|
+
const first = strategyData.applicableStrategies[0];
|
|
937
|
+
if (!first)
|
|
938
|
+
continue;
|
|
939
|
+
const originalPrice = getOrderProductOriginalPriceForPromotion(mainProducts[originalIndex]);
|
|
940
|
+
metadata._promotion = {
|
|
941
|
+
strategyId: first.strategyId,
|
|
942
|
+
strategyMetadata: first.strategyMetadata,
|
|
943
|
+
inPromotion: false,
|
|
944
|
+
originalPrice,
|
|
945
|
+
finalPrice: originalPrice
|
|
946
|
+
};
|
|
947
|
+
product.metadata = metadata;
|
|
948
|
+
}
|
|
949
|
+
const giftActions = calculateGiftActions(extendedGifts, existingGifts);
|
|
950
|
+
for (const gift of existingGifts) {
|
|
951
|
+
const strategyId = (_g = getGiftInfo(gift)) == null ? void 0 : _g.strategyId;
|
|
952
|
+
if (!strategyId)
|
|
953
|
+
continue;
|
|
954
|
+
const latest = strategyGiftInfoMap.get(strategyId);
|
|
955
|
+
if (latest && ((_h = gift.metadata) == null ? void 0 : _h._giftInfo)) {
|
|
956
|
+
gift.metadata._giftInfo.lastEvaluatedGiftCount = latest.giftCount;
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
const unfulfilledPromotions = calculateUnfulfilledPromotions(
|
|
960
|
+
processedProducts,
|
|
961
|
+
applicableStrategiesResult,
|
|
962
|
+
mainProducts
|
|
963
|
+
);
|
|
964
|
+
for (const product of processedProducts) {
|
|
965
|
+
delete product._sortIndex;
|
|
966
|
+
delete product._sortSubIndex;
|
|
967
|
+
delete product._originalProductUid;
|
|
968
|
+
delete product._sourceCartNum;
|
|
969
|
+
delete product._wasInPromotionBeforeConsolidate;
|
|
970
|
+
}
|
|
971
|
+
return {
|
|
972
|
+
products: processedProducts,
|
|
973
|
+
totalDiscount: result.totalDiscount,
|
|
974
|
+
gifts: extendedGifts,
|
|
975
|
+
giftActions,
|
|
976
|
+
unfulfilledPromotions
|
|
977
|
+
};
|
|
978
|
+
}
|
|
979
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
980
|
+
0 && (module.exports = {
|
|
981
|
+
appendPromotionTags,
|
|
982
|
+
buildConsolidateKeyForPromotion,
|
|
983
|
+
calculateUnfulfilledPromotions,
|
|
984
|
+
extractProductMatchIdentifiersFromStrategyConfig,
|
|
985
|
+
getOrderProductBasePrice,
|
|
986
|
+
getOrderProductOriginalPriceForPromotion,
|
|
987
|
+
getOrderProductUid,
|
|
988
|
+
mergeIdenticalPromotionCartLines,
|
|
989
|
+
processCartPromotion,
|
|
990
|
+
resolveStrategyEligibleProducts,
|
|
991
|
+
resolveStrategyRequiredQuantity
|
|
992
|
+
});
|