@pisell/pisellos 2.2.307 → 2.2.309
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 +9 -0
- package/dist/modules/Order/index.d.ts +1 -0
- package/dist/modules/Order/index.js +118 -59
- package/dist/modules/Order/utils/weighedProduct.d.ts +12 -0
- package/dist/modules/Order/utils/weighedProduct.js +94 -0
- package/dist/modules/Order/utils.js +6 -4
- package/dist/modules/ResourcePlanner/planner.js +10 -8
- package/dist/modules/Rules/index.js +4 -2
- package/dist/modules/Rules/types.d.ts +2 -0
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +40 -25
- package/dist/solution/BaseSales/utils.js +3 -2
- package/dist/solution/ScanOrder/utils.js +3 -2
- package/dist/solution/UnifiedBookingSales/index.js +3 -4
- package/lib/modules/Order/index.d.ts +1 -0
- package/lib/modules/Order/index.js +71 -11
- package/lib/modules/Order/utils/weighedProduct.d.ts +12 -0
- package/lib/modules/Order/utils/weighedProduct.js +89 -0
- package/lib/modules/Order/utils.js +3 -2
- package/lib/modules/ResourcePlanner/planner.js +10 -8
- package/lib/modules/Rules/index.js +4 -2
- package/lib/modules/Rules/types.d.ts +2 -0
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +24 -9
- package/lib/solution/BaseSales/utils.js +2 -1
- package/lib/solution/ScanOrder/utils.js +2 -1
- package/lib/solution/UnifiedBookingSales/index.js +3 -4
- package/package.json +1 -1
|
@@ -0,0 +1,9 @@
|
|
|
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, ITEM_REWARD_STRATEGY } from "./examples";
|
|
@@ -100,6 +100,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
|
|
|
100
100
|
}>;
|
|
101
101
|
applyDiscount(options?: {
|
|
102
102
|
reapplyBookingDiscountProductUids?: string[];
|
|
103
|
+
reapplyWeighedDiscountProductUids?: string[];
|
|
103
104
|
}): void;
|
|
104
105
|
/**
|
|
105
106
|
* 注入促销评估器。
|
|
@@ -34,13 +34,14 @@ import { BaseModule } from "../BaseModule";
|
|
|
34
34
|
import { OrderHooks } from "./types";
|
|
35
35
|
import { composeLinePrice, generateDuration, getAllDiscountList, mergeRelationForms, ensureCartItemOriginHolder, buildSubmitPayload, createDefaultTempOrder, createDefaultOrderRulesHooks, createEmptySummary, createUuidV4, formatDateTime, isTempOrder, normalizeOrderMetaList, normalizeBookingIsAll, normalizeBookingSubType, mapPaymentItemsToOrderPayments, normalizeOrderProductDiscountList, resolveEffectivePerUnitDiscount, ensureProductSku, getProductSkuOptions, normalizeProductSkuOptions, sumOptionUnitPrice, clearTempOrderHolderAssignments, getOrderProductLineUid, indexOrderProductsByUid, calculateOrderProductsDeposit, buildPointCardSnapshotFromWalletPassList, mergeOrderProductDisplayFields, resolveIsFormSubject, isMarkdownBundle } from "./utils";
|
|
36
36
|
import { isNormalProduct } from "../Product/utils";
|
|
37
|
+
import { getWeighedProductPriceFingerprint, resolveWeighedSourcePrice, withOriginalBundleOptionPrices } from "./utils/weighedProduct";
|
|
37
38
|
import dayjs from 'dayjs';
|
|
38
39
|
import { buildSalesNoteText, decodeSalesNotesSnapshot, getSalesNotePolicy } from "./salesNotes";
|
|
39
40
|
import { ensureOrderPaymentNumber, mergeOrderPaymentRecord, resolveOrderPaymentIdentity } from "./payment-utils";
|
|
40
41
|
import { resolvePaymentNumberDevicePrefix, resolvePaymentNumberDevicePrefixFromDeviceId } from "../../utils/payment-number";
|
|
41
42
|
import { processCartPromotion, appendPromotionTags as _appendPromotionTags, getOrderProductUid as getPromotionUid, PRODUCT_LINE_MERGE_DISABLED_METADATA_KEY } from "../../solution/BaseSales/utils/cartPromotion";
|
|
42
43
|
import { buildProductLineFingerprint, getProductIdentityIndex, getSafeProductNum, isIdentityMatch, normalizeOrderProduct } from "../../solution/ScanOrder/utils";
|
|
43
|
-
import { hasManualProductDiscountFlag, syncManualProductDiscountProductNum } from "./utils/manualProductDiscount";
|
|
44
|
+
import { hasManualProductDiscountFlag, syncManualProductDiscountProductNum, buildManualProductDiscountItem, findManualProductDiscountItem, mergeManualProductDiscountIntoList } from "./utils/manualProductDiscount";
|
|
44
45
|
import { expandHydratedProductsForDiscountCollection, restoreHydratedBundleDiscounts } from "./utils/bundleDiscountHydration";
|
|
45
46
|
import { getOrderCollectionPersistentId, getOrderCollectionUid, normalizeOrderCollections, repairDuplicateProductLineIdentities as repairDuplicateOrderProductLineIdentities, setOrderCollectionUid } from "./utils/orderCollectionIdentity";
|
|
46
47
|
import { consolidateDiscountFreeProductLines, ensureUniqueProductLineUids } from "./utils/discountProductLineIdentity";
|
|
@@ -936,7 +937,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
936
937
|
},
|
|
937
938
|
orderTotalAmount: Number(((_this$store$summary2 = this.store.summary) === null || _this$store$summary2 === void 0 ? void 0 : _this$store$summary2.total_amount) || 0)
|
|
938
939
|
}, {
|
|
939
|
-
reapplyBookingDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids
|
|
940
|
+
reapplyBookingDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids,
|
|
941
|
+
reapplyWeighedDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyWeighedDiscountProductUids
|
|
940
942
|
});
|
|
941
943
|
if (result !== null && result !== void 0 && result.productList) {
|
|
942
944
|
var previousProductsByUid = indexOrderProductsByUid(tempOrder.products);
|
|
@@ -5125,8 +5127,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5125
5127
|
}
|
|
5126
5128
|
}, {
|
|
5127
5129
|
key: "applyOrderProductUpdateToTempOrder",
|
|
5128
|
-
value: function applyOrderProductUpdateToTempOrder(tempOrder, params) {
|
|
5129
|
-
var _targetProduct$metada2, _product_sku, _metadata2, _metadata3, _metadata4, _metadata5, _metadata6, _metadata7, _metadata8, _metadata9, _metadata10, _nextProduct$
|
|
5130
|
+
value: function applyOrderProductUpdateToTempOrder(tempOrder, params, reapplyWeighedDiscountProductUids) {
|
|
5131
|
+
var _targetProduct$metada2, _product_sku, _metadata2, _metadata3, _metadata4, _metadata5, _metadata6, _metadata7, _metadata8, _metadata9, _metadata10, _nextProduct$metadata2, _targetProduct$metada20, _tempOrder$products$p, _tempOrder$products$p2;
|
|
5130
5132
|
var product_id = params.product_id,
|
|
5131
5133
|
product_variant_id = params.product_variant_id,
|
|
5132
5134
|
updates = params.updates,
|
|
@@ -5192,7 +5194,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5192
5194
|
var previousLineFingerprint = buildProductLineFingerprint(getProductSkuOptions(targetProduct), targetProduct.product_bundle);
|
|
5193
5195
|
var nextLineFingerprint = buildProductLineFingerprint(getProductSkuOptions(nextProduct), nextProduct.product_bundle);
|
|
5194
5196
|
var callerChangesVariant = Number(product_variant_id || 0) !== Number(targetProduct.product_variant_id || 0);
|
|
5195
|
-
var
|
|
5197
|
+
var callerChangesWeighing = getWeighedProductPriceFingerprint(targetProduct.product_sku) !== getWeighedProductPriceFingerprint(nextProduct.product_sku);
|
|
5198
|
+
var callerChangesLineConfiguration = callerChangesVariant || callerChangesWeighing || previousLineFingerprint !== nextLineFingerprint;
|
|
5196
5199
|
var isPersistedOrderLine = targetProduct.order_detail_id !== undefined && targetProduct.order_detail_id !== null;
|
|
5197
5200
|
var callerChangesDiscountList = Array.isArray(updates === null || updates === void 0 ? void 0 : updates.discount_list) && updates.discount_list.length > 0 && !isSameDiscountList(updates.discount_list, targetProduct.discount_list);
|
|
5198
5201
|
var callerUpdatesManualPrice = (updates === null || updates === void 0 || (_metadata8 = updates.metadata) === null || _metadata8 === void 0 ? void 0 : _metadata8.price_override) !== undefined || (updates === null || updates === void 0 || (_metadata9 = updates.metadata) === null || _metadata9 === void 0 ? void 0 : _metadata9.is_manual_discount) !== undefined || (updates === null || updates === void 0 || (_metadata10 = updates.metadata) === null || _metadata10 === void 0 ? void 0 : _metadata10.product_discount_reason) !== undefined || callerChangesDiscountList;
|
|
@@ -5208,33 +5211,50 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5208
5211
|
};
|
|
5209
5212
|
return hasChangedPrice(updates.selling_price, targetProduct.selling_price) || hasChangedPrice(updates.original_price, targetProduct.original_price);
|
|
5210
5213
|
}();
|
|
5214
|
+
var weighedSourcePrice = callerChangesWeighing ? resolveWeighedSourcePrice(nextProduct.product_sku) : undefined;
|
|
5215
|
+
var hasResolvedWeighedPrice = weighedSourcePrice !== undefined;
|
|
5216
|
+
if (hasResolvedWeighedPrice && !callerUpdatesSourcePrice) {
|
|
5217
|
+
var _ref71, _targetProduct$metada3, _targetProduct$metada4, _ref72, _targetProduct$metada5, _targetProduct$metada6;
|
|
5218
|
+
var nextMainOriginal = new Decimal(weighedSourcePrice).plus(sumOptionUnitPrice(getProductSkuOptions(nextProduct)));
|
|
5219
|
+
var previousMainOriginal = new Decimal((_ref71 = (_targetProduct$metada3 = (_targetProduct$metada4 = targetProduct.metadata) === null || _targetProduct$metada4 === void 0 ? void 0 : _targetProduct$metada4.main_product_original_price) !== null && _targetProduct$metada3 !== void 0 ? _targetProduct$metada3 : targetProduct.original_price) !== null && _ref71 !== void 0 ? _ref71 : 0);
|
|
5220
|
+
var previousMainSelling = new Decimal((_ref72 = (_targetProduct$metada5 = (_targetProduct$metada6 = targetProduct.metadata) === null || _targetProduct$metada6 === void 0 ? void 0 : _targetProduct$metada6.main_product_selling_price) !== null && _targetProduct$metada5 !== void 0 ? _targetProduct$metada5 : targetProduct.selling_price) !== null && _ref72 !== void 0 ? _ref72 : 0);
|
|
5221
|
+
// A manual final price remains fixed; other legacy discounts keep their amount
|
|
5222
|
+
// until Rules reapplies the currently selected wallet discount below.
|
|
5223
|
+
var nextMainSelling = isManualProductDiscountProduct(nextProduct) ? previousMainSelling : nextMainOriginal.minus(previousMainOriginal.minus(previousMainSelling));
|
|
5224
|
+
nextProduct.metadata = _objectSpread(_objectSpread({}, nextProduct.metadata), {}, {
|
|
5225
|
+
source_product_price: weighedSourcePrice,
|
|
5226
|
+
main_product_original_price: callerUpdatesMainOriginalPrice ? nextProduct.metadata.main_product_original_price : nextMainOriginal.toFixed(2),
|
|
5227
|
+
main_product_selling_price: callerUpdatesMainSellingPrice ? nextProduct.metadata.main_product_selling_price : Decimal.max(0, nextMainSelling).toFixed(2),
|
|
5228
|
+
price_schema_version: 2
|
|
5229
|
+
});
|
|
5230
|
+
}
|
|
5211
5231
|
if (isPersistedOrderLine && !callerChangesLineConfiguration && !callerUpdatesManualPrice && !callerAllowsBookingReprice) {
|
|
5212
|
-
var _targetProduct$
|
|
5232
|
+
var _targetProduct$metada7, _targetProduct$metada8, _targetProduct$metada9, _targetProduct$metada10, _targetProduct$metada11;
|
|
5213
5233
|
nextProduct.selling_price = targetProduct.selling_price;
|
|
5214
5234
|
nextProduct.original_price = targetProduct.original_price;
|
|
5215
5235
|
nextProduct.payment_price = targetProduct.payment_price;
|
|
5216
5236
|
nextProduct.metadata = _objectSpread(_objectSpread({}, nextProduct.metadata || {}), {}, {
|
|
5217
|
-
source_product_price: (_targetProduct$
|
|
5218
|
-
main_product_selling_price: (_targetProduct$
|
|
5219
|
-
main_product_original_price: (_targetProduct$
|
|
5220
|
-
price_schema_version: (_targetProduct$
|
|
5237
|
+
source_product_price: (_targetProduct$metada7 = targetProduct.metadata) === null || _targetProduct$metada7 === void 0 ? void 0 : _targetProduct$metada7.source_product_price,
|
|
5238
|
+
main_product_selling_price: (_targetProduct$metada8 = targetProduct.metadata) === null || _targetProduct$metada8 === void 0 ? void 0 : _targetProduct$metada8.main_product_selling_price,
|
|
5239
|
+
main_product_original_price: (_targetProduct$metada9 = targetProduct.metadata) === null || _targetProduct$metada9 === void 0 ? void 0 : _targetProduct$metada9.main_product_original_price,
|
|
5240
|
+
price_schema_version: (_targetProduct$metada10 = (_targetProduct$metada11 = targetProduct.metadata) === null || _targetProduct$metada11 === void 0 ? void 0 : _targetProduct$metada11.price_schema_version) !== null && _targetProduct$metada10 !== void 0 ? _targetProduct$metada10 : 2
|
|
5221
5241
|
});
|
|
5222
5242
|
nextProduct.product_bundle = this.preservePersistedBundlePriceFields(targetProduct.product_bundle, nextProduct.product_bundle);
|
|
5223
5243
|
} else if (callerChangesLineConfiguration && callerUpdatesSourcePrice && (!callerUpdatesMainSellingPrice || !callerUpdatesMainOriginalPrice)) {
|
|
5224
|
-
var _targetProduct$
|
|
5244
|
+
var _targetProduct$metada12, _targetProduct$metada13, _targetProduct$metada14;
|
|
5225
5245
|
// 新配置只传了 source 时,不能把未传的 main_product_* 从旧行继承下来。
|
|
5226
5246
|
// 以新 source + 新 option 重建券前价;券后价未显式提供时保留旧主商品折扣额。
|
|
5227
|
-
var
|
|
5228
|
-
var
|
|
5229
|
-
var preservedDiscount =
|
|
5230
|
-
var
|
|
5247
|
+
var _previousMainOriginal = new Decimal(Number((_targetProduct$metada12 = targetProduct.metadata) === null || _targetProduct$metada12 === void 0 ? void 0 : _targetProduct$metada12.main_product_original_price) || 0);
|
|
5248
|
+
var _previousMainSelling = new Decimal(Number((_targetProduct$metada13 = (_targetProduct$metada14 = targetProduct.metadata) === null || _targetProduct$metada14 === void 0 ? void 0 : _targetProduct$metada14.main_product_selling_price) !== null && _targetProduct$metada13 !== void 0 ? _targetProduct$metada13 : _previousMainOriginal.toNumber()));
|
|
5249
|
+
var preservedDiscount = _previousMainOriginal.minus(_previousMainSelling);
|
|
5250
|
+
var _nextMainOriginal = new Decimal(Number(updates.metadata.source_product_price) || 0).plus(sumOptionUnitPrice(getProductSkuOptions(nextProduct)));
|
|
5231
5251
|
nextProduct.metadata = _objectSpread(_objectSpread({}, nextProduct.metadata || {}), {}, {
|
|
5232
5252
|
source_product_price: String(updates.metadata.source_product_price),
|
|
5233
|
-
main_product_original_price: callerUpdatesMainOriginalPrice ? String(updates.metadata.main_product_original_price) :
|
|
5234
|
-
main_product_selling_price: callerUpdatesMainSellingPrice ? String(updates.metadata.main_product_selling_price) :
|
|
5253
|
+
main_product_original_price: callerUpdatesMainOriginalPrice ? String(updates.metadata.main_product_original_price) : _nextMainOriginal.toDecimalPlaces(2).toFixed(2),
|
|
5254
|
+
main_product_selling_price: callerUpdatesMainSellingPrice ? String(updates.metadata.main_product_selling_price) : hasResolvedWeighedPrice && isManualProductDiscountProduct(nextProduct) ? _previousMainSelling.toFixed(2) : _nextMainOriginal.minus(preservedDiscount).toDecimalPlaces(2).toFixed(2),
|
|
5235
5255
|
price_schema_version: 2
|
|
5236
5256
|
});
|
|
5237
|
-
} else if (callerChangesVariant && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
|
|
5257
|
+
} else if (callerChangesVariant && !hasResolvedWeighedPrice && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
|
|
5238
5258
|
// variant 已变化但 caller 没有显式报价时,旧 v2 metadata 不能继续充当权威价格源。
|
|
5239
5259
|
// 清理后由 normalize 优先读取 metadata.origin.variant 中新 variant 的目录价;
|
|
5240
5260
|
// 顶层 original/selling 的旧差额仍会作为 legacy discount 迁移到新价格。
|
|
@@ -5244,24 +5264,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5244
5264
|
delete nextProduct.metadata.main_product_selling_price;
|
|
5245
5265
|
delete nextProduct.metadata.main_product_original_price;
|
|
5246
5266
|
delete nextProduct.metadata.price_schema_version;
|
|
5247
|
-
} else if (callerChangesLineConfiguration && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
|
|
5248
|
-
var
|
|
5267
|
+
} else if (callerChangesLineConfiguration && !hasResolvedWeighedPrice && !callerUpdatesTopPrice && !callerUpdatesMainMeta) {
|
|
5268
|
+
var _ref73, _targetProduct$metada15, _targetProduct$metada16, _ref74, _targetProduct$metada17, _targetProduct$metada18, _targetProduct$metada19;
|
|
5249
5269
|
// 仅 option / bundle 变化时,保留历史 source 和主商品折扣金额,
|
|
5250
5270
|
// 但必须让 original 与 selling 一起随新的 option 金额移动。
|
|
5251
5271
|
var previousOptionSum = sumOptionUnitPrice(getProductSkuOptions(targetProduct));
|
|
5252
5272
|
var nextOptionSum = sumOptionUnitPrice(getProductSkuOptions(nextProduct));
|
|
5253
|
-
var
|
|
5254
|
-
var
|
|
5255
|
-
var _preservedDiscount =
|
|
5256
|
-
var previousSource = ((_targetProduct$
|
|
5257
|
-
var
|
|
5273
|
+
var _previousMainOriginal2 = new Decimal(Number((_ref73 = (_targetProduct$metada15 = (_targetProduct$metada16 = targetProduct.metadata) === null || _targetProduct$metada16 === void 0 ? void 0 : _targetProduct$metada16.main_product_original_price) !== null && _targetProduct$metada15 !== void 0 ? _targetProduct$metada15 : targetProduct.original_price) !== null && _ref73 !== void 0 ? _ref73 : 0) || 0);
|
|
5274
|
+
var _previousMainSelling2 = new Decimal(Number((_ref74 = (_targetProduct$metada17 = (_targetProduct$metada18 = targetProduct.metadata) === null || _targetProduct$metada18 === void 0 ? void 0 : _targetProduct$metada18.main_product_selling_price) !== null && _targetProduct$metada17 !== void 0 ? _targetProduct$metada17 : targetProduct.selling_price) !== null && _ref74 !== void 0 ? _ref74 : _previousMainOriginal2.toNumber()) || 0);
|
|
5275
|
+
var _preservedDiscount = _previousMainOriginal2.minus(_previousMainSelling2);
|
|
5276
|
+
var previousSource = ((_targetProduct$metada19 = targetProduct.metadata) === null || _targetProduct$metada19 === void 0 ? void 0 : _targetProduct$metada19.source_product_price) != null ? new Decimal(Number(targetProduct.metadata.source_product_price) || 0) : _previousMainOriginal2.minus(previousOptionSum);
|
|
5277
|
+
var _nextMainOriginal2 = previousSource.plus(nextOptionSum);
|
|
5258
5278
|
nextProduct.metadata = _objectSpread(_objectSpread({}, nextProduct.metadata || {}), {}, {
|
|
5259
5279
|
source_product_price: previousSource.toDecimalPlaces(2).toFixed(2),
|
|
5260
|
-
main_product_original_price:
|
|
5261
|
-
main_product_selling_price:
|
|
5280
|
+
main_product_original_price: _nextMainOriginal2.toDecimalPlaces(2).toFixed(2),
|
|
5281
|
+
main_product_selling_price: _nextMainOriginal2.minus(_preservedDiscount).toDecimalPlaces(2).toFixed(2),
|
|
5262
5282
|
price_schema_version: 2
|
|
5263
5283
|
});
|
|
5264
|
-
} else if (callerUpdatesTopPrice && !callerUpdatesMainMeta) {
|
|
5284
|
+
} else if (callerUpdatesTopPrice && !callerUpdatesMainMeta && !hasResolvedWeighedPrice) {
|
|
5265
5285
|
var _existedMeta = nextProduct.metadata || {};
|
|
5266
5286
|
nextProduct.metadata = _objectSpread({}, _existedMeta);
|
|
5267
5287
|
delete nextProduct.metadata.source_product_price;
|
|
@@ -5269,11 +5289,40 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5269
5289
|
delete nextProduct.metadata.main_product_original_price;
|
|
5270
5290
|
delete nextProduct.metadata.price_schema_version;
|
|
5271
5291
|
}
|
|
5292
|
+
if (callerChangesLineConfiguration && resolveWeighedSourcePrice(nextProduct.product_sku) !== undefined && nextProduct.metadata.main_product_original_price != null && nextProduct.metadata.main_product_selling_price != null && isManualProductDiscountProduct(nextProduct)) {
|
|
5293
|
+
var _nextProduct$metadata;
|
|
5294
|
+
var originalPrice = composeLinePrice({
|
|
5295
|
+
mainPrice: nextProduct.metadata.main_product_original_price,
|
|
5296
|
+
bundle: withOriginalBundleOptionPrices(nextProduct.product_bundle),
|
|
5297
|
+
useOriginalBundle: true
|
|
5298
|
+
});
|
|
5299
|
+
var sellingPrice = composeLinePrice({
|
|
5300
|
+
mainPrice: nextProduct.metadata.main_product_selling_price,
|
|
5301
|
+
bundle: nextProduct.product_bundle
|
|
5302
|
+
});
|
|
5303
|
+
var previousManualDiscount = findManualProductDiscountItem(nextProduct.discount_list);
|
|
5304
|
+
nextProduct.original_price = originalPrice;
|
|
5305
|
+
nextProduct.metadata = _objectSpread(_objectSpread({}, nextProduct.metadata), {}, {
|
|
5306
|
+
origin: _objectSpread(_objectSpread({}, nextProduct.metadata.origin), {}, {
|
|
5307
|
+
_extend: _objectSpread(_objectSpread({}, (_nextProduct$metadata = nextProduct.metadata.origin) === null || _nextProduct$metadata === void 0 ? void 0 : _nextProduct$metadata._extend), {}, {
|
|
5308
|
+
origin_total: Number(originalPrice)
|
|
5309
|
+
})
|
|
5310
|
+
})
|
|
5311
|
+
});
|
|
5312
|
+
nextProduct.discount_list = mergeManualProductDiscountIntoList(nextProduct.discount_list, buildManualProductDiscountItem({
|
|
5313
|
+
originTotal: Number(originalPrice),
|
|
5314
|
+
sellingTotal: Number(sellingPrice),
|
|
5315
|
+
quantity: nextProduct.num,
|
|
5316
|
+
message: previousManualDiscount === null || previousManualDiscount === void 0 ? void 0 : previousManualDiscount.discount.message,
|
|
5317
|
+
discountway: previousManualDiscount === null || previousManualDiscount === void 0 ? void 0 : previousManualDiscount.discount.discountway,
|
|
5318
|
+
discount_per: previousManualDiscount === null || previousManualDiscount === void 0 ? void 0 : previousManualDiscount.discount.discount_per
|
|
5319
|
+
}));
|
|
5320
|
+
}
|
|
5272
5321
|
// normalizeOrderProduct 幂等:v2 metadata 存在 → 保留 main_product_* 折扣重算 composite;
|
|
5273
5322
|
// 否则 → 把顶层 selling_price 视作 source,派生 main_product_* 并写 price_schema_version: 2。
|
|
5274
5323
|
var normalizedProduct = this.normalizeVirtualSettlementProductIfEnabled(mergeOrderProductDisplayFields(nextProduct, normalizeOrderProduct(nextProduct)));
|
|
5275
5324
|
normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
|
|
5276
|
-
var preservedBookingUid = nextProduct.booking_uid || ((_nextProduct$
|
|
5325
|
+
var preservedBookingUid = nextProduct.booking_uid || ((_nextProduct$metadata2 = nextProduct.metadata) === null || _nextProduct$metadata2 === void 0 ? void 0 : _nextProduct$metadata2.booking_uid) || targetProduct.booking_uid || ((_targetProduct$metada20 = targetProduct.metadata) === null || _targetProduct$metada20 === void 0 ? void 0 : _targetProduct$metada20.booking_uid);
|
|
5277
5326
|
if (!booking && preservedBookingUid) {
|
|
5278
5327
|
normalizedProduct.booking_uid = preservedBookingUid;
|
|
5279
5328
|
normalizedProduct.metadata = _objectSpread(_objectSpread({}, normalizedProduct.metadata || {}), {}, {
|
|
@@ -5281,8 +5330,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5281
5330
|
});
|
|
5282
5331
|
}
|
|
5283
5332
|
if (booking) {
|
|
5284
|
-
var _normalizedProduct$me, _targetProduct$
|
|
5285
|
-
var productUid = String(((_normalizedProduct$me = normalizedProduct.metadata) === null || _normalizedProduct$me === void 0 ? void 0 : _normalizedProduct$me.unique_identification_number) || ((_targetProduct$
|
|
5333
|
+
var _normalizedProduct$me, _targetProduct$metada21;
|
|
5334
|
+
var productUid = String(((_normalizedProduct$me = normalizedProduct.metadata) === null || _normalizedProduct$me === void 0 ? void 0 : _normalizedProduct$me.unique_identification_number) || ((_targetProduct$metada21 = targetProduct.metadata) === null || _targetProduct$metada21 === void 0 ? void 0 : _targetProduct$metada21.unique_identification_number) || unique_identification_number || createUuidV4());
|
|
5286
5335
|
normalizedProduct.metadata = _objectSpread(_objectSpread({}, normalizedProduct.metadata || {}), {}, {
|
|
5287
5336
|
unique_identification_number: productUid
|
|
5288
5337
|
});
|
|
@@ -5302,6 +5351,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5302
5351
|
});
|
|
5303
5352
|
tempOrder.bookings = [].concat(_toConsumableArray(tempOrder.bookings || []), [linked.booking]);
|
|
5304
5353
|
}
|
|
5354
|
+
if (callerChangesWeighing && !isManualProductDiscountProduct(normalizedProduct)) {
|
|
5355
|
+
var _normalizedProduct$me2;
|
|
5356
|
+
var uid = (_normalizedProduct$me2 = normalizedProduct.metadata) === null || _normalizedProduct$me2 === void 0 ? void 0 : _normalizedProduct$me2.unique_identification_number;
|
|
5357
|
+
if (uid) reapplyWeighedDiscountProductUids === null || reapplyWeighedDiscountProductUids === void 0 || reapplyWeighedDiscountProductUids.push(String(uid));
|
|
5358
|
+
}
|
|
5305
5359
|
tempOrder.products[productIndex] = normalizedProduct;
|
|
5306
5360
|
this.syncTempOrderHolderFromBookings(tempOrder);
|
|
5307
5361
|
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);
|
|
@@ -5311,32 +5365,34 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5311
5365
|
key: "updateOrderProduct",
|
|
5312
5366
|
value: function () {
|
|
5313
5367
|
var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(params) {
|
|
5314
|
-
var tempOrder, updatedProductUid, promotionPayload;
|
|
5368
|
+
var tempOrder, reapplyWeighedDiscountProductUids, updatedProductUid, promotionPayload;
|
|
5315
5369
|
return _regeneratorRuntime().wrap(function _callee25$(_context27) {
|
|
5316
5370
|
while (1) switch (_context27.prev = _context27.next) {
|
|
5317
5371
|
case 0:
|
|
5318
5372
|
tempOrder = this.ensureTempOrder();
|
|
5319
|
-
|
|
5320
|
-
|
|
5373
|
+
reapplyWeighedDiscountProductUids = [];
|
|
5374
|
+
updatedProductUid = this.applyOrderProductUpdateToTempOrder(tempOrder, params, reapplyWeighedDiscountProductUids);
|
|
5375
|
+
_context27.next = 5;
|
|
5321
5376
|
return this.evaluatePromotion();
|
|
5322
|
-
case
|
|
5377
|
+
case 5:
|
|
5323
5378
|
promotionPayload = _context27.sent;
|
|
5324
5379
|
this.applyDiscount({
|
|
5380
|
+
reapplyWeighedDiscountProductUids: reapplyWeighedDiscountProductUids,
|
|
5325
5381
|
reapplyBookingDiscountProductUids: params.allow_booking_discount_reapply && updatedProductUid ? [String(updatedProductUid)] : undefined
|
|
5326
5382
|
});
|
|
5327
5383
|
this.sanitizeTempOrderProducts(tempOrder);
|
|
5328
|
-
_context27.next =
|
|
5384
|
+
_context27.next = 10;
|
|
5329
5385
|
return this.recalculateSummary({
|
|
5330
5386
|
createIfMissing: true
|
|
5331
5387
|
});
|
|
5332
|
-
case
|
|
5388
|
+
case 10:
|
|
5333
5389
|
this.persistTempOrder();
|
|
5334
5390
|
this.emitPromotionApplied(promotionPayload);
|
|
5335
5391
|
this.logInfo('updateOrderProduct success', {
|
|
5336
5392
|
params: params
|
|
5337
5393
|
});
|
|
5338
5394
|
return _context27.abrupt("return", tempOrder.products);
|
|
5339
|
-
case
|
|
5395
|
+
case 14:
|
|
5340
5396
|
case "end":
|
|
5341
5397
|
return _context27.stop();
|
|
5342
5398
|
}
|
|
@@ -5352,7 +5408,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5352
5408
|
value: function () {
|
|
5353
5409
|
var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(paramsList) {
|
|
5354
5410
|
var _this32 = this;
|
|
5355
|
-
var tempOrder, reapplyBookingDiscountProductUids;
|
|
5411
|
+
var tempOrder, reapplyWeighedDiscountProductUids, reapplyBookingDiscountProductUids;
|
|
5356
5412
|
return _regeneratorRuntime().wrap(function _callee26$(_context28) {
|
|
5357
5413
|
while (1) switch (_context28.prev = _context28.next) {
|
|
5358
5414
|
case 0:
|
|
@@ -5363,24 +5419,26 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5363
5419
|
}
|
|
5364
5420
|
return _context28.abrupt("return", tempOrder.products);
|
|
5365
5421
|
case 3:
|
|
5422
|
+
reapplyWeighedDiscountProductUids = [];
|
|
5366
5423
|
reapplyBookingDiscountProductUids = paramsList.reduce(function (acc, params) {
|
|
5367
|
-
var updatedProductUid = _this32.applyOrderProductUpdateToTempOrder(tempOrder, params);
|
|
5424
|
+
var updatedProductUid = _this32.applyOrderProductUpdateToTempOrder(tempOrder, params, reapplyWeighedDiscountProductUids);
|
|
5368
5425
|
// 批量改预约时间时,延迟到最后一次折扣计算里统一恢复已选预约折扣卡。
|
|
5369
5426
|
if (params.allow_booking_discount_reapply && updatedProductUid) {
|
|
5370
5427
|
acc.push(String(updatedProductUid));
|
|
5371
5428
|
}
|
|
5372
5429
|
return acc;
|
|
5373
5430
|
}, []);
|
|
5374
|
-
_context28.next =
|
|
5431
|
+
_context28.next = 7;
|
|
5375
5432
|
return this.finalizeAfterProductsMutation(tempOrder, {
|
|
5433
|
+
reapplyWeighedDiscountProductUids: reapplyWeighedDiscountProductUids,
|
|
5376
5434
|
reapplyBookingDiscountProductUids: reapplyBookingDiscountProductUids.length ? reapplyBookingDiscountProductUids : undefined
|
|
5377
5435
|
});
|
|
5378
|
-
case
|
|
5436
|
+
case 7:
|
|
5379
5437
|
this.logInfo('updateOrderProduct success', {
|
|
5380
5438
|
paramsList: paramsList
|
|
5381
5439
|
});
|
|
5382
5440
|
return _context28.abrupt("return", tempOrder.products);
|
|
5383
|
-
case
|
|
5441
|
+
case 9:
|
|
5384
5442
|
case "end":
|
|
5385
5443
|
return _context28.stop();
|
|
5386
5444
|
}
|
|
@@ -5395,7 +5453,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5395
5453
|
key: "updateOrderProductQuantity",
|
|
5396
5454
|
value: function () {
|
|
5397
5455
|
var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(params) {
|
|
5398
|
-
var _targetProduct$
|
|
5456
|
+
var _targetProduct$metada22;
|
|
5399
5457
|
var product_id, product_variant_id, num, unique_identification_number, identity_key, product_sku, product_bundle, tempOrder, identityLookup, productIndex, targetUid, targetProduct, normalizedProduct, settlementSnapshot, currencyProductId, asset, requiredAmount, balance, isVirtualSettlement, promotionPayload;
|
|
5400
5458
|
return _regeneratorRuntime().wrap(function _callee27$(_context29) {
|
|
5401
5459
|
while (1) switch (_context29.prev = _context29.next) {
|
|
@@ -5437,7 +5495,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5437
5495
|
normalizedProduct = this.normalizeVirtualSettlementProductIfEnabled(normalizeOrderProduct(_objectSpread(_objectSpread({}, targetProduct), {}, {
|
|
5438
5496
|
num: getSafeProductNum(num),
|
|
5439
5497
|
metadata: _objectSpread(_objectSpread({}, targetProduct.metadata || {}), {}, {
|
|
5440
|
-
unique_identification_number: ((_targetProduct$
|
|
5498
|
+
unique_identification_number: ((_targetProduct$metada22 = targetProduct.metadata) === null || _targetProduct$metada22 === void 0 ? void 0 : _targetProduct$metada22.unique_identification_number) || unique_identification_number
|
|
5441
5499
|
})
|
|
5442
5500
|
})));
|
|
5443
5501
|
normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
|
|
@@ -5558,7 +5616,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5558
5616
|
case 3:
|
|
5559
5617
|
promotionPayload = _context30.sent;
|
|
5560
5618
|
this.applyDiscount({
|
|
5561
|
-
reapplyBookingDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids
|
|
5619
|
+
reapplyBookingDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids,
|
|
5620
|
+
reapplyWeighedDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyWeighedDiscountProductUids
|
|
5562
5621
|
});
|
|
5563
5622
|
this.sanitizeTempOrderProducts(tempOrder);
|
|
5564
5623
|
_context30.next = 8;
|
|
@@ -5870,23 +5929,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
5870
5929
|
}, {
|
|
5871
5930
|
key: "buildCurrentSubmitPayloadForLocalPrint",
|
|
5872
5931
|
value: function buildCurrentSubmitPayloadForLocalPrint(params) {
|
|
5873
|
-
var _params$cacheId, _this$otherParams5,
|
|
5932
|
+
var _params$cacheId, _this$otherParams5, _ref75, _params$businessCode, _this$otherParams6, _this$otherParams7;
|
|
5874
5933
|
var tempOrder = this.ensureTempOrder();
|
|
5875
5934
|
this.persistTempOrder();
|
|
5876
5935
|
var payload = buildSubmitPayload({
|
|
5877
5936
|
tempOrder: tempOrder,
|
|
5878
5937
|
cacheId: (_params$cacheId = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId !== void 0 ? _params$cacheId : this.cacheId,
|
|
5879
5938
|
platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams5 = this.otherParams) === null || _this$otherParams5 === void 0 ? void 0 : _this$otherParams5.platform),
|
|
5880
|
-
businessCode: (
|
|
5939
|
+
businessCode: (_ref75 = (_params$businessCode = params === null || params === void 0 ? void 0 : params.businessCode) !== null && _params$businessCode !== void 0 ? _params$businessCode : (_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.businessCode) !== null && _ref75 !== void 0 ? _ref75 : (_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.business_code,
|
|
5881
5940
|
channel: params === null || params === void 0 ? void 0 : params.channel,
|
|
5882
5941
|
type: params === null || params === void 0 ? void 0 : params.type,
|
|
5883
5942
|
summary: this.store.summary || createEmptySummary(),
|
|
5884
5943
|
enhance: function enhance(nextPayload) {
|
|
5885
|
-
var
|
|
5944
|
+
var _ref76, _tempOrder$order_numb, _ref77, _tempOrder$shop_order2, _ref78, _tempOrder$shop_full_;
|
|
5886
5945
|
return _objectSpread(_objectSpread({}, nextPayload), {}, {
|
|
5887
|
-
order_number: (
|
|
5888
|
-
shop_order_number: (
|
|
5889
|
-
shop_full_order_number: (
|
|
5946
|
+
order_number: (_ref76 = (_tempOrder$order_numb = tempOrder.order_number) !== null && _tempOrder$order_numb !== void 0 ? _tempOrder$order_numb : nextPayload.order_number) !== null && _ref76 !== void 0 ? _ref76 : null,
|
|
5947
|
+
shop_order_number: (_ref77 = (_tempOrder$shop_order2 = tempOrder.shop_order_number) !== null && _tempOrder$shop_order2 !== void 0 ? _tempOrder$shop_order2 : nextPayload.shop_order_number) !== null && _ref77 !== void 0 ? _ref77 : null,
|
|
5948
|
+
shop_full_order_number: (_ref78 = (_tempOrder$shop_full_ = tempOrder.shop_full_order_number) !== null && _tempOrder$shop_full_ !== void 0 ? _tempOrder$shop_full_ : nextPayload.shop_full_order_number) !== null && _ref78 !== void 0 ? _ref78 : null,
|
|
5890
5949
|
small_ticket_data_flag: 1
|
|
5891
5950
|
});
|
|
5892
5951
|
}
|
|
@@ -6050,7 +6109,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
6050
6109
|
key: "runSubmitTempOrder",
|
|
6051
6110
|
value: function () {
|
|
6052
6111
|
var _runSubmitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(params) {
|
|
6053
|
-
var _params$cacheId3, _this$otherParams12,
|
|
6112
|
+
var _params$cacheId3, _this$otherParams12, _ref79, _ref80, _submitSnapshot$busin, _this$otherParams13, _this$otherParams14, _submitSnapshot$type;
|
|
6054
6113
|
var tempOrder, isOnlineStorePlatform, shouldConfirmPendingVoucherPayments, hasPaymentOverride, preparedPaymentOverride, latestSummary, effectiveCacheId, hasPaymentStatusOverride, shouldOverridePaymentStatus, hasSmallTicketDataFlagOverride, enhancePayload, submitSnapshot, payload, result, _payload$payments, _payload$payments2, backendErrorResponse, isLocalPendingSubmit, salesNotesState, submittedOrderId, resultRecord;
|
|
6055
6114
|
return _regeneratorRuntime().wrap(function _callee37$(_context40) {
|
|
6056
6115
|
while (1) switch (_context40.prev = _context40.next) {
|
|
@@ -6117,7 +6176,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
6117
6176
|
tempOrder: tempOrder,
|
|
6118
6177
|
cacheId: effectiveCacheId,
|
|
6119
6178
|
platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams12 = this.otherParams) === null || _this$otherParams12 === void 0 ? void 0 : _this$otherParams12.platform),
|
|
6120
|
-
businessCode: (
|
|
6179
|
+
businessCode: (_ref79 = (_ref80 = (_submitSnapshot$busin = submitSnapshot.businessCode) !== null && _submitSnapshot$busin !== void 0 ? _submitSnapshot$busin : params === null || params === void 0 ? void 0 : params.businessCode) !== null && _ref80 !== void 0 ? _ref80 : (_this$otherParams13 = this.otherParams) === null || _this$otherParams13 === void 0 ? void 0 : _this$otherParams13.businessCode) !== null && _ref79 !== void 0 ? _ref79 : (_this$otherParams14 = this.otherParams) === null || _this$otherParams14 === void 0 ? void 0 : _this$otherParams14.business_code,
|
|
6121
6180
|
channel: params === null || params === void 0 ? void 0 : params.channel,
|
|
6122
6181
|
type: (_submitSnapshot$type = submitSnapshot.type) !== null && _submitSnapshot$type !== void 0 ? _submitSnapshot$type : params === null || params === void 0 ? void 0 : params.type,
|
|
6123
6182
|
summary: latestSummary,
|
|
@@ -7222,7 +7281,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
7222
7281
|
_step24;
|
|
7223
7282
|
try {
|
|
7224
7283
|
for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
|
|
7225
|
-
var _product$metadata12,
|
|
7284
|
+
var _product$metadata12, _ref81, _ref82, _existed$origin, _rawProduct$metadata;
|
|
7226
7285
|
var _step24$value = _slicedToArray(_step24.value, 2),
|
|
7227
7286
|
index = _step24$value[0],
|
|
7228
7287
|
product = _step24$value[1];
|
|
@@ -7230,7 +7289,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
7230
7289
|
if (!uid) continue;
|
|
7231
7290
|
var existed = productsByUid[uid] && _typeof(productsByUid[uid]) === 'object' ? productsByUid[uid] : {};
|
|
7232
7291
|
var rawProduct = rawProducts[index] && _typeof(rawProducts[index]) === 'object' ? rawProducts[index] : product;
|
|
7233
|
-
var origin = (
|
|
7292
|
+
var origin = (_ref81 = (_ref82 = (_existed$origin = existed.origin) !== null && _existed$origin !== void 0 ? _existed$origin : rawProduct._origin) !== null && _ref82 !== void 0 ? _ref82 : (_rawProduct$metadata = rawProduct.metadata) === null || _rawProduct$metadata === void 0 ? void 0 : _rawProduct$metadata.origin) !== null && _ref81 !== void 0 ? _ref81 : rawProduct;
|
|
7234
7293
|
var originSnapshot = cloneDeep(origin);
|
|
7235
7294
|
var productOptionString = this.buildHydratedProductOptionString(rawProduct) || this.buildHydratedProductOptionString(product);
|
|
7236
7295
|
if (productOptionString && originSnapshot && _typeof(originSnapshot) === 'object') {
|
|
@@ -7359,10 +7418,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
7359
7418
|
}, {
|
|
7360
7419
|
key: "normalizeHydratedProductOptionItem",
|
|
7361
7420
|
value: function normalizeHydratedProductOptionItem(optionItem) {
|
|
7362
|
-
var
|
|
7363
|
-
var rawNum = (
|
|
7421
|
+
var _ref83, _optionItem$num, _ref84, _optionItem$add_price;
|
|
7422
|
+
var rawNum = (_ref83 = (_optionItem$num = optionItem === null || optionItem === void 0 ? void 0 : optionItem.num) !== null && _optionItem$num !== void 0 ? _optionItem$num : optionItem === null || optionItem === void 0 ? void 0 : optionItem.quantity) !== null && _ref83 !== void 0 ? _ref83 : 1;
|
|
7364
7423
|
var parsedNum = Number(rawNum);
|
|
7365
|
-
var rawPrice = (
|
|
7424
|
+
var rawPrice = (_ref84 = (_optionItem$add_price = optionItem === null || optionItem === void 0 ? void 0 : optionItem.add_price) !== null && _optionItem$add_price !== void 0 ? _optionItem$add_price : optionItem === null || optionItem === void 0 ? void 0 : optionItem.price) !== null && _ref84 !== void 0 ? _ref84 : 0;
|
|
7366
7425
|
var parsedPrice = Number(rawPrice);
|
|
7367
7426
|
var normalized = _objectSpread(_objectSpread({}, optionItem), {}, {
|
|
7368
7427
|
option_group_item_id: optionItem === null || optionItem === void 0 ? void 0 : optionItem.option_group_item_id,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Only pricing/measurement fields participate; display and option data do not. */
|
|
2
|
+
export declare function getWeighedProductPriceFingerprint(sku?: Record<string, any>): string;
|
|
3
|
+
/**
|
|
4
|
+
* A weighed line's source is the amount for its net weight, never its catalog unit price.
|
|
5
|
+
* Persisted SKU measurements and the full catalog snapshot take priority over runtime
|
|
6
|
+
* _extend.weighing, which can survive repricing with an obsolete total_amount.
|
|
7
|
+
*/
|
|
8
|
+
export declare function resolveWeighedSourcePrice(sku?: Record<string, any>, weighing?: Record<string, any>): string | undefined;
|
|
9
|
+
/** Original bundle totals must use the nested options before manual distribution. */
|
|
10
|
+
export declare function withOriginalBundleOptionPrices(bundles?: Array<Record<string, any>>): {
|
|
11
|
+
option: any;
|
|
12
|
+
}[] | undefined;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
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); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
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); }
|
|
7
|
+
import Decimal from 'decimal.js';
|
|
8
|
+
var UNIT_GRAMS = {
|
|
9
|
+
kg: '1000',
|
|
10
|
+
KILOGRAMS: '1000',
|
|
11
|
+
g: '1',
|
|
12
|
+
GRAMS: '1',
|
|
13
|
+
lb: '453.59237',
|
|
14
|
+
POUNDS: '453.59237',
|
|
15
|
+
oz: '28.349523125',
|
|
16
|
+
OUNCES: '28.349523125'
|
|
17
|
+
};
|
|
18
|
+
function nonNegative(value) {
|
|
19
|
+
if (value === null || value === undefined || value === '') return undefined;
|
|
20
|
+
try {
|
|
21
|
+
var result = new Decimal(value);
|
|
22
|
+
return result.isFinite() && result.gte(0) ? result : undefined;
|
|
23
|
+
} catch (_unused) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function numericKey(value) {
|
|
28
|
+
var _nonNegative;
|
|
29
|
+
return (_nonNegative = nonNegative(value)) === null || _nonNegative === void 0 ? void 0 : _nonNegative.toString();
|
|
30
|
+
}
|
|
31
|
+
function unitKey(value) {
|
|
32
|
+
return UNIT_GRAMS[String(value)] || (value == null ? undefined : String(value));
|
|
33
|
+
}
|
|
34
|
+
function snapshotKey(snapshot) {
|
|
35
|
+
var _snapshot$unit_value;
|
|
36
|
+
return [numericKey(snapshot === null || snapshot === void 0 ? void 0 : snapshot.price), unitKey(snapshot === null || snapshot === void 0 ? void 0 : snapshot.unit), numericKey((_snapshot$unit_value = snapshot === null || snapshot === void 0 ? void 0 : snapshot.unit_value) !== null && _snapshot$unit_value !== void 0 ? _snapshot$unit_value : 1)];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Only pricing/measurement fields participate; display and option data do not. */
|
|
40
|
+
export function getWeighedProductPriceFingerprint(sku) {
|
|
41
|
+
var _sku$unit_weight;
|
|
42
|
+
if (Number(sku === null || sku === void 0 ? void 0 : sku.open_sold_weight) !== 1) return 'unweighed';
|
|
43
|
+
return JSON.stringify([1, numericKey(sku === null || sku === void 0 ? void 0 : sku.net_weight), unitKey(sku === null || sku === void 0 ? void 0 : sku.unit), numericKey(sku === null || sku === void 0 ? void 0 : sku.unit_price), numericKey((_sku$unit_weight = sku === null || sku === void 0 ? void 0 : sku.unit_weight) !== null && _sku$unit_weight !== void 0 ? _sku$unit_weight : 1), snapshotKey(sku === null || sku === void 0 ? void 0 : sku.unit_data_snapshot)]);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* A weighed line's source is the amount for its net weight, never its catalog unit price.
|
|
48
|
+
* Persisted SKU measurements and the full catalog snapshot take priority over runtime
|
|
49
|
+
* _extend.weighing, which can survive repricing with an obsolete total_amount.
|
|
50
|
+
*/
|
|
51
|
+
export function resolveWeighedSourcePrice(sku, weighing) {
|
|
52
|
+
var _snapshot$unit_value2, _weighing$unit_weight, _sku$unit_weight2, _measurement$unit_wei;
|
|
53
|
+
if ((sku === null || sku === void 0 ? void 0 : sku.open_sold_weight) != null && Number(sku.open_sold_weight) !== 1) return undefined;
|
|
54
|
+
if (Number(sku === null || sku === void 0 ? void 0 : sku.open_sold_weight) !== 1 && !weighing) return undefined;
|
|
55
|
+
var hasSkuMeasurement = (sku === null || sku === void 0 ? void 0 : sku.net_weight) !== undefined && (sku === null || sku === void 0 ? void 0 : sku.net_weight) !== null;
|
|
56
|
+
var measurement = hasSkuMeasurement ? sku : weighing;
|
|
57
|
+
var netWeight = nonNegative(measurement === null || measurement === void 0 ? void 0 : measurement.net_weight);
|
|
58
|
+
if (netWeight === undefined) return undefined;
|
|
59
|
+
var snapshot = hasSkuMeasurement ? sku === null || sku === void 0 ? void 0 : sku.unit_data_snapshot : weighing === null || weighing === void 0 ? void 0 : weighing.scalePriceProduct;
|
|
60
|
+
var snapshotPrice = nonNegative(snapshot === null || snapshot === void 0 ? void 0 : snapshot.price);
|
|
61
|
+
var snapshotUnits = nonNegative((_snapshot$unit_value2 = snapshot === null || snapshot === void 0 ? void 0 : snapshot.unit_value) !== null && _snapshot$unit_value2 !== void 0 ? _snapshot$unit_value2 : 1);
|
|
62
|
+
var sourceGrams = UNIT_GRAMS[String(snapshot === null || snapshot === void 0 ? void 0 : snapshot.unit)];
|
|
63
|
+
var targetGrams = UNIT_GRAMS[String(measurement === null || measurement === void 0 ? void 0 : measurement.unit)];
|
|
64
|
+
if (snapshotPrice && snapshotUnits !== null && snapshotUnits !== void 0 && snapshotUnits.gt(0) && sourceGrams && targetGrams) {
|
|
65
|
+
return snapshotPrice.mul(netWeight).mul(targetGrams).div(sourceGrams).div(snapshotUnits).toFixed(2);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Legacy callers may only retain the native scale's amount. Do not let an old
|
|
69
|
+
// amount overwrite a changed SKU measurement, unit price, or pricing snapshot.
|
|
70
|
+
var runtimeAmount = nonNegative(weighing === null || weighing === void 0 ? void 0 : weighing.total_amount);
|
|
71
|
+
var runtimeMatchesSku = !hasSkuMeasurement || numericKey(weighing === null || weighing === void 0 ? void 0 : weighing.net_weight) === numericKey(sku === null || sku === void 0 ? void 0 : sku.net_weight) && unitKey(weighing === null || weighing === void 0 ? void 0 : weighing.unit) === unitKey(sku === null || sku === void 0 ? void 0 : sku.unit) && numericKey(weighing === null || weighing === void 0 ? void 0 : weighing.unit_price) === numericKey(sku === null || sku === void 0 ? void 0 : sku.unit_price) && numericKey((_weighing$unit_weight = weighing === null || weighing === void 0 ? void 0 : weighing.unit_weight) !== null && _weighing$unit_weight !== void 0 ? _weighing$unit_weight : 1) === numericKey((_sku$unit_weight2 = sku === null || sku === void 0 ? void 0 : sku.unit_weight) !== null && _sku$unit_weight2 !== void 0 ? _sku$unit_weight2 : 1) && JSON.stringify(snapshotKey(weighing === null || weighing === void 0 ? void 0 : weighing.scalePriceProduct)) === JSON.stringify(snapshotKey(sku === null || sku === void 0 ? void 0 : sku.unit_data_snapshot));
|
|
72
|
+
if (runtimeAmount && runtimeMatchesSku) return runtimeAmount.toFixed(2);
|
|
73
|
+
|
|
74
|
+
// Older persisted orders have only a rounded per-scale-unit price.
|
|
75
|
+
var unitPrice = nonNegative(measurement === null || measurement === void 0 ? void 0 : measurement.unit_price);
|
|
76
|
+
var unitWeight = nonNegative((_measurement$unit_wei = measurement === null || measurement === void 0 ? void 0 : measurement.unit_weight) !== null && _measurement$unit_wei !== void 0 ? _measurement$unit_wei : 1);
|
|
77
|
+
if (!unitPrice || !(unitWeight !== null && unitWeight !== void 0 && unitWeight.gt(0))) return undefined;
|
|
78
|
+
return netWeight.div(unitWeight).mul(unitPrice).toFixed(2);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Original bundle totals must use the nested options before manual distribution. */
|
|
82
|
+
export function withOriginalBundleOptionPrices(bundles) {
|
|
83
|
+
return bundles === null || bundles === void 0 ? void 0 : bundles.map(function (bundle) {
|
|
84
|
+
var _bundle$option;
|
|
85
|
+
return _objectSpread(_objectSpread({}, bundle), {}, {
|
|
86
|
+
option: (_bundle$option = bundle.option) === null || _bundle$option === void 0 ? void 0 : _bundle$option.map(function (option) {
|
|
87
|
+
var _ref, _option$original_pric;
|
|
88
|
+
return _objectSpread(_objectSpread({}, option), {}, {
|
|
89
|
+
add_price: (_ref = (_option$original_pric = option.original_price) !== null && _option$original_pric !== void 0 ? _option$original_pric : option.add_price) !== null && _ref !== void 0 ? _ref : option.price
|
|
90
|
+
});
|
|
91
|
+
})
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
}
|
|
@@ -20,6 +20,8 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
20
20
|
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); }
|
|
21
21
|
import dayjs from "dayjs";
|
|
22
22
|
import Decimal from 'decimal.js';
|
|
23
|
+
import { withOriginalBundleOptionPrices } from "./utils/weighedProduct";
|
|
24
|
+
import { hasManualProductDiscountFlag } from "./utils/manualProductDiscount";
|
|
23
25
|
import { getProductHolderConfig } from "../Holder/utils";
|
|
24
26
|
import { buildProductLineFingerprint, createEmptySummary } from "../../solution/ScanOrder/utils";
|
|
25
27
|
import { createUuidV4 } from "./utils/orderCollectionIdentity";
|
|
@@ -698,7 +700,7 @@ export function createDefaultOrderRulesHooks() {
|
|
|
698
700
|
};
|
|
699
701
|
},
|
|
700
702
|
setProduct: function setProduct(product, values) {
|
|
701
|
-
var _ref23, _values$quantity, _ref24, _metadataAny$source_p, _values$discount_list, _values$quantity2;
|
|
703
|
+
var _ref23, _values$quantity, _ref24, _metadataAny$source_p, _product$product_sku, _values$discount_list, _values$quantity2;
|
|
702
704
|
var nextNum = Number((_ref23 = (_values$quantity = values.quantity) !== null && _values$quantity !== void 0 ? _values$quantity : product.num) !== null && _ref23 !== void 0 ? _ref23 : 1) || 1;
|
|
703
705
|
var metadataAny = product.metadata || {};
|
|
704
706
|
var existedSource = (_ref24 = (_metadataAny$source_p = metadataAny.source_product_price) !== null && _metadataAny$source_p !== void 0 ? _metadataAny$source_p : product.selling_price) !== null && _ref24 !== void 0 ? _ref24 : '0';
|
|
@@ -724,7 +726,7 @@ export function createDefaultOrderRulesHooks() {
|
|
|
724
726
|
});
|
|
725
727
|
var composedOriginalPrice = composeLinePrice({
|
|
726
728
|
mainPrice: nextMainOriginalPrice,
|
|
727
|
-
bundle: nextBundle,
|
|
729
|
+
bundle: Number((_product$product_sku = product.product_sku) === null || _product$product_sku === void 0 ? void 0 : _product$product_sku.open_sold_weight) === 1 && hasManualProductDiscountFlag(metadataAny) ? withOriginalBundleOptionPrices(nextBundle) : nextBundle,
|
|
728
730
|
useOriginalBundle: true
|
|
729
731
|
});
|
|
730
732
|
var finalOriginalPrice = resolveManualOverrideLineOriginalPrice({
|
|
@@ -1428,11 +1430,11 @@ export function mapPaymentItemsToOrderPayments(paymentItems) {
|
|
|
1428
1430
|
*/
|
|
1429
1431
|
export function formatV1Product(products) {
|
|
1430
1432
|
return products.map(function (product) {
|
|
1431
|
-
var _product$
|
|
1433
|
+
var _product$product_sku2, _product$note;
|
|
1432
1434
|
return {
|
|
1433
1435
|
bundle: product.product_bundle,
|
|
1434
1436
|
key: product.product_id,
|
|
1435
|
-
option: ((_product$
|
|
1437
|
+
option: ((_product$product_sku2 = product.product_sku) === null || _product$product_sku2 === void 0 ? void 0 : _product$product_sku2.option) || [],
|
|
1436
1438
|
product_id: product.product_id,
|
|
1437
1439
|
product_variant_id: product.product_variant_id,
|
|
1438
1440
|
num: product.product_quantity,
|