@pisell/pisellos 2.3.120 → 2.3.121

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.
@@ -530,7 +530,7 @@ function isSameReceiptDiscount(left, right) {
530
530
  return leftResourceId === rightResourceId && getReceiptDiscountBundleMapId(left) === getReceiptDiscountBundleMapId(right) && String((_ref10 = (_ref11 = (_left$amount = left === null || left === void 0 ? void 0 : left.amount) !== null && _left$amount !== void 0 ? _left$amount : left === null || left === void 0 ? void 0 : left.value) !== null && _ref11 !== void 0 ? _ref11 : left === null || left === void 0 ? void 0 : left.discount_amount) !== null && _ref10 !== void 0 ? _ref10 : '') === String((_ref12 = (_ref13 = (_right$amount = right === null || right === void 0 ? void 0 : right.amount) !== null && _right$amount !== void 0 ? _right$amount : right === null || right === void 0 ? void 0 : right.value) !== null && _ref13 !== void 0 ? _ref13 : right === null || right === void 0 ? void 0 : right.discount_amount) !== null && _ref12 !== void 0 ? _ref12 : '');
531
531
  }
532
532
  function resolveProductBasePrice(product) {
533
- var _product$product_vari, _product$_origin, _product$_origin2;
533
+ var _product$product_vari, _ref14, _ref15, _product$product_quan2, _product$product_sku, _product$_origin, _product$_origin2;
534
534
  var metadata = product.metadata || {};
535
535
  var origin = product._origin || metadata.origin || {};
536
536
  var variantId = (_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : product.variant_id;
@@ -538,7 +538,18 @@ function resolveProductBasePrice(product) {
538
538
  return isSameId(item === null || item === void 0 ? void 0 : item.id, variantId);
539
539
  }) : undefined;
540
540
  var isV2 = metadata.price_schema_version === 2 || metadata.price_schema_version === '2';
541
- return firstPresentValue(metadata.source_product_price, variant === null || variant === void 0 ? void 0 : variant.price, (_product$_origin = product._origin) === null || _product$_origin === void 0 ? void 0 : _product$_origin.price, (_product$_origin2 = product._origin) === null || _product$_origin2 === void 0 ? void 0 : _product$_origin2.base_price, !isV2 ? metadata.main_product_original_price : undefined, product.base_price, product.price);
541
+ var quantity = toNumber((_ref14 = (_ref15 = (_product$product_quan2 = product.product_quantity) !== null && _product$product_quan2 !== void 0 ? _product$product_quan2 : product.quantity) !== null && _ref15 !== void 0 ? _ref15 : product.num) !== null && _ref14 !== void 0 ? _ref14 : 1, 1);
542
+ var hasEntitlementPass = normalizeArray(product.discount_list).some(function (discount) {
543
+ return getProductWalletDiscountType(discount) === 'entitlement_pass';
544
+ });
545
+ var hasOptions = normalizeArray(product.options).length > 0 || normalizeArray((_product$product_sku = product.product_sku) === null || _product$product_sku === void 0 ? void 0 : _product$product_sku.option).length > 0;
546
+ var hasCombinations = normalizeArray(product.combinations).length > 0 || normalizeArray(product.product_bundle).length > 0 || normalizeArray(product.bundle).length > 0;
547
+ var aggregateSourcePrice = firstPresentValue(metadata.source_product_price, product.price);
548
+ var originalPrice = product.original_price;
549
+ // 部分旧 entitlement 商品把 source/price 持久化成了整行总价,但
550
+ // original_price 仍是单件价。仅在等式能明确证明该口径时做窄幅回退。
551
+ var useOriginalPriceAsLegacyUnitPrice = hasEntitlementPass && quantity > 1 && !hasOptions && !hasCombinations && isNumericAmount(aggregateSourcePrice) && isNumericAmount(originalPrice) && new Decimal(aggregateSourcePrice).eq(new Decimal(originalPrice).mul(quantity));
552
+ return firstPresentValue(useOriginalPriceAsLegacyUnitPrice ? originalPrice : undefined, metadata.source_product_price, variant === null || variant === void 0 ? void 0 : variant.price, (_product$_origin = product._origin) === null || _product$_origin === void 0 ? void 0 : _product$_origin.price, (_product$_origin2 = product._origin) === null || _product$_origin2 === void 0 ? void 0 : _product$_origin2.base_price, !isV2 ? metadata.main_product_original_price : undefined, product.base_price, product.price);
542
553
  }
