@pisell/pisellos 0.10.34 → 0.10.36
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/modules/Order/index.js +4 -18
- package/dist/server/utils/small-ticket.d.ts +1 -1
- package/dist/server/utils/small-ticket.js +85 -60
- package/lib/model/strategy/adapter/promotion/index.js +46 -1
- package/lib/modules/Order/index.js +3 -17
- package/lib/server/utils/small-ticket.d.ts +1 -1
- package/lib/server/utils/small-ticket.js +23 -3
- package/package.json +1 -1
|
@@ -107,13 +107,6 @@ function getVoucherPaymentLifecycleKey(payment) {
|
|
|
107
107
|
if (!isVoucherPaymentRecord(payment)) return null;
|
|
108
108
|
return "".concat(String(payment.voucher_id), "::").concat(String(payment.status || ''));
|
|
109
109
|
}
|
|
110
|
-
function hasPersistedOrderId(orderId) {
|
|
111
|
-
if (orderId === undefined || orderId === null || orderId === '') return false;
|
|
112
|
-
if (typeof orderId === 'string' && orderId.startsWith('LOCAL_')) return false;
|
|
113
|
-
var normalizedOrderId = Number(orderId);
|
|
114
|
-
if (Number.isFinite(normalizedOrderId)) return normalizedOrderId > 0;
|
|
115
|
-
return String(orderId).trim() !== '';
|
|
116
|
-
}
|
|
117
110
|
export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
118
111
|
_inherits(OrderModule, _BaseModule);
|
|
119
112
|
var _super = _createSuper(OrderModule);
|
|
@@ -593,7 +586,6 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
593
586
|
this.store.virtualCurrencyList = (prepareConfigResult === null || prepareConfigResult === void 0 ? void 0 : prepareConfigResult.virtualCurrencyList) || [];
|
|
594
587
|
if (prepareConfigResult) {
|
|
595
588
|
this.writePointCardSnapshotFromPrepareConfig({
|
|
596
|
-
orderId: orderId,
|
|
597
589
|
customerId: params.customerId,
|
|
598
590
|
availableWalletPassList: prepareConfigResult.availableWalletPassList || []
|
|
599
591
|
});
|
|
@@ -1467,12 +1459,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1467
1459
|
}, {
|
|
1468
1460
|
key: "writePointCardSnapshotFromPrepareConfig",
|
|
1469
1461
|
value: function writePointCardSnapshotFromPrepareConfig(params) {
|
|
1470
|
-
var _tempOrder$customer_i
|
|
1462
|
+
var _tempOrder$customer_i;
|
|
1471
1463
|
var tempOrder = this.store.tempOrder;
|
|
1472
1464
|
if (!tempOrder) return;
|
|
1473
1465
|
if (String((_tempOrder$customer_i = tempOrder.customer_id) !== null && _tempOrder$customer_i !== void 0 ? _tempOrder$customer_i : '') !== String(params.customerId)) return;
|
|
1474
|
-
var effectiveOrderId = (_params$orderId = params.orderId) !== null && _params$orderId !== void 0 ? _params$orderId : tempOrder.order_id;
|
|
1475
|
-
if (hasPersistedOrderId(effectiveOrderId)) return;
|
|
1476
1466
|
tempOrder.order_meta_list = _objectSpread(_objectSpread({}, normalizeOrderMetaList(tempOrder.order_meta_list) || {}), {}, {
|
|
1477
1467
|
point_cards_snapshot: buildPointCardSnapshotFromWalletPassList(params.availableWalletPassList)
|
|
1478
1468
|
});
|
|
@@ -3507,7 +3497,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3507
3497
|
email: tempOrder.email
|
|
3508
3498
|
});
|
|
3509
3499
|
var nextCustomerId = (_tempOrder$customer_i4 = tempOrder.customer_id) !== null && _tempOrder$customer_i4 !== void 0 ? _tempOrder$customer_i4 : null;
|
|
3510
|
-
if (String(previousCustomerId !== null && previousCustomerId !== void 0 ? previousCustomerId : '') !== String(nextCustomerId !== null && nextCustomerId !== void 0 ? nextCustomerId : '')
|
|
3500
|
+
if (String(previousCustomerId !== null && previousCustomerId !== void 0 ? previousCustomerId : '') !== String(nextCustomerId !== null && nextCustomerId !== void 0 ? nextCustomerId : '')) {
|
|
3511
3501
|
this.store.availableWalletIds = [];
|
|
3512
3502
|
this.clearTempOrderPointCardSnapshot(tempOrder);
|
|
3513
3503
|
}
|
|
@@ -3550,9 +3540,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3550
3540
|
if (String(previousCustomerId !== null && previousCustomerId !== void 0 ? previousCustomerId : '') !== String(nextCustomerId !== null && nextCustomerId !== void 0 ? nextCustomerId : '')) {
|
|
3551
3541
|
this.store.availableWalletIds = [];
|
|
3552
3542
|
this.store.virtualCurrencyList = [];
|
|
3553
|
-
|
|
3554
|
-
this.clearTempOrderPointCardSnapshot(tempOrder);
|
|
3555
|
-
}
|
|
3543
|
+
this.clearTempOrderPointCardSnapshot(tempOrder);
|
|
3556
3544
|
clearTempOrderHolderAssignments(tempOrder);
|
|
3557
3545
|
this.clearCustomerBoundDiscounts(tempOrder);
|
|
3558
3546
|
this.applyDiscount();
|
|
@@ -3599,9 +3587,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
3599
3587
|
if (tempOrder._extend) delete tempOrder._extend.customerSnapshot;
|
|
3600
3588
|
this.store.availableWalletIds = [];
|
|
3601
3589
|
this.store.virtualCurrencyList = [];
|
|
3602
|
-
|
|
3603
|
-
this.clearTempOrderPointCardSnapshot(tempOrder);
|
|
3604
|
-
}
|
|
3590
|
+
this.clearTempOrderPointCardSnapshot(tempOrder);
|
|
3605
3591
|
this.clearCustomerBoundDiscounts(tempOrder);
|
|
3606
3592
|
this.applyDiscount();
|
|
3607
3593
|
this.persistTempOrder();
|
|
@@ -35,7 +35,7 @@ export interface SmallTicketProduct {
|
|
|
35
35
|
selling_price: string;
|
|
36
36
|
total_selling_price: string;
|
|
37
37
|
original_price: string;
|
|
38
|
-
base_price
|
|
38
|
+
base_price?: string;
|
|
39
39
|
total_original_price: string;
|
|
40
40
|
options_total_price?: string;
|
|
41
41
|
package_items_total_price?: string;
|
|
@@ -327,13 +327,16 @@ function buildProducts(order, locale, productMap) {
|
|
|
327
327
|
var productNote = resolveProductNote(product, locale);
|
|
328
328
|
var basePrice = resolveProductBasePrice(product);
|
|
329
329
|
var resolvedCombinations = Array.isArray(product.combinations) && product.combinations.length ? normalizeExistingCombinations(product.combinations, locale, currencySymbol) : combinations;
|
|
330
|
-
|
|
330
|
+
var shouldIncludeBasePrice = options.length > 0 || resolvedCombinations.length > 0 || hasProductDiscount(product, extensionList);
|
|
331
|
+
return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
331
332
|
product_title: productTitle,
|
|
332
333
|
product_quantity: quantity,
|
|
333
334
|
selling_price: formatMoney(sellingPrice, currencySymbol),
|
|
334
335
|
total_selling_price: formatCalculatedMoney(new Decimal(toMoneyNumber(sellingPrice)).mul(quantity), currencySymbol),
|
|
335
|
-
original_price: formatMoney(originalPrice, currencySymbol)
|
|
336
|
-
|
|
336
|
+
original_price: formatMoney(originalPrice, currencySymbol)
|
|
337
|
+
}, shouldIncludeBasePrice ? {
|
|
338
|
+
base_price: formatCalculatedMoney(basePrice !== null && basePrice !== void 0 ? basePrice : 0, currencySymbol)
|
|
339
|
+
} : {}), {}, {
|
|
337
340
|
total_original_price: formatMoney(new Decimal(toMoneyNumber(originalPrice)).mul(quantity), currencySymbol)
|
|
338
341
|
}, options.length ? {
|
|
339
342
|
options_total_price: sumNormalizedOptionTotals(options, currencySymbol)
|
|
@@ -387,6 +390,16 @@ function normalizeProductDiscounts(params) {
|
|
|
387
390
|
};
|
|
388
391
|
});
|
|
389
392
|
}
|
|
393
|
+
function hasProductDiscount(product) {
|
|
394
|
+
var extensionList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
395
|
+
var hasDiscountListAmount = normalizeArray(product.discount_list).some(function (discount) {
|
|
396
|
+
var _ref10, _discount$amount3;
|
|
397
|
+
return isNonZero((_ref10 = (_discount$amount3 = discount.amount) !== null && _discount$amount3 !== void 0 ? _discount$amount3 : discount.value) !== null && _ref10 !== void 0 ? _ref10 : discount.discount_amount);
|
|
398
|
+
});
|
|
399
|
+
return hasDiscountListAmount || extensionList.some(function (row) {
|
|
400
|
+
return /^\s*-/.test(stringify(row === null || row === void 0 ? void 0 : row.value));
|
|
401
|
+
});
|
|
402
|
+
}
|
|
390
403
|
function buildProductExtensionList(params) {
|
|
391
404
|
var product = params.product,
|
|
392
405
|
locale = params.locale,
|
|
@@ -463,8 +476,8 @@ function resolveDiscountTitleWithPercent(discount, locale) {
|
|
|
463
476
|
return "".concat(title, " (").concat(percent, "%)");
|
|
464
477
|
}
|
|
465
478
|
function resolveDiscountTitle(discount, locale) {
|
|
466
|
-
var
|
|
467
|
-
var title = getLocalizedValue((
|
|
479
|
+
var _ref11, _ref12, _ref13, _ref14, _discount$discount$na, _discount$discount3, _discount$discount4, _discount$discount5;
|
|
480
|
+
var title = getLocalizedValue((_ref11 = (_ref12 = (_ref13 = (_ref14 = (_discount$discount$na = (_discount$discount3 = discount.discount) === null || _discount$discount3 === void 0 ? void 0 : _discount$discount3.name) !== null && _discount$discount$na !== void 0 ? _discount$discount$na : (_discount$discount4 = discount.discount) === null || _discount$discount4 === void 0 ? void 0 : _discount$discount4.title) !== null && _ref14 !== void 0 ? _ref14 : (_discount$discount5 = discount.discount) === null || _discount$discount5 === void 0 ? void 0 : _discount$discount5.message) !== null && _ref13 !== void 0 ? _ref13 : discount.name) !== null && _ref12 !== void 0 ? _ref12 : discount.title) !== null && _ref11 !== void 0 ? _ref11 : discount.message, locale);
|
|
468
481
|
if (title) return title;
|
|
469
482
|
if (discount.type === 'product') return label(locale, 'manualDiscount');
|
|
470
483
|
return '';
|
|
@@ -489,10 +502,10 @@ function normalizeProductOptions(params) {
|
|
|
489
502
|
parentProduct = params.parentProduct;
|
|
490
503
|
var rawOptions = Array.isArray(params.options) ? params.options : Array.isArray(product.options) ? product.options : Array.isArray((_product$product_sku = product.product_sku) === null || _product$product_sku === void 0 ? void 0 : _product$product_sku.option) ? product.product_sku.option : [];
|
|
491
504
|
return rawOptions.map(function (option) {
|
|
492
|
-
var
|
|
493
|
-
var price = (
|
|
494
|
-
var quantity = toNumber((
|
|
495
|
-
var value = (
|
|
505
|
+
var _ref15, _option$original_pric, _ref16, _option$num, _ref17, _option$value;
|
|
506
|
+
var price = (_ref15 = (_option$original_pric = option.original_price) !== null && _option$original_pric !== void 0 ? _option$original_pric : option.add_price) !== null && _ref15 !== void 0 ? _ref15 : option.price;
|
|
507
|
+
var quantity = toNumber((_ref16 = (_option$num = option.num) !== null && _option$num !== void 0 ? _option$num : option.quantity) !== null && _ref16 !== void 0 ? _ref16 : 1, 1);
|
|
508
|
+
var value = (_ref17 = (_option$value = option.value) !== null && _option$value !== void 0 ? _option$value : option.option) !== null && _ref17 !== void 0 ? _ref17 : option.item;
|
|
496
509
|
var name = getProductTitleSource(option, locale) || resolveOptionTitleFromParentProduct({
|
|
497
510
|
option: option,
|
|
498
511
|
parentProduct: parentProduct,
|
|
@@ -519,7 +532,7 @@ function normalizeProductCombinations(params) {
|
|
|
519
532
|
parentProduct = params.parentProduct;
|
|
520
533
|
var bundles = Array.isArray(product.product_bundle) ? product.product_bundle : [];
|
|
521
534
|
return bundles.map(function (bundle) {
|
|
522
|
-
var
|
|
535
|
+
var _ref18, _bundle$num, _bundle$metadata;
|
|
523
536
|
var combinationsOptions = normalizeProductOptions({
|
|
524
537
|
product: {},
|
|
525
538
|
locale: locale,
|
|
@@ -535,17 +548,20 @@ function normalizeProductCombinations(params) {
|
|
|
535
548
|
});
|
|
536
549
|
var productNote = resolveProductNote(bundle, locale);
|
|
537
550
|
var nestedCombinations = Array.isArray(bundle.combinations) ? normalizeExistingCombinations(bundle.combinations, locale, currencySymbol) : [];
|
|
538
|
-
var quantity = toNumber((
|
|
551
|
+
var quantity = toNumber((_ref18 = (_bundle$num = bundle.num) !== null && _bundle$num !== void 0 ? _bundle$num : bundle.quantity) !== null && _ref18 !== void 0 ? _ref18 : 1, 1);
|
|
539
552
|
var formattedPrice = formatBundlePrice(bundle, currencySymbol);
|
|
540
553
|
var optionsTotal = sumNormalizedOptionTotals(combinationsOptions, currencySymbol);
|
|
541
554
|
var explicitBasePrice = firstPresentValue(bundle.base_price, (_bundle$metadata = bundle.metadata) === null || _bundle$metadata === void 0 ? void 0 : _bundle$metadata.source_product_price);
|
|
542
555
|
var basePrice = isPresentId(explicitBasePrice) ? explicitBasePrice : 0;
|
|
543
|
-
|
|
556
|
+
var shouldIncludeBasePrice = combinationsOptions.length > 0 || nestedCombinations.length > 0 || hasProductDiscount(bundle);
|
|
557
|
+
return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
544
558
|
product_title: baseTitle,
|
|
545
559
|
product_quantity: quantity,
|
|
546
560
|
price: formattedPrice,
|
|
547
|
-
total_selling_price: formatCalculatedMoney(new Decimal(toMoneyNumber(formattedPrice)).mul(quantity), currencySymbol)
|
|
548
|
-
|
|
561
|
+
total_selling_price: formatCalculatedMoney(new Decimal(toMoneyNumber(formattedPrice)).mul(quantity), currencySymbol)
|
|
562
|
+
}, shouldIncludeBasePrice ? {
|
|
563
|
+
base_price: formatCalculatedMoney(basePrice, currencySymbol)
|
|
564
|
+
} : {}), {}, {
|
|
549
565
|
combinations_options: combinationsOptions
|
|
550
566
|
}, combinationsOptions.length ? {
|
|
551
567
|
options_total_price: optionsTotal
|
|
@@ -560,7 +576,7 @@ function normalizeProductCombinations(params) {
|
|
|
560
576
|
}
|
|
561
577
|
function normalizeExistingCombinations(combinations, locale, currencySymbol) {
|
|
562
578
|
return combinations.map(function (combination) {
|
|
563
|
-
var
|
|
579
|
+
var _ref19, _ref20, _combination$product_, _firstPresentValue;
|
|
564
580
|
if (!combination || _typeof(combination) !== 'object' || Array.isArray(combination)) {
|
|
565
581
|
return combination;
|
|
566
582
|
}
|
|
@@ -577,18 +593,20 @@ function normalizeExistingCombinations(combinations, locale, currencySymbol) {
|
|
|
577
593
|
delete snapshot.product_note;
|
|
578
594
|
delete snapshot.note;
|
|
579
595
|
delete snapshot.combinations;
|
|
580
|
-
var quantity = toNumber((
|
|
596
|
+
var quantity = toNumber((_ref19 = (_ref20 = (_combination$product_ = combination.product_quantity) !== null && _combination$product_ !== void 0 ? _combination$product_ : combination.num) !== null && _ref20 !== void 0 ? _ref20 : combination.quantity) !== null && _ref19 !== void 0 ? _ref19 : 1, 1);
|
|
581
597
|
var unitPrice = (_firstPresentValue = firstPresentValue(combination.selling_price, combination.price, combination.original_price)) !== null && _firstPresentValue !== void 0 ? _firstPresentValue : 0;
|
|
582
598
|
var optionsAmount = sumMoneyValues(normalizedOptions.map(function (option) {
|
|
583
599
|
return option.total_price;
|
|
584
600
|
}));
|
|
585
601
|
var explicitBasePrice = firstPresentValue(combination.base_price);
|
|
586
602
|
var basePrice = isPresentId(explicitBasePrice) ? explicitBasePrice : 0;
|
|
587
|
-
|
|
603
|
+
var shouldIncludeBasePrice = normalizedOptions.length > 0 || nestedCombinations.length > 0 || hasProductDiscount(combination, normalizeArray(combination.extension_list));
|
|
604
|
+
return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, snapshot), {}, {
|
|
588
605
|
product_quantity: quantity,
|
|
589
|
-
total_selling_price: formatCalculatedMoney(new Decimal(toMoneyNumber(unitPrice)).mul(quantity), currencySymbol)
|
|
606
|
+
total_selling_price: formatCalculatedMoney(new Decimal(toMoneyNumber(unitPrice)).mul(quantity), currencySymbol)
|
|
607
|
+
}, shouldIncludeBasePrice ? {
|
|
590
608
|
base_price: formatCalculatedMoney(basePrice, currencySymbol)
|
|
591
|
-
}, Array.isArray(combination.combinations_options) ? {
|
|
609
|
+
} : {}), Array.isArray(combination.combinations_options) ? {
|
|
592
610
|
combinations_options: normalizedOptions
|
|
593
611
|
} : Array.isArray(combination.options) ? {
|
|
594
612
|
options: normalizedOptions
|
|
@@ -624,7 +642,7 @@ function resolveProductNote(product, locale) {
|
|
|
624
642
|
return getLocalizedValue(product.note, locale).trim();
|
|
625
643
|
}
|
|
626
644
|
function resolveBundleProductTitle(params) {
|
|
627
|
-
var
|
|
645
|
+
var _ref21, _ref22, _bundle$bundle_produc;
|
|
628
646
|
var bundle = params.bundle,
|
|
629
647
|
productMap = params.productMap,
|
|
630
648
|
locale = params.locale,
|
|
@@ -637,7 +655,7 @@ function resolveBundleProductTitle(params) {
|
|
|
637
655
|
});
|
|
638
656
|
var parentBundleTitle = parentBundleItem ? getProductTitleSource(parentBundleItem, locale) : '';
|
|
639
657
|
if (parentBundleTitle) return parentBundleTitle;
|
|
640
|
-
var productId = (
|
|
658
|
+
var productId = (_ref21 = (_ref22 = (_bundle$bundle_produc = bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle._bundle_product_id) !== null && _ref22 !== void 0 ? _ref22 : bundle.product_id) !== null && _ref21 !== void 0 ? _ref21 : bundle.id;
|
|
641
659
|
var fallbackProduct = resolveProductFromMap(productId, productMap);
|
|
642
660
|
if (!fallbackProduct) return '';
|
|
643
661
|
return getProductTitleSource(fallbackProduct, locale);
|
|
@@ -689,10 +707,10 @@ function resolveVariantTextFromSkuKey(params) {
|
|
|
689
707
|
}
|
|
690
708
|
function resolveVariantTextFromNameMap(params) {
|
|
691
709
|
if (!params.nameMap || _typeof(params.nameMap) !== 'object') return '';
|
|
692
|
-
return Object.entries(params.nameMap).map(function (
|
|
693
|
-
var
|
|
694
|
-
groupPositionId =
|
|
695
|
-
value =
|
|
710
|
+
return Object.entries(params.nameMap).map(function (_ref23) {
|
|
711
|
+
var _ref24 = _slicedToArray(_ref23, 2),
|
|
712
|
+
groupPositionId = _ref24[0],
|
|
713
|
+
value = _ref24[1];
|
|
696
714
|
var group = resolveVariantGroup(params.parentProduct, groupPositionId);
|
|
697
715
|
if (!group) return '';
|
|
698
716
|
var groupName = getLocalizedValue(group.name, params.locale);
|
|
@@ -726,12 +744,12 @@ function getProductTitleSource(source, locale) {
|
|
|
726
744
|
return resolveTitleValue(source.product_title, locale) || resolveTitleValue(source.title, locale) || resolveTitleValue(source.name, locale);
|
|
727
745
|
}
|
|
728
746
|
function resolveTitleValue(value, locale) {
|
|
729
|
-
var
|
|
747
|
+
var _ref25, _ref26, _ref27, _ref28, _value$locale;
|
|
730
748
|
if (value === undefined || value === null) return '';
|
|
731
749
|
if (_typeof(value) !== 'object') return stringify(value);
|
|
732
750
|
var dashedLocale = locale.replace('_', '-');
|
|
733
751
|
var underscoredLocale = locale.replace('-', '_');
|
|
734
|
-
return stringify((
|
|
752
|
+
return stringify((_ref25 = (_ref26 = (_ref27 = (_ref28 = (_value$locale = value[locale]) !== null && _value$locale !== void 0 ? _value$locale : value[dashedLocale]) !== null && _ref28 !== void 0 ? _ref28 : value[underscoredLocale]) !== null && _ref27 !== void 0 ? _ref27 : value.original) !== null && _ref26 !== void 0 ? _ref26 : value.auto) !== null && _ref25 !== void 0 ? _ref25 : '');
|
|
735
753
|
}
|
|
736
754
|
function resolveOptionTitleFromParentProduct(params) {
|
|
737
755
|
var option = params.option,
|
|
@@ -749,17 +767,17 @@ function flattenOptionItems(parentProduct) {
|
|
|
749
767
|
return optionGroups.flatMap(function (group) {
|
|
750
768
|
var items = normalizeArray(group.option_item || group.option_items || group.option || group.options || group.items || group.children || group.product_option_item);
|
|
751
769
|
return items.map(function (item) {
|
|
752
|
-
var
|
|
770
|
+
var _ref29, _item$option_group_id;
|
|
753
771
|
return _objectSpread(_objectSpread({}, item), {}, {
|
|
754
|
-
option_group_id: (
|
|
772
|
+
option_group_id: (_ref29 = (_item$option_group_id = item.option_group_id) !== null && _item$option_group_id !== void 0 ? _item$option_group_id : group.id) !== null && _ref29 !== void 0 ? _ref29 : group.option_group_id
|
|
755
773
|
});
|
|
756
774
|
});
|
|
757
775
|
});
|
|
758
776
|
}
|
|
759
777
|
function isOptionItemMatch(option, item) {
|
|
760
|
-
var
|
|
761
|
-
var optionItemId = (
|
|
762
|
-
var itemId = (
|
|
778
|
+
var _ref30, _option$option_group_, _ref31, _item$option_group_it, _option$option_group_2, _item$option_group_id2;
|
|
779
|
+
var optionItemId = (_ref30 = (_option$option_group_ = option.option_group_item_id) !== null && _option$option_group_ !== void 0 ? _option$option_group_ : option.product_option_item_id) !== null && _ref30 !== void 0 ? _ref30 : option.id;
|
|
780
|
+
var itemId = (_ref31 = (_item$option_group_it = item.option_group_item_id) !== null && _item$option_group_it !== void 0 ? _item$option_group_it : item.product_option_item_id) !== null && _ref31 !== void 0 ? _ref31 : item.id;
|
|
763
781
|
if (!isSameId(optionItemId, itemId)) return false;
|
|
764
782
|
var optionGroupId = (_option$option_group_2 = option.option_group_id) !== null && _option$option_group_2 !== void 0 ? _option$option_group_2 : option.group_id;
|
|
765
783
|
var itemGroupId = (_item$option_group_id2 = item.option_group_id) !== null && _item$option_group_id2 !== void 0 ? _item$option_group_id2 : item.group_id;
|
|
@@ -769,16 +787,16 @@ function isOptionItemMatch(option, item) {
|
|
|
769
787
|
return true;
|
|
770
788
|
}
|
|
771
789
|
function resolveBundleItemFromParentProduct(params) {
|
|
772
|
-
var
|
|
790
|
+
var _ref32, _bundle$bundle_varian, _bundle$bundle_id, _bundle$bundle_group_, _ref34, _bundle$bundle_produc2;
|
|
773
791
|
var bundle = params.bundle,
|
|
774
792
|
parentProduct = params.parentProduct;
|
|
775
793
|
if (!parentProduct) return null;
|
|
776
794
|
var bundleItems = flattenBundleItems(parentProduct);
|
|
777
|
-
var bundleVariantId = (
|
|
795
|
+
var bundleVariantId = (_ref32 = (_bundle$bundle_varian = bundle.bundle_variant_id) !== null && _bundle$bundle_varian !== void 0 ? _bundle$bundle_varian : bundle.variant_id) !== null && _ref32 !== void 0 ? _ref32 : bundle.product_variant_id;
|
|
778
796
|
if (isNonZeroId(bundleVariantId)) {
|
|
779
797
|
var matchedByVariant = bundleItems.find(function (item) {
|
|
780
|
-
var
|
|
781
|
-
return isSameId((
|
|
798
|
+
var _ref33, _item$bundle_variant_;
|
|
799
|
+
return isSameId((_ref33 = (_item$bundle_variant_ = item.bundle_variant_id) !== null && _item$bundle_variant_ !== void 0 ? _item$bundle_variant_ : item.variant_id) !== null && _ref33 !== void 0 ? _ref33 : item.product_variant_id, bundleVariantId);
|
|
782
800
|
});
|
|
783
801
|
if (matchedByVariant) return matchedByVariant;
|
|
784
802
|
}
|
|
@@ -791,18 +809,18 @@ function resolveBundleItemFromParentProduct(params) {
|
|
|
791
809
|
if (matchedByBundleId) return matchedByBundleId;
|
|
792
810
|
}
|
|
793
811
|
var bundleGroupId = (_bundle$bundle_group_ = bundle.bundle_group_id) !== null && _bundle$bundle_group_ !== void 0 ? _bundle$bundle_group_ : bundle.group_id;
|
|
794
|
-
var bundleProductId = (
|
|
812
|
+
var bundleProductId = (_ref34 = (_bundle$bundle_produc2 = bundle.bundle_product_id) !== null && _bundle$bundle_produc2 !== void 0 ? _bundle$bundle_produc2 : bundle._bundle_product_id) !== null && _ref34 !== void 0 ? _ref34 : bundle.product_id;
|
|
795
813
|
if (isPresentId(bundleGroupId) && isPresentId(bundleProductId)) {
|
|
796
814
|
var matchedByGroupAndProduct = bundleItems.find(function (item) {
|
|
797
|
-
var _item$group_id,
|
|
798
|
-
return isSameId((_item$group_id = item.group_id) !== null && _item$group_id !== void 0 ? _item$group_id : item.bundle_group_id, bundleGroupId) && isSameId((
|
|
815
|
+
var _item$group_id, _ref35, _item$bundle_product_;
|
|
816
|
+
return isSameId((_item$group_id = item.group_id) !== null && _item$group_id !== void 0 ? _item$group_id : item.bundle_group_id, bundleGroupId) && isSameId((_ref35 = (_item$bundle_product_ = item.bundle_product_id) !== null && _item$bundle_product_ !== void 0 ? _item$bundle_product_ : item._bundle_product_id) !== null && _ref35 !== void 0 ? _ref35 : item.product_id, bundleProductId);
|
|
799
817
|
});
|
|
800
818
|
if (matchedByGroupAndProduct) return matchedByGroupAndProduct;
|
|
801
819
|
}
|
|
802
820
|
if (isPresentId(bundleProductId)) {
|
|
803
821
|
return bundleItems.find(function (item) {
|
|
804
|
-
var
|
|
805
|
-
return isSameId((
|
|
822
|
+
var _ref36, _item$bundle_product_2;
|
|
823
|
+
return isSameId((_ref36 = (_item$bundle_product_2 = item.bundle_product_id) !== null && _item$bundle_product_2 !== void 0 ? _item$bundle_product_2 : item._bundle_product_id) !== null && _ref36 !== void 0 ? _ref36 : item.product_id, bundleProductId);
|
|
806
824
|
}) || null;
|
|
807
825
|
}
|
|
808
826
|
return null;
|
|
@@ -812,9 +830,9 @@ function flattenBundleItems(parentProduct) {
|
|
|
812
830
|
return bundleGroups.flatMap(function (group) {
|
|
813
831
|
var items = Array.isArray(group.bundle_item) ? group.bundle_item : [];
|
|
814
832
|
return items.map(function (item) {
|
|
815
|
-
var
|
|
833
|
+
var _ref37, _item$group_id2;
|
|
816
834
|
return _objectSpread(_objectSpread({}, item), {}, {
|
|
817
|
-
group_id: (
|
|
835
|
+
group_id: (_ref37 = (_item$group_id2 = item.group_id) !== null && _item$group_id2 !== void 0 ? _item$group_id2 : group.id) !== null && _ref37 !== void 0 ? _ref37 : group.group_id
|
|
818
836
|
});
|
|
819
837
|
});
|
|
820
838
|
});
|
|
@@ -838,8 +856,8 @@ function isSameId(left, right) {
|
|
|
838
856
|
return String(left) === String(right);
|
|
839
857
|
}
|
|
840
858
|
function formatBundlePrice(bundle, currencySymbol) {
|
|
841
|
-
var
|
|
842
|
-
var value = (
|
|
859
|
+
var _ref38, _ref39, _bundle$bundle_sellin;
|
|
860
|
+
var value = (_ref38 = (_ref39 = (_bundle$bundle_sellin = bundle.bundle_selling_price) !== null && _bundle$bundle_sellin !== void 0 ? _bundle$bundle_sellin : bundle.bundle_sum_price) !== null && _ref39 !== void 0 ? _ref39 : bundle.price) !== null && _ref38 !== void 0 ? _ref38 : 0;
|
|
843
861
|
var amount = new Decimal(toMoneyNumber(value));
|
|
844
862
|
// 套餐价格协议:只有 markdown 是减价;加价与商品原价都保持正数。
|
|
845
863
|
var isNegative = bundle.price_type === 'markdown';
|
|
@@ -857,9 +875,9 @@ function buildFees(params) {
|
|
|
857
875
|
financials = params.financials;
|
|
858
876
|
var fees = [];
|
|
859
877
|
for (var _i = 0, _normalizeArray = normalizeArray(order.surcharges || summary.surcharges); _i < _normalizeArray.length; _i++) {
|
|
860
|
-
var
|
|
878
|
+
var _ref40, _surcharge$amount;
|
|
861
879
|
var surcharge = _normalizeArray[_i];
|
|
862
|
-
var value = (
|
|
880
|
+
var value = (_ref40 = (_surcharge$amount = surcharge.amount) !== null && _surcharge$amount !== void 0 ? _surcharge$amount : surcharge.value) !== null && _ref40 !== void 0 ? _ref40 : surcharge.total_amount;
|
|
863
881
|
if (!isNonZero(value)) continue;
|
|
864
882
|
fees.push({
|
|
865
883
|
item: getLocalizedValue(surcharge.name || surcharge.title || surcharge.item, locale),
|
|
@@ -967,9 +985,9 @@ function resolveTaxTitle(params) {
|
|
|
967
985
|
}
|
|
968
986
|
function calculateProductOriginalAmount(order) {
|
|
969
987
|
return normalizeArray(order.products).reduce(function (total, product) {
|
|
970
|
-
var
|
|
971
|
-
var quantity = toNumber((
|
|
972
|
-
var originalPrice = (
|
|
988
|
+
var _ref41, _ref42, _product$product_quan2, _ref43, _ref44, _ref45, _product$original_pri2;
|
|
989
|
+
var quantity = toNumber((_ref41 = (_ref42 = (_product$product_quan2 = product.product_quantity) !== null && _product$product_quan2 !== void 0 ? _product$product_quan2 : product.quantity) !== null && _ref42 !== void 0 ? _ref42 : product.num) !== null && _ref41 !== void 0 ? _ref41 : 1, 1);
|
|
990
|
+
var originalPrice = (_ref43 = (_ref44 = (_ref45 = (_product$original_pri2 = product.original_price) !== null && _product$original_pri2 !== void 0 ? _product$original_pri2 : product.selling_price) !== null && _ref45 !== void 0 ? _ref45 : product.payment_price) !== null && _ref44 !== void 0 ? _ref44 : product.price) !== null && _ref43 !== void 0 ? _ref43 : 0;
|
|
973
991
|
return total.plus(new Decimal(toMoneyNumber(originalPrice)).mul(quantity));
|
|
974
992
|
}, new Decimal(0));
|
|
975
993
|
}
|
|
@@ -1057,8 +1075,8 @@ function sortBookings(bookings) {
|
|
|
1057
1075
|
}
|
|
1058
1076
|
var bookingUidOrder = compareOptionalValues(firstPresentValue((_left$booking2 = left.booking) === null || _left$booking2 === void 0 || (_left$booking2 = _left$booking2.metadata) === null || _left$booking2 === void 0 ? void 0 : _left$booking2.unique_identification_number, (_left$booking3 = left.booking) === null || _left$booking3 === void 0 ? void 0 : _left$booking3.booking_uid), firstPresentValue((_right$booking2 = right.booking) === null || _right$booking2 === void 0 || (_right$booking2 = _right$booking2.metadata) === null || _right$booking2 === void 0 ? void 0 : _right$booking2.unique_identification_number, (_right$booking3 = right.booking) === null || _right$booking3 === void 0 ? void 0 : _right$booking3.booking_uid));
|
|
1059
1077
|
return bookingUidOrder || left.index - right.index;
|
|
1060
|
-
}).map(function (
|
|
1061
|
-
var booking =
|
|
1078
|
+
}).map(function (_ref46) {
|
|
1079
|
+
var booking = _ref46.booking;
|
|
1062
1080
|
return booking;
|
|
1063
1081
|
});
|
|
1064
1082
|
}
|
|
@@ -1120,8 +1138,8 @@ function buildRefundData(params) {
|
|
|
1120
1138
|
result.set(identity, candidate);
|
|
1121
1139
|
}
|
|
1122
1140
|
return result;
|
|
1123
|
-
}, new Map()).values()).filter(function (
|
|
1124
|
-
var refund =
|
|
1141
|
+
}, new Map()).values()).filter(function (_ref47) {
|
|
1142
|
+
var refund = _ref47.refund;
|
|
1125
1143
|
return isPrintableRefund(refund);
|
|
1126
1144
|
}).sort(function (left, right) {
|
|
1127
1145
|
var leftTime = refundTimestamp(left.refund);
|
|
@@ -1129,9 +1147,9 @@ function buildRefundData(params) {
|
|
|
1129
1147
|
if (leftTime !== rightTime) return leftTime < rightTime ? -1 : 1;
|
|
1130
1148
|
return left.index - right.index;
|
|
1131
1149
|
});
|
|
1132
|
-
return refunds.map(function (
|
|
1150
|
+
return refunds.map(function (_ref48) {
|
|
1133
1151
|
var _firstPresentValue8;
|
|
1134
|
-
var refund =
|
|
1152
|
+
var refund = _ref48.refund;
|
|
1135
1153
|
var payment = resolveRefundPayment(refund, payments);
|
|
1136
1154
|
var methodName = paymentMethodName(payment, params.locale) || label(params.locale, 'refund');
|
|
1137
1155
|
var amount = (_firstPresentValue8 = firstPresentValue(refund.amount, refund.refund_amount, refund.total_amount)) !== null && _firstPresentValue8 !== void 0 ? _firstPresentValue8 : 0;
|
|
@@ -1226,6 +1244,7 @@ function buildPointCardSnapshotAssets(params) {
|
|
|
1226
1244
|
var _params$order$order_m;
|
|
1227
1245
|
var snapshots = (_params$order$order_m = params.order.order_meta_list) === null || _params$order$order_m === void 0 ? void 0 : _params$order$order_m.point_cards_snapshot;
|
|
1228
1246
|
if (!Array.isArray(snapshots)) return [];
|
|
1247
|
+
var snapshotTime = firstPresentValue(params.order.updated_at, params.order.created_at);
|
|
1229
1248
|
var seenSnapshotIds = new Set();
|
|
1230
1249
|
return snapshots.flatMap(function (snapshot) {
|
|
1231
1250
|
if (!snapshot || _typeof(snapshot) !== 'object' || Array.isArray(snapshot)) return [];
|
|
@@ -1246,6 +1265,12 @@ function buildPointCardSnapshotAssets(params) {
|
|
|
1246
1265
|
value: trimDecimal(remainingPoints)
|
|
1247
1266
|
});
|
|
1248
1267
|
}
|
|
1268
|
+
if (isPresentId(snapshotTime)) {
|
|
1269
|
+
rows.push({
|
|
1270
|
+
item: formatDateTime(snapshotTime, params.locale),
|
|
1271
|
+
value: ''
|
|
1272
|
+
});
|
|
1273
|
+
}
|
|
1249
1274
|
return [rows];
|
|
1250
1275
|
});
|
|
1251
1276
|
}
|
|
@@ -1352,8 +1377,8 @@ function buildPaymentItems(params) {
|
|
|
1352
1377
|
includeUsage: includeFundRecordUsage
|
|
1353
1378
|
})));
|
|
1354
1379
|
} else {
|
|
1355
|
-
var
|
|
1356
|
-
var remainingAmount = (
|
|
1380
|
+
var _ref49, _payment$remaining_am, _payment$metadata;
|
|
1381
|
+
var remainingAmount = (_ref49 = (_payment$remaining_am = payment.remaining_amount) !== null && _payment$remaining_am !== void 0 ? _payment$remaining_am : payment.balance) !== null && _ref49 !== void 0 ? _ref49 : (_payment$metadata = payment.metadata) === null || _payment$metadata === void 0 ? void 0 : _payment$metadata.remaining_amount;
|
|
1357
1382
|
if (remainingAmount !== undefined && remainingAmount !== null) {
|
|
1358
1383
|
items.push({
|
|
1359
1384
|
item: label(locale, 'remainingAmount'),
|
|
@@ -1507,12 +1532,12 @@ function label(locale, key) {
|
|
|
1507
1532
|
return ((_LABELS$locale = LABELS[locale]) === null || _LABELS$locale === void 0 ? void 0 : _LABELS$locale[key]) || LABELS.en[key] || key;
|
|
1508
1533
|
}
|
|
1509
1534
|
function getLocalizedValue(value, locale) {
|
|
1510
|
-
var
|
|
1535
|
+
var _ref50, _ref51, _ref52, _ref53, _ref54, _ref55, _value$locale2;
|
|
1511
1536
|
if (value === undefined || value === null) return '';
|
|
1512
1537
|
if (_typeof(value) !== 'object') return stringify(value);
|
|
1513
1538
|
var dashedLocale = locale.replace('_', '-');
|
|
1514
1539
|
var underscoredLocale = locale.replace('-', '_');
|
|
1515
|
-
return stringify((
|
|
1540
|
+
return stringify((_ref50 = (_ref51 = (_ref52 = (_ref53 = (_ref54 = (_ref55 = (_value$locale2 = value[locale]) !== null && _value$locale2 !== void 0 ? _value$locale2 : value[dashedLocale]) !== null && _ref55 !== void 0 ? _ref55 : value[underscoredLocale]) !== null && _ref54 !== void 0 ? _ref54 : value.original) !== null && _ref53 !== void 0 ? _ref53 : value.auto) !== null && _ref52 !== void 0 ? _ref52 : value.default) !== null && _ref51 !== void 0 ? _ref51 : value.en) !== null && _ref50 !== void 0 ? _ref50 : '');
|
|
1516
1541
|
}
|
|
1517
1542
|
function resolveServiceTypeLabelKey(serviceType, order) {
|
|
1518
1543
|
var normalized = serviceType.trim().toLowerCase().replace(/[\s-]+/g, '_');
|
|
@@ -1 +1,46 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "BUY_X_GET_Y_FREE_STRATEGY", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _examples.BUY_X_GET_Y_FREE_STRATEGY;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "ITEM_REWARD_STRATEGY", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _examples.ITEM_REWARD_STRATEGY;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "PromotionAdapter", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _adapter.PromotionAdapter;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "PromotionEvaluator", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _evaluator.PromotionEvaluator;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "X_ITEMS_FOR_Y_PRICE_STRATEGY", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _examples.X_ITEMS_FOR_Y_PRICE_STRATEGY;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "default", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _adapter.default;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
var _evaluator = require("./evaluator");
|
|
43
|
+
var _adapter = _interopRequireWildcard(require("./adapter"));
|
|
44
|
+
var _examples = require("./examples");
|
|
45
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
46
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -72,13 +72,6 @@ function getVoucherPaymentLifecycleKey(payment) {
|
|
|
72
72
|
if (!isVoucherPaymentRecord(payment)) return null;
|
|
73
73
|
return `${String(payment.voucher_id)}::${String(payment.status || '')}`;
|
|
74
74
|
}
|
|
75
|
-
function hasPersistedOrderId(orderId) {
|
|
76
|
-
if (orderId === undefined || orderId === null || orderId === '') return false;
|
|
77
|
-
if (typeof orderId === 'string' && orderId.startsWith('LOCAL_')) return false;
|
|
78
|
-
const normalizedOrderId = Number(orderId);
|
|
79
|
-
if (Number.isFinite(normalizedOrderId)) return normalizedOrderId > 0;
|
|
80
|
-
return String(orderId).trim() !== '';
|
|
81
|
-
}
|
|
82
75
|
class OrderModule extends _BaseModule.BaseModule {
|
|
83
76
|
defaultName = 'order';
|
|
84
77
|
defaultVersion = '1.0.0';
|
|
@@ -480,7 +473,6 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
480
473
|
this.store.virtualCurrencyList = prepareConfigResult?.virtualCurrencyList || [];
|
|
481
474
|
if (prepareConfigResult) {
|
|
482
475
|
this.writePointCardSnapshotFromPrepareConfig({
|
|
483
|
-
orderId,
|
|
484
476
|
customerId: params.customerId,
|
|
485
477
|
availableWalletPassList: prepareConfigResult.availableWalletPassList || []
|
|
486
478
|
});
|
|
@@ -986,8 +978,6 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
986
978
|
const tempOrder = this.store.tempOrder;
|
|
987
979
|
if (!tempOrder) return;
|
|
988
980
|
if (String(tempOrder.customer_id ?? '') !== String(params.customerId)) return;
|
|
989
|
-
const effectiveOrderId = params.orderId ?? tempOrder.order_id;
|
|
990
|
-
if (hasPersistedOrderId(effectiveOrderId)) return;
|
|
991
981
|
tempOrder.order_meta_list = {
|
|
992
982
|
...((0, _utils.normalizeOrderMetaList)(tempOrder.order_meta_list) || {}),
|
|
993
983
|
point_cards_snapshot: (0, _utils.buildPointCardSnapshotFromWalletPassList)(params.availableWalletPassList)
|
|
@@ -2465,7 +2455,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2465
2455
|
email: tempOrder.email
|
|
2466
2456
|
});
|
|
2467
2457
|
const nextCustomerId = tempOrder.customer_id ?? null;
|
|
2468
|
-
if (String(previousCustomerId ?? '') !== String(nextCustomerId ?? '')
|
|
2458
|
+
if (String(previousCustomerId ?? '') !== String(nextCustomerId ?? '')) {
|
|
2469
2459
|
this.store.availableWalletIds = [];
|
|
2470
2460
|
this.clearTempOrderPointCardSnapshot(tempOrder);
|
|
2471
2461
|
}
|
|
@@ -2505,9 +2495,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2505
2495
|
if (String(previousCustomerId ?? '') !== String(nextCustomerId ?? '')) {
|
|
2506
2496
|
this.store.availableWalletIds = [];
|
|
2507
2497
|
this.store.virtualCurrencyList = [];
|
|
2508
|
-
|
|
2509
|
-
this.clearTempOrderPointCardSnapshot(tempOrder);
|
|
2510
|
-
}
|
|
2498
|
+
this.clearTempOrderPointCardSnapshot(tempOrder);
|
|
2511
2499
|
(0, _utils.clearTempOrderHolderAssignments)(tempOrder);
|
|
2512
2500
|
this.clearCustomerBoundDiscounts(tempOrder);
|
|
2513
2501
|
this.applyDiscount();
|
|
@@ -2547,9 +2535,7 @@ class OrderModule extends _BaseModule.BaseModule {
|
|
|
2547
2535
|
if (tempOrder._extend) delete tempOrder._extend.customerSnapshot;
|
|
2548
2536
|
this.store.availableWalletIds = [];
|
|
2549
2537
|
this.store.virtualCurrencyList = [];
|
|
2550
|
-
|
|
2551
|
-
this.clearTempOrderPointCardSnapshot(tempOrder);
|
|
2552
|
-
}
|
|
2538
|
+
this.clearTempOrderPointCardSnapshot(tempOrder);
|
|
2553
2539
|
this.clearCustomerBoundDiscounts(tempOrder);
|
|
2554
2540
|
this.applyDiscount();
|
|
2555
2541
|
this.persistTempOrder();
|
|
@@ -35,7 +35,7 @@ export interface SmallTicketProduct {
|
|
|
35
35
|
selling_price: string;
|
|
36
36
|
total_selling_price: string;
|
|
37
37
|
original_price: string;
|
|
38
|
-
base_price
|
|
38
|
+
base_price?: string;
|
|
39
39
|
total_original_price: string;
|
|
40
40
|
options_total_price?: string;
|
|
41
41
|
package_items_total_price?: string;
|
|
@@ -322,13 +322,16 @@ function buildProducts(order, locale, productMap) {
|
|
|
322
322
|
const productNote = resolveProductNote(product, locale);
|
|
323
323
|
const basePrice = resolveProductBasePrice(product);
|
|
324
324
|
const resolvedCombinations = Array.isArray(product.combinations) && product.combinations.length ? normalizeExistingCombinations(product.combinations, locale, currencySymbol) : combinations;
|
|
325
|
+
const shouldIncludeBasePrice = options.length > 0 || resolvedCombinations.length > 0 || hasProductDiscount(product, extensionList);
|
|
325
326
|
return {
|
|
326
327
|
product_title: productTitle,
|
|
327
328
|
product_quantity: quantity,
|
|
328
329
|
selling_price: formatMoney(sellingPrice, currencySymbol),
|
|
329
330
|
total_selling_price: formatCalculatedMoney(new _decimal.default(toMoneyNumber(sellingPrice)).mul(quantity), currencySymbol),
|
|
330
331
|
original_price: formatMoney(originalPrice, currencySymbol),
|
|
331
|
-
|
|
332
|
+
...(shouldIncludeBasePrice ? {
|
|
333
|
+
base_price: formatCalculatedMoney(basePrice ?? 0, currencySymbol)
|
|
334
|
+
} : {}),
|
|
332
335
|
total_original_price: formatMoney(new _decimal.default(toMoneyNumber(originalPrice)).mul(quantity), currencySymbol),
|
|
333
336
|
...(options.length ? {
|
|
334
337
|
options_total_price: sumNormalizedOptionTotals(options, currencySymbol)
|
|
@@ -386,6 +389,10 @@ function normalizeProductDiscounts(params) {
|
|
|
386
389
|
};
|
|
387
390
|
});
|
|
388
391
|
}
|
|
392
|
+
function hasProductDiscount(product, extensionList = []) {
|
|
393
|
+
const hasDiscountListAmount = normalizeArray(product.discount_list).some(discount => isNonZero(discount.amount ?? discount.value ?? discount.discount_amount));
|
|
394
|
+
return hasDiscountListAmount || extensionList.some(row => /^\s*-/.test(stringify(row?.value)));
|
|
395
|
+
}
|
|
389
396
|
function buildProductExtensionList(params) {
|
|
390
397
|
const {
|
|
391
398
|
product,
|
|
@@ -545,12 +552,15 @@ function normalizeProductCombinations(params) {
|
|
|
545
552
|
const optionsTotal = sumNormalizedOptionTotals(combinationsOptions, currencySymbol);
|
|
546
553
|
const explicitBasePrice = firstPresentValue(bundle.base_price, bundle.metadata?.source_product_price);
|
|
547
554
|
const basePrice = isPresentId(explicitBasePrice) ? explicitBasePrice : 0;
|
|
555
|
+
const shouldIncludeBasePrice = combinationsOptions.length > 0 || nestedCombinations.length > 0 || hasProductDiscount(bundle);
|
|
548
556
|
return {
|
|
549
557
|
product_title: baseTitle,
|
|
550
558
|
product_quantity: quantity,
|
|
551
559
|
price: formattedPrice,
|
|
552
560
|
total_selling_price: formatCalculatedMoney(new _decimal.default(toMoneyNumber(formattedPrice)).mul(quantity), currencySymbol),
|
|
553
|
-
|
|
561
|
+
...(shouldIncludeBasePrice ? {
|
|
562
|
+
base_price: formatCalculatedMoney(basePrice, currencySymbol)
|
|
563
|
+
} : {}),
|
|
554
564
|
combinations_options: combinationsOptions,
|
|
555
565
|
...(combinationsOptions.length ? {
|
|
556
566
|
options_total_price: optionsTotal
|
|
@@ -592,11 +602,14 @@ function normalizeExistingCombinations(combinations, locale, currencySymbol) {
|
|
|
592
602
|
const optionsAmount = sumMoneyValues(normalizedOptions.map(option => option.total_price));
|
|
593
603
|
const explicitBasePrice = firstPresentValue(combination.base_price);
|
|
594
604
|
const basePrice = isPresentId(explicitBasePrice) ? explicitBasePrice : 0;
|
|
605
|
+
const shouldIncludeBasePrice = normalizedOptions.length > 0 || nestedCombinations.length > 0 || hasProductDiscount(combination, normalizeArray(combination.extension_list));
|
|
595
606
|
return {
|
|
596
607
|
...snapshot,
|
|
597
608
|
product_quantity: quantity,
|
|
598
609
|
total_selling_price: formatCalculatedMoney(new _decimal.default(toMoneyNumber(unitPrice)).mul(quantity), currencySymbol),
|
|
599
|
-
|
|
610
|
+
...(shouldIncludeBasePrice ? {
|
|
611
|
+
base_price: formatCalculatedMoney(basePrice, currencySymbol)
|
|
612
|
+
} : {}),
|
|
600
613
|
...(Array.isArray(combination.combinations_options) ? {
|
|
601
614
|
combinations_options: normalizedOptions
|
|
602
615
|
} : Array.isArray(combination.options) ? {
|
|
@@ -1178,6 +1191,7 @@ function collectDisplayedWalletPassIds(payments) {
|
|
|
1178
1191
|
function buildPointCardSnapshotAssets(params) {
|
|
1179
1192
|
const snapshots = params.order.order_meta_list?.point_cards_snapshot;
|
|
1180
1193
|
if (!Array.isArray(snapshots)) return [];
|
|
1194
|
+
const snapshotTime = firstPresentValue(params.order.updated_at, params.order.created_at);
|
|
1181
1195
|
const seenSnapshotIds = new Set();
|
|
1182
1196
|
return snapshots.flatMap(snapshot => {
|
|
1183
1197
|
if (!snapshot || typeof snapshot !== 'object' || Array.isArray(snapshot)) return [];
|
|
@@ -1198,6 +1212,12 @@ function buildPointCardSnapshotAssets(params) {
|
|
|
1198
1212
|
value: trimDecimal(remainingPoints)
|
|
1199
1213
|
});
|
|
1200
1214
|
}
|
|
1215
|
+
if (isPresentId(snapshotTime)) {
|
|
1216
|
+
rows.push({
|
|
1217
|
+
item: formatDateTime(snapshotTime, params.locale),
|
|
1218
|
+
value: ''
|
|
1219
|
+
});
|
|
1220
|
+
}
|
|
1201
1221
|
return [rows];
|
|
1202
1222
|
});
|
|
1203
1223
|
}
|