@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
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
// 导出评估器
|
|
2
|
-
export { PromotionEvaluator } from "./evaluator";
|
|
3
|
-
|
|
4
|
-
// 导出适配器
|
|
5
|
-
export { PromotionAdapter } from "./adapter";
|
|
6
|
-
export { default } from "./adapter";
|
|
7
|
-
|
|
8
|
-
// 导出策略配置示例常量
|
|
9
|
-
export { X_ITEMS_FOR_Y_PRICE_STRATEGY, BUY_X_GET_Y_FREE_STRATEGY } from "./examples";
|
|
@@ -16,6 +16,7 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
16
16
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
17
17
|
import dayjs from 'dayjs';
|
|
18
18
|
import { resolveManualDiscountMessage } from "../../Order/utils/manualProductDiscount";
|
|
19
|
+
import { buildProductOptionStringFromOrderLine } from "./orderLineDisplay";
|
|
19
20
|
function safeFormat(value, fmt) {
|
|
20
21
|
if (value === undefined || value === null) return undefined;
|
|
21
22
|
var d = dayjs(value);
|
|
@@ -188,12 +189,13 @@ export function buildCacheItemFromOrderLine(input) {
|
|
|
188
189
|
var capacity = resolveCapacityFromBooking(booking);
|
|
189
190
|
var holderId = (_booking$metadata$hol = (_booking$metadata2 = booking.metadata) === null || _booking$metadata2 === void 0 ? void 0 : _booking$metadata2.holder_id) !== null && _booking$metadata$hol !== void 0 ? _booking$metadata$hol : booking.holder_id;
|
|
190
191
|
var productTitle = resolveProductTitle(product, booking, sourceProduct);
|
|
192
|
+
var productOptionString = buildProductOptionStringFromOrderLine(product);
|
|
191
193
|
var other = {
|
|
192
194
|
product_variant_id: (_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : 0,
|
|
193
195
|
option: Array.isArray(product.product_option_item) ? _toConsumableArray(product.product_option_item) : [],
|
|
194
196
|
bundle: Array.isArray(product.product_bundle) ? _toConsumableArray(product.product_bundle) : []
|
|
195
197
|
};
|
|
196
|
-
var extend = {
|
|
198
|
+
var extend = _objectSpread({
|
|
197
199
|
start_date: startDate ? dayjs(startDate) : undefined,
|
|
198
200
|
end_date: endDate ? dayjs(endDate) : undefined,
|
|
199
201
|
startDate: startDate ? dayjs(startDate) : undefined,
|
|
@@ -214,7 +216,9 @@ export function buildCacheItemFromOrderLine(input) {
|
|
|
214
216
|
other: other,
|
|
215
217
|
like_status: booking.like_status || 'common',
|
|
216
218
|
discount_reason: resolveManualDiscountMessage(product.discount_list, (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.product_discount_reason) || undefined
|
|
217
|
-
}
|
|
219
|
+
}, productOptionString ? {
|
|
220
|
+
product_option_string: productOptionString
|
|
221
|
+
} : {});
|
|
218
222
|
var manualDiscount = (product.discount_list || []).find(function (d) {
|
|
219
223
|
return (d === null || d === void 0 ? void 0 : d.type) === 'product';
|
|
220
224
|
});
|
|
@@ -234,14 +238,17 @@ export function buildCacheItemFromOrderLine(input) {
|
|
|
234
238
|
if (Array.isArray(booking.relation_forms)) {
|
|
235
239
|
extend.relation_forms = booking.relation_forms;
|
|
236
240
|
}
|
|
237
|
-
var base = _objectSpread(_objectSpread({}, sourceProduct || {}), {}, {
|
|
241
|
+
var base = _objectSpread(_objectSpread(_objectSpread({}, sourceProduct || {}), {}, {
|
|
238
242
|
id: resolvedId,
|
|
239
243
|
product_id: resolvedId,
|
|
240
244
|
extension_type: (_ref9 = (_extension_type = sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.extension_type) !== null && _extension_type !== void 0 ? _extension_type : booking === null || booking === void 0 || (_booking$product2 = booking.product) === null || _booking$product2 === void 0 ? void 0 : _booking$product2.extension_type) !== null && _ref9 !== void 0 ? _ref9 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.extension_type,
|
|
241
245
|
title: productTitle || (sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.title) || (booking === null || booking === void 0 || (_booking$product3 = booking.product) === null || _booking$product3 === void 0 ? void 0 : _booking$product3.title),
|
|
242
246
|
price: (_price = sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.price) !== null && _price !== void 0 ? _price : selling,
|
|
243
247
|
selling_price: product.selling_price,
|
|
244
|
-
original_price: product.original_price
|
|
248
|
+
original_price: product.original_price
|
|
249
|
+
}, productOptionString ? {
|
|
250
|
+
product_option_string: productOptionString
|
|
251
|
+
} : {}), {}, {
|
|
245
252
|
_extend: extend,
|
|
246
253
|
new: 0,
|
|
247
254
|
autoClose: false,
|
|
@@ -13,6 +13,7 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
13
13
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
14
14
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
15
15
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
16
|
+
import { buildProductOptionStringFromOrderLine } from "./orderLineDisplay";
|
|
16
17
|
/**
|
|
17
18
|
* 从已加车的普通商品 order line 反查 SkuDetailModal edit 所需的 cacheItem。
|
|
18
19
|
*
|
|
@@ -86,6 +87,7 @@ export function buildNormalProductCacheItemFromOrderLine(input) {
|
|
|
86
87
|
var option = Array.isArray(product.product_option_item) ? _toConsumableArray(product.product_option_item) : [];
|
|
87
88
|
var bundle = mapOrderBundleToOtherBundle(Array.isArray(product.product_bundle) ? product.product_bundle : []);
|
|
88
89
|
var originExtend = (_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 || (_product$metadata2 = _product$metadata2.origin) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2._extend;
|
|
90
|
+
var productOptionString = buildProductOptionStringFromOrderLine(product);
|
|
89
91
|
var other = {
|
|
90
92
|
product_id: resolvedId,
|
|
91
93
|
product_variant_id: (_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : 0,
|
|
@@ -99,7 +101,7 @@ export function buildNormalProductCacheItemFromOrderLine(input) {
|
|
|
99
101
|
option: other.option,
|
|
100
102
|
bundle: other.bundle
|
|
101
103
|
};
|
|
102
|
-
var extend = _objectSpread(_objectSpread({
|
|
104
|
+
var extend = _objectSpread(_objectSpread(_objectSpread({
|
|
103
105
|
quantity: (_product$num2 = product.num) !== null && _product$num2 !== void 0 ? _product$num2 : 1,
|
|
104
106
|
product_name: (_title = sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.title) !== null && _title !== void 0 ? _title : '',
|
|
105
107
|
note: (_product$note = product.note) !== null && _product$note !== void 0 ? _product$note : '',
|
|
@@ -111,7 +113,9 @@ export function buildNormalProductCacheItemFromOrderLine(input) {
|
|
|
111
113
|
skuValue: JSON.parse(JSON.stringify(skuValue)),
|
|
112
114
|
_skuValue: JSON.parse(JSON.stringify(skuValue)),
|
|
113
115
|
isNormalProduct: true
|
|
114
|
-
},
|
|
116
|
+
}, productOptionString ? {
|
|
117
|
+
product_option_string: productOptionString
|
|
118
|
+
} : {}), (originExtend === null || originExtend === void 0 ? void 0 : originExtend.priceOverride) !== undefined ? {
|
|
115
119
|
priceOverride: originExtend.priceOverride
|
|
116
120
|
} : {}), (originExtend === null || originExtend === void 0 ? void 0 : originExtend.bundle_edit) !== undefined ? {
|
|
117
121
|
bundle_edit: originExtend.bundle_edit
|
|
@@ -120,14 +124,17 @@ export function buildNormalProductCacheItemFromOrderLine(input) {
|
|
|
120
124
|
extend.skuValue = JSON.parse(JSON.stringify(originExtend.skuValue || originExtend._skuValue));
|
|
121
125
|
extend._skuValue = JSON.parse(JSON.stringify(extend.skuValue));
|
|
122
126
|
}
|
|
123
|
-
return _objectSpread(_objectSpread({}, sourceProduct || {}), {}, {
|
|
127
|
+
return _objectSpread(_objectSpread(_objectSpread({}, sourceProduct || {}), {}, {
|
|
124
128
|
id: resolvedId,
|
|
125
129
|
product_id: resolvedId,
|
|
126
130
|
_id: uid,
|
|
127
131
|
title: sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.title,
|
|
128
132
|
price: (_price3 = sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.price) !== null && _price3 !== void 0 ? _price3 : sourcePrice,
|
|
129
133
|
selling_price: product.selling_price,
|
|
130
|
-
original_price: product.original_price
|
|
134
|
+
original_price: product.original_price
|
|
135
|
+
}, productOptionString ? {
|
|
136
|
+
product_option_string: productOptionString
|
|
137
|
+
} : {}), {}, {
|
|
131
138
|
note: product.note,
|
|
132
139
|
order_detail_id: (_product$order_detail = product.order_detail_id) !== null && _product$order_detail !== void 0 ? _product$order_detail : null,
|
|
133
140
|
new: 0,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function buildProductOptionStringFromOrderLine(product: any): string;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
2
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
3
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
4
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
5
|
+
function pickDisplayText(value) {
|
|
6
|
+
if (value === undefined || value === null) return '';
|
|
7
|
+
if (typeof value === 'string') return value;
|
|
8
|
+
if (_typeof(value) !== 'object') return String(value);
|
|
9
|
+
return value.auto || value.original || value.en || value['zh-CN'] || value['zh-HK'] || '';
|
|
10
|
+
}
|
|
11
|
+
function formatNamePair(group, item) {
|
|
12
|
+
var groupText = pickDisplayText(group);
|
|
13
|
+
var itemText = pickDisplayText(item);
|
|
14
|
+
if (groupText && itemText) return "".concat(groupText, ":").concat(itemText);
|
|
15
|
+
return groupText || itemText;
|
|
16
|
+
}
|
|
17
|
+
export function buildProductOptionStringFromOrderLine(product) {
|
|
18
|
+
var segments = [];
|
|
19
|
+
var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
|
|
20
|
+
if (Array.isArray(sku.variant)) {
|
|
21
|
+
var _iterator = _createForOfIteratorHelper(sku.variant),
|
|
22
|
+
_step;
|
|
23
|
+
try {
|
|
24
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
25
|
+
var variant = _step.value;
|
|
26
|
+
var segment = formatNamePair(variant === null || variant === void 0 ? void 0 : variant.group, variant === null || variant === void 0 ? void 0 : variant.item);
|
|
27
|
+
if (segment) segments.push(segment);
|
|
28
|
+
}
|
|
29
|
+
} catch (err) {
|
|
30
|
+
_iterator.e(err);
|
|
31
|
+
} finally {
|
|
32
|
+
_iterator.f();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return segments.join(', ');
|
|
36
|
+
}
|
|
@@ -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;
|
|
@@ -1127,7 +1127,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1127
1127
|
return mapPaymentItemsToOrderPayments(payments, {
|
|
1128
1128
|
includeVoided: false
|
|
1129
1129
|
}).reduce(function (sum, payment) {
|
|
1130
|
-
var amount = new Decimal(payment.amount || 0);
|
|
1130
|
+
var amount = new Decimal(payment.amount || 0).minus(new Decimal(payment.service_fee || 0));
|
|
1131
1131
|
var rounding = new Decimal(payment.rounding_amount || 0);
|
|
1132
1132
|
return sum.plus(amount.minus(rounding));
|
|
1133
1133
|
}, new Decimal(0));
|
|
@@ -2229,8 +2229,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2229
2229
|
key: "updateOrderProduct",
|
|
2230
2230
|
value: function () {
|
|
2231
2231
|
var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(params) {
|
|
2232
|
-
var _targetProduct$metada2, _metadata, _metadata2, _metadata3, _nextProduct$metadata, _targetProduct$
|
|
2233
|
-
var product_id, product_variant_id, updates, unique_identification_number, identity_key, product_option_item, product_bundle, booking, tempOrder, identityLookup, productIndex, targetUid, targetProduct, nextProduct, callerUpdatesTopPrice, callerUpdatesMainMeta, existedMeta, normalizedProduct, preservedBookingUid, _normalizedProduct$me, _targetProduct$
|
|
2232
|
+
var _targetProduct$metada2, _metadata, _metadata2, _metadata3, _metadata4, _metadata5, _metadata6, _nextProduct$metadata, _targetProduct$metada7, _tempOrder$products$p;
|
|
2233
|
+
var product_id, product_variant_id, updates, unique_identification_number, identity_key, product_option_item, product_bundle, booking, tempOrder, identityLookup, productIndex, targetUid, targetProduct, nextProduct, callerUpdatesTopPrice, callerUpdatesMainMeta, isPersistedOrderLine, callerUpdatesManualPrice, _targetProduct$metada3, _targetProduct$metada4, _targetProduct$metada5, _targetProduct$metada6, existedMeta, normalizedProduct, preservedBookingUid, _normalizedProduct$me, _targetProduct$metada8, productUid, linked;
|
|
2234
2234
|
return _regeneratorRuntime().wrap(function _callee17$(_context19) {
|
|
2235
2235
|
while (1) switch (_context19.prev = _context19.next) {
|
|
2236
2236
|
case 0:
|
|
@@ -2285,7 +2285,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2285
2285
|
// 如果 caller 走推荐路径(updates.metadata.* 显式指定主价),保留 metadata 由 normalize 认它。
|
|
2286
2286
|
callerUpdatesTopPrice = Object.prototype.hasOwnProperty.call(updates || {}, 'selling_price') || Object.prototype.hasOwnProperty.call(updates || {}, 'original_price');
|
|
2287
2287
|
callerUpdatesMainMeta = (updates === null || updates === void 0 || (_metadata = updates.metadata) === null || _metadata === void 0 ? void 0 : _metadata.main_product_selling_price) !== undefined || (updates === null || updates === void 0 || (_metadata2 = updates.metadata) === null || _metadata2 === void 0 ? void 0 : _metadata2.main_product_original_price) !== undefined || (updates === null || updates === void 0 || (_metadata3 = updates.metadata) === null || _metadata3 === void 0 ? void 0 : _metadata3.source_product_price) !== undefined;
|
|
2288
|
-
|
|
2288
|
+
isPersistedOrderLine = targetProduct.order_detail_id !== undefined && targetProduct.order_detail_id !== null;
|
|
2289
|
+
callerUpdatesManualPrice = (updates === null || updates === void 0 || (_metadata4 = updates.metadata) === null || _metadata4 === void 0 ? void 0 : _metadata4.price_override) !== undefined || (updates === null || updates === void 0 || (_metadata5 = updates.metadata) === null || _metadata5 === void 0 ? void 0 : _metadata5.is_manual_discount) !== undefined || (updates === null || updates === void 0 || (_metadata6 = updates.metadata) === null || _metadata6 === void 0 ? void 0 : _metadata6.product_discount_reason) !== undefined || Array.isArray(updates === null || updates === void 0 ? void 0 : updates.discount_list) && updates.discount_list.length > 0;
|
|
2290
|
+
if (isPersistedOrderLine && !callerUpdatesManualPrice) {
|
|
2291
|
+
nextProduct.selling_price = targetProduct.selling_price;
|
|
2292
|
+
nextProduct.original_price = targetProduct.original_price;
|
|
2293
|
+
nextProduct.payment_price = targetProduct.payment_price;
|
|
2294
|
+
nextProduct.metadata = _objectSpread(_objectSpread({}, nextProduct.metadata || {}), {}, {
|
|
2295
|
+
source_product_price: (_targetProduct$metada3 = targetProduct.metadata) === null || _targetProduct$metada3 === void 0 ? void 0 : _targetProduct$metada3.source_product_price,
|
|
2296
|
+
main_product_selling_price: (_targetProduct$metada4 = targetProduct.metadata) === null || _targetProduct$metada4 === void 0 ? void 0 : _targetProduct$metada4.main_product_selling_price,
|
|
2297
|
+
main_product_original_price: (_targetProduct$metada5 = targetProduct.metadata) === null || _targetProduct$metada5 === void 0 ? void 0 : _targetProduct$metada5.main_product_original_price,
|
|
2298
|
+
price_schema_version: (_targetProduct$metada6 = targetProduct.metadata) === null || _targetProduct$metada6 === void 0 ? void 0 : _targetProduct$metada6.price_schema_version
|
|
2299
|
+
});
|
|
2300
|
+
} else if (callerUpdatesTopPrice && !callerUpdatesMainMeta) {
|
|
2289
2301
|
existedMeta = nextProduct.metadata || {};
|
|
2290
2302
|
nextProduct.metadata = _objectSpread({}, existedMeta);
|
|
2291
2303
|
delete nextProduct.metadata.source_product_price;
|
|
@@ -2297,7 +2309,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2297
2309
|
// 否则 → 把顶层 selling_price 视作 source,派生 main_product_* 并写 price_schema_version: 2。
|
|
2298
2310
|
normalizedProduct = mergeOrderProductDisplayFields(nextProduct, normalizeOrderProduct(nextProduct));
|
|
2299
2311
|
normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
|
|
2300
|
-
preservedBookingUid = nextProduct.booking_uid || ((_nextProduct$metadata = nextProduct.metadata) === null || _nextProduct$metadata === void 0 ? void 0 : _nextProduct$metadata.booking_uid) || targetProduct.booking_uid || ((_targetProduct$
|
|
2312
|
+
preservedBookingUid = nextProduct.booking_uid || ((_nextProduct$metadata = nextProduct.metadata) === null || _nextProduct$metadata === void 0 ? void 0 : _nextProduct$metadata.booking_uid) || targetProduct.booking_uid || ((_targetProduct$metada7 = targetProduct.metadata) === null || _targetProduct$metada7 === void 0 ? void 0 : _targetProduct$metada7.booking_uid);
|
|
2301
2313
|
if (!booking && preservedBookingUid) {
|
|
2302
2314
|
normalizedProduct.booking_uid = preservedBookingUid;
|
|
2303
2315
|
normalizedProduct.metadata = _objectSpread(_objectSpread({}, normalizedProduct.metadata || {}), {}, {
|
|
@@ -2305,7 +2317,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2305
2317
|
});
|
|
2306
2318
|
}
|
|
2307
2319
|
if (booking) {
|
|
2308
|
-
productUid = String(((_normalizedProduct$me = normalizedProduct.metadata) === null || _normalizedProduct$me === void 0 ? void 0 : _normalizedProduct$me.unique_identification_number) || ((_targetProduct$
|
|
2320
|
+
productUid = String(((_normalizedProduct$me = normalizedProduct.metadata) === null || _normalizedProduct$me === void 0 ? void 0 : _normalizedProduct$me.unique_identification_number) || ((_targetProduct$metada8 = targetProduct.metadata) === null || _targetProduct$metada8 === void 0 ? void 0 : _targetProduct$metada8.unique_identification_number) || unique_identification_number || createUuidV4());
|
|
2309
2321
|
normalizedProduct.metadata = _objectSpread(_objectSpread({}, normalizedProduct.metadata || {}), {}, {
|
|
2310
2322
|
unique_identification_number: productUid
|
|
2311
2323
|
});
|
|
@@ -2327,18 +2339,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2327
2339
|
}
|
|
2328
2340
|
tempOrder.products[productIndex] = normalizedProduct;
|
|
2329
2341
|
this.captureProductRuntime(tempOrder, updates, tempOrder.products[productIndex], (_tempOrder$products$p = tempOrder.products[productIndex].metadata) === null || _tempOrder$products$p === void 0 ? void 0 : _tempOrder$products$p.unique_identification_number);
|
|
2330
|
-
_context19.next =
|
|
2342
|
+
_context19.next = 29;
|
|
2331
2343
|
return this.applyPromotion();
|
|
2332
|
-
case
|
|
2344
|
+
case 29:
|
|
2333
2345
|
this.applyDiscount();
|
|
2334
|
-
_context19.next =
|
|
2346
|
+
_context19.next = 32;
|
|
2335
2347
|
return this.recalculateSummary({
|
|
2336
2348
|
createIfMissing: true
|
|
2337
2349
|
});
|
|
2338
|
-
case
|
|
2350
|
+
case 32:
|
|
2339
2351
|
this.persistTempOrder();
|
|
2340
2352
|
return _context19.abrupt("return", tempOrder.products);
|
|
2341
|
-
case
|
|
2353
|
+
case 34:
|
|
2342
2354
|
case "end":
|
|
2343
2355
|
return _context19.stop();
|
|
2344
2356
|
}
|
|
@@ -2353,7 +2365,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2353
2365
|
key: "updateOrderProductQuantity",
|
|
2354
2366
|
value: function () {
|
|
2355
2367
|
var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(params) {
|
|
2356
|
-
var _targetProduct$
|
|
2368
|
+
var _targetProduct$metada9;
|
|
2357
2369
|
var product_id, product_variant_id, num, unique_identification_number, identity_key, product_option_item, product_bundle, tempOrder, identityLookup, productIndex, targetUid, targetProduct, normalizedProduct;
|
|
2358
2370
|
return _regeneratorRuntime().wrap(function _callee18$(_context20) {
|
|
2359
2371
|
while (1) switch (_context20.prev = _context20.next) {
|
|
@@ -2394,7 +2406,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2394
2406
|
normalizedProduct = normalizeOrderProduct(_objectSpread(_objectSpread({}, targetProduct), {}, {
|
|
2395
2407
|
num: getSafeProductNum(num),
|
|
2396
2408
|
metadata: _objectSpread(_objectSpread({}, targetProduct.metadata || {}), {}, {
|
|
2397
|
-
unique_identification_number: ((_targetProduct$
|
|
2409
|
+
unique_identification_number: ((_targetProduct$metada9 = targetProduct.metadata) === null || _targetProduct$metada9 === void 0 ? void 0 : _targetProduct$metada9.unique_identification_number) || unique_identification_number
|
|
2398
2410
|
})
|
|
2399
2411
|
}));
|
|
2400
2412
|
normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
|
|
@@ -3328,8 +3340,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3328
3340
|
var existed = productsByUid[uid] && _typeof(productsByUid[uid]) === 'object' ? productsByUid[uid] : {};
|
|
3329
3341
|
var rawProduct = rawProducts[index] && _typeof(rawProducts[index]) === 'object' ? rawProducts[index] : product;
|
|
3330
3342
|
var origin = (_ref23 = (_ref24 = (_existed$origin = existed.origin) !== null && _existed$origin !== void 0 ? _existed$origin : rawProduct._origin) !== null && _ref24 !== void 0 ? _ref24 : (_rawProduct$metadata = rawProduct.metadata) === null || _rawProduct$metadata === void 0 ? void 0 : _rawProduct$metadata.origin) !== null && _ref23 !== void 0 ? _ref23 : rawProduct;
|
|
3343
|
+
var originSnapshot = cloneDeep(origin);
|
|
3344
|
+
var productOptionString = this.buildHydratedProductOptionString(rawProduct) || this.buildHydratedProductOptionString(product);
|
|
3345
|
+
if (productOptionString && originSnapshot && _typeof(originSnapshot) === 'object') {
|
|
3346
|
+
if (originSnapshot.product_option_string === undefined) {
|
|
3347
|
+
originSnapshot.product_option_string = productOptionString;
|
|
3348
|
+
}
|
|
3349
|
+
if (originSnapshot.product_options_stirng === undefined) {
|
|
3350
|
+
originSnapshot.product_options_stirng = productOptionString;
|
|
3351
|
+
}
|
|
3352
|
+
}
|
|
3331
3353
|
productsByUid[uid] = _objectSpread(_objectSpread({}, existed), {}, {
|
|
3332
|
-
origin:
|
|
3354
|
+
origin: originSnapshot
|
|
3333
3355
|
});
|
|
3334
3356
|
}
|
|
3335
3357
|
} catch (err) {
|
|
@@ -3344,6 +3366,44 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3344
3366
|
nextTempOrder.vouchers = raw.vouchers || [];
|
|
3345
3367
|
return nextTempOrder;
|
|
3346
3368
|
}
|
|
3369
|
+
}, {
|
|
3370
|
+
key: "pickHydratedDisplayText",
|
|
3371
|
+
value: function pickHydratedDisplayText(value) {
|
|
3372
|
+
if (value === undefined || value === null) return '';
|
|
3373
|
+
if (typeof value === 'string') return value;
|
|
3374
|
+
if (_typeof(value) !== 'object') return String(value);
|
|
3375
|
+
return value.auto || value.original || value.en || value['zh-CN'] || value['zh-HK'] || '';
|
|
3376
|
+
}
|
|
3377
|
+
}, {
|
|
3378
|
+
key: "formatHydratedNamePair",
|
|
3379
|
+
value: function formatHydratedNamePair(group, item) {
|
|
3380
|
+
var groupText = this.pickHydratedDisplayText(group);
|
|
3381
|
+
var itemText = this.pickHydratedDisplayText(item);
|
|
3382
|
+
if (groupText && itemText) return "".concat(groupText, ":").concat(itemText);
|
|
3383
|
+
return groupText || itemText;
|
|
3384
|
+
}
|
|
3385
|
+
}, {
|
|
3386
|
+
key: "buildHydratedProductOptionString",
|
|
3387
|
+
value: function buildHydratedProductOptionString(product) {
|
|
3388
|
+
var segments = [];
|
|
3389
|
+
var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
|
|
3390
|
+
if (Array.isArray(sku.variant)) {
|
|
3391
|
+
var _iterator9 = _createForOfIteratorHelper(sku.variant),
|
|
3392
|
+
_step9;
|
|
3393
|
+
try {
|
|
3394
|
+
for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
|
|
3395
|
+
var variant = _step9.value;
|
|
3396
|
+
var segment = this.formatHydratedNamePair(variant === null || variant === void 0 ? void 0 : variant.group, variant === null || variant === void 0 ? void 0 : variant.item);
|
|
3397
|
+
if (segment) segments.push(segment);
|
|
3398
|
+
}
|
|
3399
|
+
} catch (err) {
|
|
3400
|
+
_iterator9.e(err);
|
|
3401
|
+
} finally {
|
|
3402
|
+
_iterator9.f();
|
|
3403
|
+
}
|
|
3404
|
+
}
|
|
3405
|
+
return segments.join(', ');
|
|
3406
|
+
}
|
|
3347
3407
|
}, {
|
|
3348
3408
|
key: "normalizeHydratedProductOptionItem",
|
|
3349
3409
|
value: function normalizeHydratedProductOptionItem(optionItem) {
|
|
@@ -3352,22 +3412,58 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3352
3412
|
var parsedNum = Number(rawNum);
|
|
3353
3413
|
var rawPrice = (_ref26 = (_optionItem$price = optionItem === null || optionItem === void 0 ? void 0 : optionItem.price) !== null && _optionItem$price !== void 0 ? _optionItem$price : optionItem === null || optionItem === void 0 ? void 0 : optionItem.add_price) !== null && _ref26 !== void 0 ? _ref26 : 0;
|
|
3354
3414
|
var parsedPrice = Number(rawPrice);
|
|
3355
|
-
|
|
3415
|
+
var normalized = {
|
|
3356
3416
|
option_group_item_id: optionItem === null || optionItem === void 0 ? void 0 : optionItem.option_group_item_id,
|
|
3357
3417
|
option_group_id: optionItem === null || optionItem === void 0 ? void 0 : optionItem.option_group_id,
|
|
3358
3418
|
num: Number.isFinite(parsedNum) && parsedNum > 0 ? parsedNum : 1,
|
|
3359
3419
|
price: Number.isFinite(parsedPrice) ? parsedPrice : 0
|
|
3360
3420
|
};
|
|
3421
|
+
if ((optionItem === null || optionItem === void 0 ? void 0 : optionItem.name) !== undefined) normalized.name = optionItem.name;
|
|
3422
|
+
if ((optionItem === null || optionItem === void 0 ? void 0 : optionItem.group_name) !== undefined) normalized.group_name = optionItem.group_name;
|
|
3423
|
+
if ((optionItem === null || optionItem === void 0 ? void 0 : optionItem.id) !== undefined) normalized.id = optionItem.id;
|
|
3424
|
+
return normalized;
|
|
3425
|
+
}
|
|
3426
|
+
}, {
|
|
3427
|
+
key: "mergeHydratedProductOptionDisplayFields",
|
|
3428
|
+
value: function mergeHydratedProductOptionDisplayFields(options, skuOptions) {
|
|
3429
|
+
if (!Array.isArray(skuOptions) || skuOptions.length === 0) return options;
|
|
3430
|
+
var displayByItemId = new Map();
|
|
3431
|
+
var _iterator10 = _createForOfIteratorHelper(skuOptions),
|
|
3432
|
+
_step10;
|
|
3433
|
+
try {
|
|
3434
|
+
for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
|
|
3435
|
+
var option = _step10.value;
|
|
3436
|
+
var key = option === null || option === void 0 ? void 0 : option.option_group_item_id;
|
|
3437
|
+
if (key === undefined || key === null || key === '') continue;
|
|
3438
|
+
displayByItemId.set(String(key), option);
|
|
3439
|
+
}
|
|
3440
|
+
} catch (err) {
|
|
3441
|
+
_iterator10.e(err);
|
|
3442
|
+
} finally {
|
|
3443
|
+
_iterator10.f();
|
|
3444
|
+
}
|
|
3445
|
+
return options.map(function (option) {
|
|
3446
|
+
var _option$option_group_;
|
|
3447
|
+
var display = displayByItemId.get(String((_option$option_group_ = option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _option$option_group_ !== void 0 ? _option$option_group_ : ''));
|
|
3448
|
+
if (!display) return option;
|
|
3449
|
+
return _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, option), option.name === undefined && display.name !== undefined ? {
|
|
3450
|
+
name: display.name
|
|
3451
|
+
} : {}), option.group_name === undefined && display.group_name !== undefined ? {
|
|
3452
|
+
group_name: display.group_name
|
|
3453
|
+
} : {}), option.id === undefined && display.id !== undefined ? {
|
|
3454
|
+
id: display.id
|
|
3455
|
+
} : {});
|
|
3456
|
+
});
|
|
3361
3457
|
}
|
|
3362
3458
|
}, {
|
|
3363
3459
|
key: "resolveHydratedProductOptions",
|
|
3364
3460
|
value: function resolveHydratedProductOptions(row) {
|
|
3365
3461
|
var _row$product_sku,
|
|
3366
3462
|
_this11 = this;
|
|
3463
|
+
var skuOptions = (_row$product_sku = row.product_sku) === null || _row$product_sku === void 0 ? void 0 : _row$product_sku.option;
|
|
3367
3464
|
if (Array.isArray(row.product_option_item) && row.product_option_item.length > 0) {
|
|
3368
|
-
return row.product_option_item;
|
|
3465
|
+
return this.mergeHydratedProductOptionDisplayFields(row.product_option_item, skuOptions);
|
|
3369
3466
|
}
|
|
3370
|
-
var skuOptions = (_row$product_sku = row.product_sku) === null || _row$product_sku === void 0 ? void 0 : _row$product_sku.option;
|
|
3371
3467
|
if (!Array.isArray(skuOptions)) return [];
|
|
3372
3468
|
return skuOptions.map(function (optionItem) {
|
|
3373
3469
|
return _this11.normalizeHydratedProductOptionItem(optionItem || {});
|
|
@@ -3448,67 +3544,67 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3448
3544
|
var amount = new Decimal(discount.amount || 0).times(qty).plus(((_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata.product_discount_difference) || 0);
|
|
3449
3545
|
savedMap.set(discountKey, (savedMap.get(discountKey) || new Decimal(0)).plus(amount));
|
|
3450
3546
|
};
|
|
3451
|
-
var
|
|
3452
|
-
|
|
3547
|
+
var _iterator11 = _createForOfIteratorHelper(productList),
|
|
3548
|
+
_step11;
|
|
3453
3549
|
try {
|
|
3454
|
-
for (
|
|
3455
|
-
var product =
|
|
3550
|
+
for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
|
|
3551
|
+
var product = _step11.value;
|
|
3456
3552
|
var qty = product.num || 1;
|
|
3457
|
-
var
|
|
3458
|
-
|
|
3553
|
+
var _iterator13 = _createForOfIteratorHelper(product.discount_list || []),
|
|
3554
|
+
_step13;
|
|
3459
3555
|
try {
|
|
3460
|
-
for (
|
|
3461
|
-
var pd =
|
|
3556
|
+
for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
|
|
3557
|
+
var pd = _step13.value;
|
|
3462
3558
|
addDiscountAmount(pd, qty);
|
|
3463
3559
|
}
|
|
3464
3560
|
} catch (err) {
|
|
3465
|
-
|
|
3561
|
+
_iterator13.e(err);
|
|
3466
3562
|
} finally {
|
|
3467
|
-
|
|
3563
|
+
_iterator13.f();
|
|
3468
3564
|
}
|
|
3469
|
-
var
|
|
3470
|
-
|
|
3565
|
+
var _iterator14 = _createForOfIteratorHelper(product.product_bundle || []),
|
|
3566
|
+
_step14;
|
|
3471
3567
|
try {
|
|
3472
|
-
for (
|
|
3568
|
+
for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
|
|
3473
3569
|
var _ref27, _bundle$num;
|
|
3474
|
-
var bundle =
|
|
3570
|
+
var bundle = _step14.value;
|
|
3475
3571
|
var bundleQty = new Decimal(Number(qty) || 1).times(Number((_ref27 = (_bundle$num = bundle === null || bundle === void 0 ? void 0 : bundle.num) !== null && _bundle$num !== void 0 ? _bundle$num : bundle === null || bundle === void 0 ? void 0 : bundle.quantity) !== null && _ref27 !== void 0 ? _ref27 : 1) || 1).toNumber();
|
|
3476
|
-
var
|
|
3477
|
-
|
|
3572
|
+
var _iterator15 = _createForOfIteratorHelper((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []),
|
|
3573
|
+
_step15;
|
|
3478
3574
|
try {
|
|
3479
|
-
for (
|
|
3480
|
-
var _pd =
|
|
3575
|
+
for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
|
|
3576
|
+
var _pd = _step15.value;
|
|
3481
3577
|
addDiscountAmount(_pd, bundleQty);
|
|
3482
3578
|
}
|
|
3483
3579
|
} catch (err) {
|
|
3484
|
-
|
|
3580
|
+
_iterator15.e(err);
|
|
3485
3581
|
} finally {
|
|
3486
|
-
|
|
3582
|
+
_iterator15.f();
|
|
3487
3583
|
}
|
|
3488
3584
|
}
|
|
3489
3585
|
} catch (err) {
|
|
3490
|
-
|
|
3586
|
+
_iterator14.e(err);
|
|
3491
3587
|
} finally {
|
|
3492
|
-
|
|
3588
|
+
_iterator14.f();
|
|
3493
3589
|
}
|
|
3494
3590
|
}
|
|
3495
3591
|
} catch (err) {
|
|
3496
|
-
|
|
3592
|
+
_iterator11.e(err);
|
|
3497
3593
|
} finally {
|
|
3498
|
-
|
|
3594
|
+
_iterator11.f();
|
|
3499
3595
|
}
|
|
3500
|
-
var
|
|
3501
|
-
|
|
3596
|
+
var _iterator12 = _createForOfIteratorHelper(discountList),
|
|
3597
|
+
_step12;
|
|
3502
3598
|
try {
|
|
3503
|
-
for (
|
|
3504
|
-
var d =
|
|
3599
|
+
for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
|
|
3600
|
+
var d = _step12.value;
|
|
3505
3601
|
var key = d.id;
|
|
3506
3602
|
d.savedAmount = d.isSelected && key != null && savedMap.has(key) ? savedMap.get(key).toNumber() : 0;
|
|
3507
3603
|
}
|
|
3508
3604
|
} catch (err) {
|
|
3509
|
-
|
|
3605
|
+
_iterator12.e(err);
|
|
3510
3606
|
} finally {
|
|
3511
|
-
|
|
3607
|
+
_iterator12.f();
|
|
3512
3608
|
}
|
|
3513
3609
|
}
|
|
3514
3610
|
}]);
|