543
554
  function normalizeProductDiscounts(params) {
544
555
  var product = params.product,
@@ -546,16 +557,17 @@ function normalizeProductDiscounts(params) {
546
557
  currencySymbol = params.currencySymbol,
547
558
  quantity = params.quantity;
548
559
  var rows = normalizeArray(product.discount_list).filter(function (discount) {
549
- var _ref14, _discount$amount;
550
- var amount = (_ref14 = (_discount$amount = discount.amount) !== null && _discount$amount !== void 0 ? _discount$amount : discount.value) !== null && _ref14 !== void 0 ? _ref14 : discount.discount_amount;
560
+ var _ref16, _discount$amount;
561
+ var amount = (_ref16 = (_discount$amount = discount.amount) !== null && _discount$amount !== void 0 ? _discount$amount : discount.value) !== null && _ref16 !== void 0 ? _ref16 : discount.discount_amount;
551
562
  return isNonZero(amount);
552
563
  }).map(function (discount) {
553
- var _ref15, _discount$amount2;
564
+ var _ref17, _discount$amount2;
554
565
  var title = resolveDiscountTitleWithPercent(discount, locale);
555
- var amount = (_ref15 = (_discount$amount2 = discount.amount) !== null && _discount$amount2 !== void 0 ? _discount$amount2 : discount.value) !== null && _ref15 !== void 0 ? _ref15 : discount.discount_amount;
566
+ var amount = (_ref17 = (_discount$amount2 = discount.amount) !== null && _discount$amount2 !== void 0 ? _discount$amount2 : discount.value) !== null && _ref17 !== void 0 ? _ref17 : discount.discount_amount;
556
567
  var isMarkup = isManualMarkup(discount);
557
568
  var isAggregatedBundleDiscount = Boolean(getReceiptDiscountBundleMapId(discount));
558
- var totalAmount = new Decimal(toMoneyNumber(amount)).mul(isAggregatedBundleDiscount ? 1 : quantity);
569
+ var isEntitlementPass = getProductWalletDiscountType(discount) === 'entitlement_pass';
570
+ var totalAmount = new Decimal(toMoneyNumber(amount)).mul(isAggregatedBundleDiscount || isEntitlementPass ? 1 : quantity);
559
571
  var formattedAmount = isMarkup ? formatMoney(totalAmount.abs(), currencySymbol) : formatNegativeMoney(totalAmount, currencySymbol);
560
572
  return {
561
573
  item: title,
@@ -565,24 +577,24 @@ function normalizeProductDiscounts(params) {
565
577
  });
566
578
  return rows.sort(function (left, right) {
567
579
  return Number(right.isMarkup) - Number(left.isMarkup);
568
- }).map(function (_ref16) {
569
- var _isMarkup = _ref16.isMarkup,
570
- row = _objectWithoutProperties(_ref16, _excluded);
580
+ }).map(function (_ref18) {
581
+ var _isMarkup = _ref18.isMarkup,
582
+ row = _objectWithoutProperties(_ref18, _excluded);
571
583
  return row;
572
584
  });
573
585
  }
574
586
  function isManualMarkup(discount) {
575
- var _discount$discount, _ref17, _discount$amount3;
587
+ var _discount$discount, _ref19, _discount$amount3;
576
588
  if (discount.type !== 'product') return false;
577
589
  if (((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.discount_type) === 'change_price') return true;
578
- var amount = (_ref17 = (_discount$amount3 = discount.amount) !== null && _discount$amount3 !== void 0 ? _discount$amount3 : discount.value) !== null && _ref17 !== void 0 ? _ref17 : discount.discount_amount;
590
+ var amount = (_ref19 = (_discount$amount3 = discount.amount) !== null && _discount$amount3 !== void 0 ? _discount$amount3 : discount.value) !== null && _ref19 !== void 0 ? _ref19 : discount.discount_amount;
579
591
  return new Decimal(toMoneyNumber(amount)).isNegative();
580
592
  }
581
593
  function hasProductDiscount(product) {
582
594
  var extensionList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
583
595
  var hasDiscountListAmount = normalizeArray(product.discount_list).some(function (discount) {
584
- var _ref18, _discount$amount4;
585
- return isNonZero((_ref18 = (_discount$amount4 = discount.amount) !== null && _discount$amount4 !== void 0 ? _discount$amount4 : discount.value) !== null && _ref18 !== void 0 ? _ref18 : discount.discount_amount);
596
+ var _ref20, _discount$amount4;
597
+ return isNonZero((_ref20 = (_discount$amount4 = discount.amount) !== null && _discount$amount4 !== void 0 ? _discount$amount4 : discount.value) !== null && _ref20 !== void 0 ? _ref20 : discount.discount_amount);
586
598
  });
587
599
  return hasDiscountListAmount || extensionList.some(function (row) {
588
600
  return /^\s*-/.test(stringify(row === null || row === void 0 ? void 0 : row.value));
@@ -667,8 +679,8 @@ function resolveDiscountTitleWithPercent(discount, locale) {
667
679
  return "".concat(title, " (").concat(percent, "%)");
668
680
  }
669
681
  function resolveDiscountTitle(discount, locale) {
670
- var _ref19, _ref20, _ref21, _ref22, _discount$discount$na, _discount$discount4, _discount$discount5, _discount$discount6;
671
- var title = getLocalizedValue((_ref19 = (_ref20 = (_ref21 = (_ref22 = (_discount$discount$na = (_discount$discount4 = discount.discount) === null || _discount$discount4 === void 0 ? void 0 : _discount$discount4.name) !== null && _discount$discount$na !== void 0 ? _discount$discount$na : (_discount$discount5 = discount.discount) === null || _discount$discount5 === void 0 ? void 0 : _discount$discount5.title) !== null && _ref22 !== void 0 ? _ref22 : (_discount$discount6 = discount.discount) === null || _discount$discount6 === void 0 ? void 0 : _discount$discount6.message) !== null && _ref21 !== void 0 ? _ref21 : discount.name) !== null && _ref20 !== void 0 ? _ref20 : discount.title) !== null && _ref19 !== void 0 ? _ref19 : discount.message, locale);
682
+ var _ref21, _ref22, _ref23, _ref24, _discount$discount$na, _discount$discount4, _discount$discount5, _discount$discount6;
683
+ var title = getLocalizedValue((_ref21 = (_ref22 = (_ref23 = (_ref24 = (_discount$discount$na = (_discount$discount4 = discount.discount) === null || _discount$discount4 === void 0 ? void 0 : _discount$discount4.name) !== null && _discount$discount$na !== void 0 ? _discount$discount$na : (_discount$discount5 = discount.discount) === null || _discount$discount5 === void 0 ? void 0 : _discount$discount5.title) !== null && _ref24 !== void 0 ? _ref24 : (_discount$discount6 = discount.discount) === null || _discount$discount6 === void 0 ? void 0 : _discount$discount6.message) !== null && _ref23 !== void 0 ? _ref23 : discount.name) !== null && _ref22 !== void 0 ? _ref22 : discount.title) !== null && _ref21 !== void 0 ? _ref21 : discount.message, locale);
672
684
  if (title) return title;
673
685
  if (discount.type === 'product') {
674
686
  return label(locale, isManualMarkup(discount) ? 'manualMarkup' : 'manualDiscount');
@@ -688,17 +700,17 @@ function resolveProductTitle(params) {
688
700
  return getProductTitleSource(fallbackProduct, locale);
689
701
  }
690
702
  function normalizeProductOptions(params) {
691
- var _product$product_sku;
703
+ var _product$product_sku2;
692
704
  var product = params.product,
693
705
  locale = params.locale,
694
706
  currencySymbol = params.currencySymbol,
695
707
  parentProduct = params.parentProduct;
696
- 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 : [];
708
+ var rawOptions = Array.isArray(params.options) ? params.options : Array.isArray(product.options) ? product.options : Array.isArray((_product$product_sku2 = product.product_sku) === null || _product$product_sku2 === void 0 ? void 0 : _product$product_sku2.option) ? product.product_sku.option : [];
697
709
  return rawOptions.map(function (option) {
698
- var _ref23, _option$original_pric, _ref24, _option$num, _ref25, _option$value;
699
- var price = (_ref23 = (_option$original_pric = option.original_price) !== null && _option$original_pric !== void 0 ? _option$original_pric : option.add_price) !== null && _ref23 !== void 0 ? _ref23 : option.price;
700
- var quantity = toNumber((_ref24 = (_option$num = option.num) !== null && _option$num !== void 0 ? _option$num : option.quantity) !== null && _ref24 !== void 0 ? _ref24 : 1, 1);
701
- var value = (_ref25 = (_option$value = option.value) !== null && _option$value !== void 0 ? _option$value : option.option) !== null && _ref25 !== void 0 ? _ref25 : option.item;
710
+ var _ref25, _option$original_pric, _ref26, _option$num, _ref27, _option$value;
711
+ var price = (_ref25 = (_option$original_pric = option.original_price) !== null && _option$original_pric !== void 0 ? _option$original_pric : option.add_price) !== null && _ref25 !== void 0 ? _ref25 : option.price;
712
+ var quantity = toNumber((_ref26 = (_option$num = option.num) !== null && _option$num !== void 0 ? _option$num : option.quantity) !== null && _ref26 !== void 0 ? _ref26 : 1, 1);
713
+ var value = (_ref27 = (_option$value = option.value) !== null && _option$value !== void 0 ? _option$value : option.option) !== null && _ref27 !== void 0 ? _ref27 : option.item;
702
714
  var name = getProductTitleSource(option, locale) || resolveOptionTitleFromParentProduct({
703
715
  option: option,
704
716
  parentProduct: parentProduct,
@@ -725,7 +737,7 @@ function normalizeProductCombinations(params) {
725
737
  parentProduct = params.parentProduct;
726
738
  var bundles = Array.isArray(product.product_bundle) ? product.product_bundle : [];
727
739
  return bundles.map(function (bundle) {
728
- var _ref26, _bundle$num;
740
+ var _ref28, _bundle$num;
729
741
  var combinationsOptions = normalizeProductOptions({
730
742
  product: {},
731
743
  locale: locale,
@@ -741,7 +753,7 @@ function normalizeProductCombinations(params) {
741
753
  });
742
754
  var productNote = resolveProductNote(bundle, locale);
743
755
  var nestedCombinations = Array.isArray(bundle.combinations) ? normalizeExistingCombinations(bundle.combinations, locale, currencySymbol) : [];
744
- var quantity = toNumber((_ref26 = (_bundle$num = bundle.num) !== null && _bundle$num !== void 0 ? _bundle$num : bundle.quantity) !== null && _ref26 !== void 0 ? _ref26 : 1, 1);
756
+ var quantity = toNumber((_ref28 = (_bundle$num = bundle.num) !== null && _bundle$num !== void 0 ? _bundle$num : bundle.quantity) !== null && _ref28 !== void 0 ? _ref28 : 1, 1);
745
757
  var formattedPrice = formatBundlePrice(bundle, currencySymbol);
746
758
  var optionsTotal = sumNormalizedOptionTotals(combinationsOptions, currencySymbol);
747
759
  var explicitBasePrice = resolveCombinationBasePrice(bundle);
@@ -778,7 +790,7 @@ function normalizeProductCombinations(params) {
778
790
  }
779
791
  function normalizeExistingCombinations(combinations, locale, currencySymbol) {
780
792
  return combinations.map(function (combination) {
781
- var _ref27, _ref28, _combination$product_, _firstPresentValue;
793
+ var _ref29, _ref30, _combination$product_, _firstPresentValue;
782
794
  if (!combination || _typeof(combination) !== 'object' || Array.isArray(combination)) {
783
795
  return combination;
784
796
  }
@@ -796,7 +808,7 @@ function normalizeExistingCombinations(combinations, locale, currencySymbol) {
796
808
  delete snapshot.note;
797
809
  delete snapshot.combinations;
798
810
  delete snapshot.discount_list;
799
- var quantity = toNumber((_ref27 = (_ref28 = (_combination$product_ = combination.product_quantity) !== null && _combination$product_ !== void 0 ? _combination$product_ : combination.num) !== null && _ref28 !== void 0 ? _ref28 : combination.quantity) !== null && _ref27 !== void 0 ? _ref27 : 1, 1);
811
+ var quantity = toNumber((_ref29 = (_ref30 = (_combination$product_ = combination.product_quantity) !== null && _combination$product_ !== void 0 ? _combination$product_ : combination.num) !== null && _ref30 !== void 0 ? _ref30 : combination.quantity) !== null && _ref29 !== void 0 ? _ref29 : 1, 1);
800
812
  var unitPrice = (_firstPresentValue = firstPresentValue(combination.selling_price, combination.price, combination.original_price)) !== null && _firstPresentValue !== void 0 ? _firstPresentValue : 0;
801
813
  var optionsAmount = sumMoneyValues(normalizedOptions.map(function (option) {
802
814
  return option.total_price;
@@ -879,7 +891,7 @@ function buildProductAllergyMap(order, locale) {
879
891
  return allergyByProductUid;
880
892
  }
881
893
  function resolveBundleProductTitle(params) {
882
- var _ref29, _ref30, _bundle$bundle_produc;
894
+ var _ref31, _ref32, _bundle$bundle_produc;
883
895
  var bundle = params.bundle,
884
896
  productMap = params.productMap,
885
897
  locale = params.locale,
@@ -892,7 +904,7 @@ function resolveBundleProductTitle(params) {
892
904
  });
893
905
  var parentBundleTitle = parentBundleItem ? getProductTitleSource(parentBundleItem, locale) : '';
894
906
  if (parentBundleTitle) return parentBundleTitle;
895
- var productId = (_ref29 = (_ref30 = (_bundle$bundle_produc = bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle._bundle_product_id) !== null && _ref30 !== void 0 ? _ref30 : bundle.product_id) !== null && _ref29 !== void 0 ? _ref29 : bundle.id;
907
+ var productId = (_ref31 = (_ref32 = (_bundle$bundle_produc = bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle._bundle_product_id) !== null && _ref32 !== void 0 ? _ref32 : bundle.product_id) !== null && _ref31 !== void 0 ? _ref31 : bundle.id;
896
908
  var fallbackProduct = resolveProductFromMap(productId, productMap);
897
909
  if (!fallbackProduct) return '';
898
910
  return getProductTitleSource(fallbackProduct, locale);
@@ -944,10 +956,10 @@ function resolveVariantTextFromSkuKey(params) {
944
956
  }
945
957
  function resolveVariantTextFromNameMap(params) {
946
958
  if (!params.nameMap || _typeof(params.nameMap) !== 'object') return '';
947
- return Object.entries(params.nameMap).map(function (_ref31) {
948
- var _ref32 = _slicedToArray(_ref31, 2),
949
- groupPositionId = _ref32[0],
950
- value = _ref32[1];
959
+ return Object.entries(params.nameMap).map(function (_ref33) {
960
+ var _ref34 = _slicedToArray(_ref33, 2),
961
+ groupPositionId = _ref34[0],
962
+ value = _ref34[1];
951
963
  var group = resolveVariantGroup(params.parentProduct, groupPositionId);
952
964
  if (!group) return '';
953
965
  var groupName = getLocalizedValue(group.name, params.locale);
@@ -981,12 +993,12 @@ function getProductTitleSource(source, locale) {
981
993
  return resolveTitleValue(source.product_title, locale) || resolveTitleValue(source.title, locale) || resolveTitleValue(source.name, locale);
982
994
  }
983
995
  function resolveTitleValue(value, locale) {
984
- var _ref33, _ref34, _ref35, _ref36, _value$locale;
996
+ var _ref35, _ref36, _ref37, _ref38, _value$locale;
985
997
  if (value === undefined || value === null) return '';
986
998
  if (_typeof(value) !== 'object') return stringify(value);
987
999
  var dashedLocale = locale.replace('_', '-');
988
1000
  var underscoredLocale = locale.replace('-', '_');
989
- return stringify((_ref33 = (_ref34 = (_ref35 = (_ref36 = (_value$locale = value[locale]) !== null && _value$locale !== void 0 ? _value$locale : value[dashedLocale]) !== null && _ref36 !== void 0 ? _ref36 : value[underscoredLocale]) !== null && _ref35 !== void 0 ? _ref35 : value.original) !== null && _ref34 !== void 0 ? _ref34 : value.auto) !== null && _ref33 !== void 0 ? _ref33 : '');
1001
+ return stringify((_ref35 = (_ref36 = (_ref37 = (_ref38 = (_value$locale = value[locale]) !== null && _value$locale !== void 0 ? _value$locale : value[dashedLocale]) !== null && _ref38 !== void 0 ? _ref38 : value[underscoredLocale]) !== null && _ref37 !== void 0 ? _ref37 : value.original) !== null && _ref36 !== void 0 ? _ref36 : value.auto) !== null && _ref35 !== void 0 ? _ref35 : '');
990
1002
  }
991
1003
  function resolveOptionTitleFromParentProduct(params) {
992
1004
  var option = params.option,
@@ -1004,17 +1016,17 @@ function flattenOptionItems(parentProduct) {
1004
1016
  return optionGroups.flatMap(function (group) {
1005
1017
  var items = normalizeArray(group.option_item || group.option_items || group.option || group.options || group.items || group.children || group.product_option_item);
1006
1018
  return items.map(function (item) {
1007
- var _ref37, _item$option_group_id;
1019
+ var _ref39, _item$option_group_id;
1008
1020
  return _objectSpread(_objectSpread({}, item), {}, {
1009
- option_group_id: (_ref37 = (_item$option_group_id = item.option_group_id) !== null && _item$option_group_id !== void 0 ? _item$option_group_id : group.id) !== null && _ref37 !== void 0 ? _ref37 : group.option_group_id
1021
+ option_group_id: (_ref39 = (_item$option_group_id = item.option_group_id) !== null && _item$option_group_id !== void 0 ? _item$option_group_id : group.id) !== null && _ref39 !== void 0 ? _ref39 : group.option_group_id
1010
1022
  });
1011
1023
  });
1012
1024
  });
1013
1025
  }
1014
1026
  function isOptionItemMatch(option, item) {
1015
- var _ref38, _option$option_group_, _ref39, _item$option_group_it, _option$option_group_2, _item$option_group_id2;
1016
- var optionItemId = (_ref38 = (_option$option_group_ = option.option_group_item_id) !== null && _option$option_group_ !== void 0 ? _option$option_group_ : option.product_option_item_id) !== null && _ref38 !== void 0 ? _ref38 : option.id;
1017
- var itemId = (_ref39 = (_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 && _ref39 !== void 0 ? _ref39 : item.id;
1027
+ var _ref40, _option$option_group_, _ref41, _item$option_group_it, _option$option_group_2, _item$option_group_id2;
1028
+ var optionItemId = (_ref40 = (_option$option_group_ = option.option_group_item_id) !== null && _option$option_group_ !== void 0 ? _option$option_group_ : option.product_option_item_id) !== null && _ref40 !== void 0 ? _ref40 : option.id;
1029
+ var itemId = (_ref41 = (_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 && _ref41 !== void 0 ? _ref41 : item.id;
1018
1030
  if (!isSameId(optionItemId, itemId)) return false;
1019
1031
  var optionGroupId = (_option$option_group_2 = option.option_group_id) !== null && _option$option_group_2 !== void 0 ? _option$option_group_2 : option.group_id;
1020
1032
  var itemGroupId = (_item$option_group_id2 = item.option_group_id) !== null && _item$option_group_id2 !== void 0 ? _item$option_group_id2 : item.group_id;
@@ -1024,16 +1036,16 @@ function isOptionItemMatch(option, item) {
1024
1036
  return true;
1025
1037
  }
1026
1038
  function resolveBundleItemFromParentProduct(params) {
1027
- var _ref40, _bundle$bundle_varian, _bundle$bundle_id, _bundle$bundle_group_, _ref42, _bundle$bundle_produc2;
1039
+ var _ref42, _bundle$bundle_varian, _bundle$bundle_id, _bundle$bundle_group_, _ref44, _bundle$bundle_produc2;
1028
1040
  var bundle = params.bundle,
1029
1041
  parentProduct = params.parentProduct;
1030
1042
  if (!parentProduct) return null;
1031
1043
  var bundleItems = flattenBundleItems(parentProduct);
1032
- var bundleVariantId = (_ref40 = (_bundle$bundle_varian = bundle.bundle_variant_id) !== null && _bundle$bundle_varian !== void 0 ? _bundle$bundle_varian : bundle.variant_id) !== null && _ref40 !== void 0 ? _ref40 : bundle.product_variant_id;
1044
+ var bundleVariantId = (_ref42 = (_bundle$bundle_varian = bundle.bundle_variant_id) !== null && _bundle$bundle_varian !== void 0 ? _bundle$bundle_varian : bundle.variant_id) !== null && _ref42 !== void 0 ? _ref42 : bundle.product_variant_id;
1033
1045
  if (isNonZeroId(bundleVariantId)) {
1034
1046
  var matchedByVariant = bundleItems.find(function (item) {
1035
- var _ref41, _item$bundle_variant_;
1036
- return isSameId((_ref41 = (_item$bundle_variant_ = item.bundle_variant_id) !== null && _item$bundle_variant_ !== void 0 ? _item$bundle_variant_ : item.variant_id) !== null && _ref41 !== void 0 ? _ref41 : item.product_variant_id, bundleVariantId);
1047
+ var _ref43, _item$bundle_variant_;
1048
+ return isSameId((_ref43 = (_item$bundle_variant_ = item.bundle_variant_id) !== null && _item$bundle_variant_ !== void 0 ? _item$bundle_variant_ : item.variant_id) !== null && _ref43 !== void 0 ? _ref43 : item.product_variant_id, bundleVariantId);
1037
1049
  });
1038
1050
  if (matchedByVariant) return matchedByVariant;
1039
1051
  }
@@ -1046,18 +1058,18 @@ function resolveBundleItemFromParentProduct(params) {
1046
1058
  if (matchedByBundleId) return matchedByBundleId;
1047
1059
  }
1048
1060
  var bundleGroupId = (_bundle$bundle_group_ = bundle.bundle_group_id) !== null && _bundle$bundle_group_ !== void 0 ? _bundle$bundle_group_ : bundle.group_id;
1049
- var bundleProductId = (_ref42 = (_bundle$bundle_produc2 = bundle.bundle_product_id) !== null && _bundle$bundle_produc2 !== void 0 ? _bundle$bundle_produc2 : bundle._bundle_product_id) !== null && _ref42 !== void 0 ? _ref42 : bundle.product_id;
1061
+ var bundleProductId = (_ref44 = (_bundle$bundle_produc2 = bundle.bundle_product_id) !== null && _bundle$bundle_produc2 !== void 0 ? _bundle$bundle_produc2 : bundle._bundle_product_id) !== null && _ref44 !== void 0 ? _ref44 : bundle.product_id;
1050
1062
  if (isPresentId(bundleGroupId) && isPresentId(bundleProductId)) {
1051
1063
  var matchedByGroupAndProduct = bundleItems.find(function (item) {
1052
- var _item$group_id, _ref43, _item$bundle_product_;
1053
- return isSameId((_item$group_id = item.group_id) !== null && _item$group_id !== void 0 ? _item$group_id : item.bundle_group_id, bundleGroupId) && isSameId((_ref43 = (_item$bundle_product_ = item.bundle_product_id) !== null && _item$bundle_product_ !== void 0 ? _item$bundle_product_ : item._bundle_product_id) !== null && _ref43 !== void 0 ? _ref43 : item.product_id, bundleProductId);
1064
+ var _item$group_id, _ref45, _item$bundle_product_;
1065
+ return isSameId((_item$group_id = item.group_id) !== null && _item$group_id !== void 0 ? _item$group_id : item.bundle_group_id, bundleGroupId) && isSameId((_ref45 = (_item$bundle_product_ = item.bundle_product_id) !== null && _item$bundle_product_ !== void 0 ? _item$bundle_product_ : item._bundle_product_id) !== null && _ref45 !== void 0 ? _ref45 : item.product_id, bundleProductId);
1054
1066
  });
1055
1067
  if (matchedByGroupAndProduct) return matchedByGroupAndProduct;
1056
1068
  }
1057
1069
  if (isPresentId(bundleProductId)) {
1058
1070
  return bundleItems.find(function (item) {
1059
- var _ref44, _item$bundle_product_2;
1060
- return isSameId((_ref44 = (_item$bundle_product_2 = item.bundle_product_id) !== null && _item$bundle_product_2 !== void 0 ? _item$bundle_product_2 : item._bundle_product_id) !== null && _ref44 !== void 0 ? _ref44 : item.product_id, bundleProductId);
1071
+ var _ref46, _item$bundle_product_2;
1072
+ return isSameId((_ref46 = (_item$bundle_product_2 = item.bundle_product_id) !== null && _item$bundle_product_2 !== void 0 ? _item$bundle_product_2 : item._bundle_product_id) !== null && _ref46 !== void 0 ? _ref46 : item.product_id, bundleProductId);
1061
1073
  }) || null;
1062
1074
  }
1063
1075
  return null;
@@ -1067,9 +1079,9 @@ function flattenBundleItems(parentProduct) {
1067
1079
  return bundleGroups.flatMap(function (group) {
1068
1080
  var items = Array.isArray(group.bundle_item) ? group.bundle_item : [];
1069
1081
  return items.map(function (item) {
1070
- var _ref45, _item$group_id2;
1082
+ var _ref47, _item$group_id2;
1071
1083
  return _objectSpread(_objectSpread({}, item), {}, {
1072
- group_id: (_ref45 = (_item$group_id2 = item.group_id) !== null && _item$group_id2 !== void 0 ? _item$group_id2 : group.id) !== null && _ref45 !== void 0 ? _ref45 : group.group_id
1084
+ group_id: (_ref47 = (_item$group_id2 = item.group_id) !== null && _item$group_id2 !== void 0 ? _item$group_id2 : group.id) !== null && _ref47 !== void 0 ? _ref47 : group.group_id
1073
1085
  });
1074
1086
  });
1075
1087
  });
@@ -1093,8 +1105,8 @@ function isSameId(left, right) {
1093
1105
  return String(left) === String(right);
1094
1106
  }
1095
1107
  function formatBundlePrice(bundle, currencySymbol) {
1096
- var _ref46, _ref47, _bundle$bundle_sellin;
1097
- var value = (_ref46 = (_ref47 = (_bundle$bundle_sellin = bundle.bundle_selling_price) !== null && _bundle$bundle_sellin !== void 0 ? _bundle$bundle_sellin : bundle.bundle_sum_price) !== null && _ref47 !== void 0 ? _ref47 : bundle.price) !== null && _ref46 !== void 0 ? _ref46 : 0;
1108
+ var _ref48, _ref49, _bundle$bundle_sellin;
1109
+ var value = (_ref48 = (_ref49 = (_bundle$bundle_sellin = bundle.bundle_selling_price) !== null && _bundle$bundle_sellin !== void 0 ? _bundle$bundle_sellin : bundle.bundle_sum_price) !== null && _ref49 !== void 0 ? _ref49 : bundle.price) !== null && _ref48 !== void 0 ? _ref48 : 0;
1098
1110
  var amount = new Decimal(toMoneyNumber(value));
1099
1111
  // 套餐价格协议:只有 markdown 是减价;加价与商品原价都保持正数。
1100
1112
  var isNegative = bundle.price_type === 'markdown';
@@ -1112,9 +1124,9 @@ function buildFees(params) {
1112
1124
  financials = params.financials;
1113
1125
  var fees = [];
1114
1126
  for (var _i2 = 0, _normalizeArray2 = normalizeArray(order.surcharges || summary.surcharges); _i2 < _normalizeArray2.length; _i2++) {
1115
- var _ref48, _surcharge$amount;
1127
+ var _ref50, _surcharge$amount;
1116
1128
  var surcharge = _normalizeArray2[_i2];
1117
- var value = (_ref48 = (_surcharge$amount = surcharge.amount) !== null && _surcharge$amount !== void 0 ? _surcharge$amount : surcharge.value) !== null && _ref48 !== void 0 ? _ref48 : surcharge.total_amount;
1129
+ var value = (_ref50 = (_surcharge$amount = surcharge.amount) !== null && _surcharge$amount !== void 0 ? _surcharge$amount : surcharge.value) !== null && _ref50 !== void 0 ? _ref50 : surcharge.total_amount;
1118
1130
  if (!isNonZero(value)) continue;
1119
1131
  fees.push({
1120
1132
  item: getLocalizedValue(surcharge.name || surcharge.title || surcharge.item, locale),
@@ -1216,9 +1228,9 @@ function resolveTaxTitle(params) {
1216
1228
  }
1217
1229
  function calculateProductOriginalAmount(order) {
1218
1230
  return normalizeArray(order.products).reduce(function (total, product) {
1219
- var _ref49, _ref50, _product$product_quan2, _ref51, _ref52, _ref53, _product$original_pri2;
1220
- var quantity = toNumber((_ref49 = (_ref50 = (_product$product_quan2 = product.product_quantity) !== null && _product$product_quan2 !== void 0 ? _product$product_quan2 : product.quantity) !== null && _ref50 !== void 0 ? _ref50 : product.num) !== null && _ref49 !== void 0 ? _ref49 : 1, 1);
1221
- var originalPrice = (_ref51 = (_ref52 = (_ref53 = (_product$original_pri2 = product.original_price) !== null && _product$original_pri2 !== void 0 ? _product$original_pri2 : product.selling_price) !== null && _ref53 !== void 0 ? _ref53 : product.payment_price) !== null && _ref52 !== void 0 ? _ref52 : product.price) !== null && _ref51 !== void 0 ? _ref51 : 0;
1231
+ var _ref51, _ref52, _product$product_quan3, _ref53, _ref54, _ref55, _product$original_pri2;
1232
+ var quantity = toNumber((_ref51 = (_ref52 = (_product$product_quan3 = product.product_quantity) !== null && _product$product_quan3 !== void 0 ? _product$product_quan3 : product.quantity) !== null && _ref52 !== void 0 ? _ref52 : product.num) !== null && _ref51 !== void 0 ? _ref51 : 1, 1);
1233
+ var originalPrice = (_ref53 = (_ref54 = (_ref55 = (_product$original_pri2 = product.original_price) !== null && _product$original_pri2 !== void 0 ? _product$original_pri2 : product.selling_price) !== null && _ref55 !== void 0 ? _ref55 : product.payment_price) !== null && _ref54 !== void 0 ? _ref54 : product.price) !== null && _ref53 !== void 0 ? _ref53 : 0;
1222
1234
  return total.plus(new Decimal(toMoneyNumber(originalPrice)).mul(quantity));
1223
1235
  }, new Decimal(0));
1224
1236
  }
@@ -1261,8 +1273,11 @@ function buildDelivery(order, locale) {
1261
1273
  return items;
1262
1274
  }
1263
1275
  function buildAppointment(order, locale) {
1264
- var _order$metadata13, _order$metadata14, _order$form_data;
1265
- var bookings = sortBookings(normalizeArray(order.bookings));
1276
+ var _order$metadata13, _order$metadata14, _order$metadata15, _order$form_data;
1277
+ var parentScheduleId = (_order$metadata13 = order.metadata) === null || _order$metadata13 === void 0 ? void 0 : _order$metadata13.appointment_booking_parent_schedule_id;
1278
+ var bookings = sortBookings(normalizeArray(order.bookings).filter(function (booking) {
1279
+ return isReceiptAppointmentBooking(booking, parentScheduleId);
1280
+ }));
1266
1281
  if (bookings.length) {
1267
1282
  var allResources = normalizeArray(order.resources || order.resource_list);
1268
1283
  return bookings.flatMap(function (booking) {
@@ -1274,13 +1289,26 @@ function buildAppointment(order, locale) {
1274
1289
  });
1275
1290
  });
1276
1291
  }
1277
- var tableName = order.table_name || ((_order$metadata13 = order.metadata) === null || _order$metadata13 === void 0 ? void 0 : _order$metadata13.table_name) || ((_order$metadata14 = order.metadata) === null || _order$metadata14 === void 0 || (_order$metadata14 = _order$metadata14.table) === null || _order$metadata14 === void 0 ? void 0 : _order$metadata14.name) || ((_order$form_data = order.form_data) === null || _order$form_data === void 0 ? void 0 : _order$form_data.table_name);
1292
+ var tableName = order.table_name || ((_order$metadata14 = order.metadata) === null || _order$metadata14 === void 0 ? void 0 : _order$metadata14.table_name) || ((_order$metadata15 = order.metadata) === null || _order$metadata15 === void 0 || (_order$metadata15 = _order$metadata15.table) === null || _order$metadata15 === void 0 ? void 0 : _order$metadata15.name) || ((_order$form_data = order.form_data) === null || _order$form_data === void 0 ? void 0 : _order$form_data.table_name);
1278
1293
  if (!tableName) return [];
1279
1294
  return [{
1280
1295
  item: label(locale, 'table'),
1281
1296
  value: getLocalizedValue(tableName, locale)
1282
1297
  }];
1283
1298
  }
1299
+ function isReceiptAppointmentBooking(booking, parentScheduleId) {
1300
+ if (!booking || _typeof(booking) !== 'object' || Array.isArray(booking)) {
1301
+ return false;
1302
+ }
1303
+ if (isPresentId(parentScheduleId) && isSameId(booking.schedule_event_id, parentScheduleId)) {
1304
+ return false;
1305
+ }
1306
+ var parentId = booking.parent_id;
1307
+ if (parentId === undefined || parentId === null || parentId === '') {
1308
+ return true;
1309
+ }
1310
+ return Number(parentId) !== 0;
1311
+ }
1284
1312
  function buildAppointmentRows(params) {
1285
1313
  var _booking$metadata, _booking$metadata2, _booking$holder$name, _booking$holder, _booking$metadata3;
1286
1314
  var booking = params.booking,
@@ -1352,9 +1380,9 @@ function resolveBookingResourcesForReceipt(booking, allResources, bookingCount)
1352
1380
  _step3;
1353
1381
  try {
1354
1382
  for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
1355
- var _ref55, _resource$id2;
1383
+ var _ref57, _resource$id2;
1356
1384
  var resource = _step3.value;
1357
- var id = stringify((_ref55 = (_resource$id2 = resource.id) !== null && _resource$id2 !== void 0 ? _resource$id2 : resource.resource_id) !== null && _ref55 !== void 0 ? _ref55 : resource.relation_id).trim();
1385
+ var id = stringify((_ref57 = (_resource$id2 = resource.id) !== null && _resource$id2 !== void 0 ? _resource$id2 : resource.resource_id) !== null && _ref57 !== void 0 ? _ref57 : resource.relation_id).trim();
1358
1386
  if (id) resourceIds.add(id);
1359
1387
  }
1360
1388
  } catch (err) {
@@ -1364,8 +1392,8 @@ function resolveBookingResourcesForReceipt(booking, allResources, bookingCount)
1364
1392
  }
1365
1393
  if (resourceIds.size) {
1366
1394
  var matched = allResources.filter(function (resource) {
1367
- var _ref54, _resource$id;
1368
- return resourceIds.has(stringify((_ref54 = (_resource$id = resource.id) !== null && _resource$id !== void 0 ? _resource$id : resource.resource_id) !== null && _ref54 !== void 0 ? _ref54 : resource.relation_id).trim());
1395
+ var _ref56, _resource$id;
1396
+ return resourceIds.has(stringify((_ref56 = (_resource$id = resource.id) !== null && _resource$id !== void 0 ? _resource$id : resource.resource_id) !== null && _ref56 !== void 0 ? _ref56 : resource.relation_id).trim());
1369
1397
  });
1370
1398
  if (matched.length) return matched;
1371
1399
  }
@@ -1398,8 +1426,8 @@ function sortBookings(bookings) {
1398
1426
  }
1399
1427
  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));
1400
1428
  return bookingUidOrder || left.index - right.index;
1401
- }).map(function (_ref56) {
1402
- var booking = _ref56.booking;
1429
+ }).map(function (_ref58) {
1430
+ var booking = _ref58.booking;
1403
1431
  return booking;
1404
1432
  });
1405
1433
  }
@@ -1461,8 +1489,8 @@ function buildRefundData(params) {
1461
1489
  result.set(identity, candidate);
1462
1490
  }
1463
1491
  return result;
1464
- }, new Map()).values()).filter(function (_ref57) {
1465
- var refund = _ref57.refund;
1492
+ }, new Map()).values()).filter(function (_ref59) {
1493
+ var refund = _ref59.refund;
1466
1494
  return isPrintableRefund(refund);
1467
1495
  }).sort(function (left, right) {
1468
1496
  var leftTime = refundTimestamp(left.refund);
@@ -1470,9 +1498,9 @@ function buildRefundData(params) {
1470
1498
  if (leftTime !== rightTime) return leftTime < rightTime ? -1 : 1;
1471
1499
  return left.index - right.index;
1472
1500
  });
1473
- return refunds.map(function (_ref58) {
1501
+ return refunds.map(function (_ref60) {
1474
1502
  var _firstPresentValue8;
1475
- var refund = _ref58.refund;
1503
+ var refund = _ref60.refund;
1476
1504
  var payment = resolveRefundPayment(refund, payments);
1477
1505
  var methodName = paymentMethodName(payment, params.locale) || label(params.locale, 'refund');
1478
1506
  var amount = (_firstPresentValue8 = firstPresentValue(refund.amount, refund.refund_amount, refund.total_amount)) !== null && _firstPresentValue8 !== void 0 ? _firstPresentValue8 : 0;
@@ -2254,8 +2282,8 @@ function buildPaymentItems(params) {
2254
2282
  virtualCurrencyUnit: virtualCurrencyUnit
2255
2283
  })));
2256
2284
  } else {
2257
- var _ref59, _payment$remaining_am, _payment$metadata;
2258
- var remainingAmount = (_ref59 = (_payment$remaining_am = payment.remaining_amount) !== null && _payment$remaining_am !== void 0 ? _payment$remaining_am : payment.balance) !== null && _ref59 !== void 0 ? _ref59 : (_payment$metadata = payment.metadata) === null || _payment$metadata === void 0 ? void 0 : _payment$metadata.remaining_amount;
2285
+ var _ref61, _payment$remaining_am, _payment$metadata;
2286
+ var remainingAmount = (_ref61 = (_payment$remaining_am = payment.remaining_amount) !== null && _payment$remaining_am !== void 0 ? _payment$remaining_am : payment.balance) !== null && _ref61 !== void 0 ? _ref61 : (_payment$metadata = payment.metadata) === null || _payment$metadata === void 0 ? void 0 : _payment$metadata.remaining_amount;
2259
2287
  if (remainingAmount !== undefined && remainingAmount !== null) {
2260
2288
  items.push({
2261
2289
  item: label(locale, 'remainingAmount'),
@@ -2418,12 +2446,12 @@ function label(locale, key) {
2418
2446
  return ((_LABELS$locale = LABELS[locale]) === null || _LABELS$locale === void 0 ? void 0 : _LABELS$locale[key]) || LABELS.en[key] || key;
2419
2447
  }
2420
2448
  function getLocalizedValue(value, locale) {
2421
- var _ref60, _ref61, _ref62, _ref63, _ref64, _ref65, _value$locale2;
2449
+ var _ref62, _ref63, _ref64, _ref65, _ref66, _ref67, _value$locale2;
2422
2450
  if (value === undefined || value === null) return '';
2423
2451
  if (_typeof(value) !== 'object') return stringify(value);
2424
2452
  var dashedLocale = locale.replace('_', '-');
2425
2453
  var underscoredLocale = locale.replace('-', '_');
2426
- return stringify((_ref60 = (_ref61 = (_ref62 = (_ref63 = (_ref64 = (_ref65 = (_value$locale2 = value[locale]) !== null && _value$locale2 !== void 0 ? _value$locale2 : value[dashedLocale]) !== null && _ref65 !== void 0 ? _ref65 : value[underscoredLocale]) !== null && _ref64 !== void 0 ? _ref64 : value.original) !== null && _ref63 !== void 0 ? _ref63 : value.auto) !== null && _ref62 !== void 0 ? _ref62 : value.default) !== null && _ref61 !== void 0 ? _ref61 : value.en) !== null && _ref60 !== void 0 ? _ref60 : '');
2454
+ return stringify((_ref62 = (_ref63 = (_ref64 = (_ref65 = (_ref66 = (_ref67 = (_value$locale2 = value[locale]) !== null && _value$locale2 !== void 0 ? _value$locale2 : value[dashedLocale]) !== null && _ref67 !== void 0 ? _ref67 : value[underscoredLocale]) !== null && _ref66 !== void 0 ? _ref66 : value.original) !== null && _ref65 !== void 0 ? _ref65 : value.auto) !== null && _ref64 !== void 0 ? _ref64 : value.default) !== null && _ref63 !== void 0 ? _ref63 : value.en) !== null && _ref62 !== void 0 ? _ref62 : '');
2427
2455
  }
2428
2456
  function resolveServiceTypeLabelKey(serviceType) {
2429
2457
  return SERVICE_TYPE_LABEL_KEYS[serviceType] || null;
@@ -1,46 +1 @@
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; }
1
+ "use strict";
@@ -511,7 +511,16 @@ function resolveProductBasePrice(product) {
511
511
  const variantId = product.product_variant_id ?? product.variant_id;
512
512
  const variant = Array.isArray(origin.variant) && isPresentId(variantId) ? origin.variant.find(item => isSameId(item?.id, variantId)) : undefined;
513
513
  const isV2 = metadata.price_schema_version === 2 || metadata.price_schema_version === '2';
514
- return firstPresentValue(metadata.source_product_price, variant?.price, product._origin?.price, product._origin?.base_price, !isV2 ? metadata.main_product_original_price : undefined, product.base_price, product.price);
514
+ const quantity = toNumber(product.product_quantity ?? product.quantity ?? product.num ?? 1, 1);
515
+ const hasEntitlementPass = normalizeArray(product.discount_list).some(discount => getProductWalletDiscountType(discount) === 'entitlement_pass');
516
+ const hasOptions = normalizeArray(product.options).length > 0 || normalizeArray(product.product_sku?.option).length > 0;
517
+ const hasCombinations = normalizeArray(product.combinations).length > 0 || normalizeArray(product.product_bundle).length > 0 || normalizeArray(product.bundle).length > 0;
518
+ const aggregateSourcePrice = firstPresentValue(metadata.source_product_price, product.price);
519
+ const originalPrice = product.original_price;
520
+ // 部分旧 entitlement 商品把 source/price 持久化成了整行总价,但
521
+ // original_price 仍是单件价。仅在等式能明确证明该口径时做窄幅回退。
522
+ const useOriginalPriceAsLegacyUnitPrice = hasEntitlementPass && quantity > 1 && !hasOptions && !hasCombinations && isNumericAmount(aggregateSourcePrice) && isNumericAmount(originalPrice) && new _decimal.default(aggregateSourcePrice).eq(new _decimal.default(originalPrice).mul(quantity));
523
+ return firstPresentValue(useOriginalPriceAsLegacyUnitPrice ? originalPrice : undefined, metadata.source_product_price, variant?.price, product._origin?.price, product._origin?.base_price, !isV2 ? metadata.main_product_original_price : undefined, product.base_price, product.price);
515
524
  }
516
525
  function normalizeProductDiscounts(params) {
517
526
  const {
@@ -528,7 +537,8 @@ function normalizeProductDiscounts(params) {
528
537
  const amount = discount.amount ?? discount.value ?? discount.discount_amount;
529
538
  const isMarkup = isManualMarkup(discount);
530
539
  const isAggregatedBundleDiscount = Boolean(getReceiptDiscountBundleMapId(discount));
531
- const totalAmount = new _decimal.default(toMoneyNumber(amount)).mul(isAggregatedBundleDiscount ? 1 : quantity);
540
+ const isEntitlementPass = getProductWalletDiscountType(discount) === 'entitlement_pass';
541
+ const totalAmount = new _decimal.default(toMoneyNumber(amount)).mul(isAggregatedBundleDiscount || isEntitlementPass ? 1 : quantity);
532
542
  const formattedAmount = isMarkup ? formatMoney(totalAmount.abs(), currencySymbol) : formatNegativeMoney(totalAmount, currencySymbol);
533
543
  return {
534
544
  item: title,
@@ -1191,7 +1201,8 @@ function buildDelivery(order, locale) {
1191
1201
  return items;
1192
1202
  }
1193
1203
  function buildAppointment(order, locale) {
1194
- const bookings = sortBookings(normalizeArray(order.bookings));
1204
+ const parentScheduleId = order.metadata?.appointment_booking_parent_schedule_id;
1205
+ const bookings = sortBookings(normalizeArray(order.bookings).filter(booking => isReceiptAppointmentBooking(booking, parentScheduleId)));
1195
1206
  if (bookings.length) {
1196
1207
  const allResources = normalizeArray(order.resources || order.resource_list);
1197
1208
  return bookings.flatMap(booking => buildAppointmentRows({
@@ -1208,6 +1219,19 @@ function buildAppointment(order, locale) {
1208
1219
  value: getLocalizedValue(tableName, locale)
1209
1220
  }];
1210
1221
  }
1222
+ function isReceiptAppointmentBooking(booking, parentScheduleId) {
1223
+ if (!booking || typeof booking !== 'object' || Array.isArray(booking)) {
1224
+ return false;
1225
+ }
1226
+ if (isPresentId(parentScheduleId) && isSameId(booking.schedule_event_id, parentScheduleId)) {
1227
+ return false;
1228
+ }
1229
+ const parentId = booking.parent_id;
1230
+ if (parentId === undefined || parentId === null || parentId === '') {
1231
+ return true;
1232
+ }
1233
+ return Number(parentId) !== 0;
1234
+ }
1211
1235
  function buildAppointmentRows(params) {
1212
1236
  const {
1213
1237
  booking,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.3.120",
4
+ "version": "2.3.121",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",