@pisell/pisellos 3.0.75 → 3.0.77

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.
@@ -2,6 +2,11 @@ import Decimal from 'decimal.js';
2
2
  import { CartItem } from '../Cart/types';
3
3
  import { ISummaryState } from './types';
4
4
  export declare const calculatePriceDetails: (shopInfo: any, items: CartItem[]) => ISummaryState['summary'];
5
+ /**
6
+ * 获取子商品折扣信息
7
+ * @param item
8
+ */
9
+ export declare const getBundleDiscountList: (bundle: any[]) => any[];
5
10
  /**
6
11
  * 计算商品小计(不含其他费用)
7
12
  * @param items - 购物车商品数组
@@ -1,3 +1,9 @@
1
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
5
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
1
7
  import Decimal from 'decimal.js';
2
8
  export var calculatePriceDetails = function calculatePriceDetails(shopInfo, items) {
3
9
  var subtotal = new Decimal(calculateSubtotal(items));
@@ -18,6 +24,34 @@ export var calculatePriceDetails = function calculatePriceDetails(shopInfo, item
18
24
  };
19
25
  };
20
26
 
27
+ /**
28
+ * 获取子商品折扣信息
29
+ * @param item
30
+ */
31
+ export var getBundleDiscountList = function getBundleDiscountList(bundle) {
32
+ if (!bundle) {
33
+ return [];
34
+ }
35
+ var discountList = [];
36
+ bundle.forEach(function (d) {
37
+ if (d.discount_list && Array.isArray(d.discount_list)) {
38
+ discountList.push.apply(discountList, _toConsumableArray(d.discount_list.filter(function (item) {
39
+ return !item.id;
40
+ })));
41
+ }
42
+ });
43
+ return discountList;
44
+ };
45
+ var getProductDiscountProductDiscountDifference = function getProductDiscountProductDiscountDifference(item) {
46
+ var _item$_origin, _item$_origin2;
47
+ var mainDiscountList = ((_item$_origin = item._origin) === null || _item$_origin === void 0 || (_item$_origin = _item$_origin.product) === null || _item$_origin === void 0 ? void 0 : _item$_origin.discount_list) || [];
48
+ var bundleDiscountList = getBundleDiscountList(((_item$_origin2 = item._origin) === null || _item$_origin2 === void 0 || (_item$_origin2 = _item$_origin2.product) === null || _item$_origin2 === void 0 ? void 0 : _item$_origin2.product_bundle) || []);
49
+ var discountList = [].concat(_toConsumableArray(mainDiscountList), _toConsumableArray(bundleDiscountList));
50
+ return discountList.reduce(function (pre, cur) {
51
+ return pre + (cur.metadata.product_discount_difference || 0);
52
+ }, 0);
53
+ };
54
+
21
55
  /**
22
56
  * 计算商品小计(不含其他费用)
23
57
  * @param items - 购物车商品数组
@@ -29,7 +63,8 @@ export var calculateSubtotal = function calculateSubtotal(items) {
29
63
  }
30
64
  var subtotal = items.reduce(function (sum, item) {
31
65
  var cartItemTotalPrice = new Decimal(item.summaryTotal || 0);
32
- return sum.plus(cartItemTotalPrice);
66
+ var productDiscountProductDiscountDifference = getProductDiscountProductDiscountDifference(item);
67
+ return sum.plus(cartItemTotalPrice).sub(productDiscountProductDiscountDifference);
33
68
  }, new Decimal(0));
34
69
  return subtotal.toFixed(2);
35
70
  };
@@ -551,19 +551,20 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
551
551
  return n.id === (((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) || discount.id);
552
552
  });
553
553
  if (index !== -1) {
554
+ var _discount$metadata;
554
555
  editModeDiscountList[index] = _objectSpread(_objectSpread({}, editModeDiscountList[index]), {}, {
555
556
  amount: new Decimal(discount.amount || 0).plus(new Decimal(editModeDiscountList[index].amount || 0)).toNumber(),
556
- savedAmount: new Decimal(discount.amount || 0).times((product === null || product === void 0 ? void 0 : product.quantity) || (product === null || product === void 0 ? void 0 : product.num) || 1).plus(new Decimal(editModeDiscountList[index].savedAmount || 0)).toNumber()
557
+ savedAmount: new Decimal(discount.amount || 0).times((product === null || product === void 0 ? void 0 : product.quantity) || (product === null || product === void 0 ? void 0 : product.num) || 1).plus((discount === null || discount === void 0 || (_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata.product_discount_difference) || 0).plus(new Decimal(editModeDiscountList[index].savedAmount || 0)).toNumber()
557
558
  });
558
559
  } else {
559
- var _discount$discount2, _discount$discount3, _discount$discount4;
560
+ var _discount$metadata2, _discount$discount2, _discount$discount3, _discount$discount4;
560
561
  if (discount.type && !discount.tag) {
561
562
  discount.tag = discount.type;
562
563
  }
563
564
  editModeDiscountList.push(_objectSpread(_objectSpread({}, discount), {}, {
564
565
  isEditMode: true,
565
566
  limited_relation_product_data: {},
566
- savedAmount: discount.amount * ((product === null || product === void 0 ? void 0 : product.quantity) || (product === null || product === void 0 ? void 0 : product.num) || 1),
567
+ savedAmount: new Decimal(discount.amount || 0).times((product === null || product === void 0 ? void 0 : product.quantity) || (product === null || product === void 0 ? void 0 : product.num) || 1).plus((discount === null || discount === void 0 || (_discount$metadata2 = discount.metadata) === null || _discount$metadata2 === void 0 ? void 0 : _discount$metadata2.product_discount_difference) || 0).toNumber(),
567
568
  isAvailable: true,
568
569
  id: ((_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.resource_id) || discount.id,
569
570
  format_title: ((_discount$discount3 = discount.discount) === null || _discount$discount3 === void 0 ? void 0 : _discount$discount3.title) || discount.format_title,
@@ -65,3 +65,27 @@ export declare const getDateIsInSchedule: (dateTime: string, scheduleList: Sched
65
65
  * @returns 过滤后的优惠券列表
66
66
  */
67
67
  export declare const filterDiscountListByBookingTime: (discountList: Discount[], bookingTime: string | null) => Discount[];
68
+ /**
69
+ * 判断是否是订单级别的固定金额折扣卡
70
+ * @param discount 折扣
71
+ * @returns 是否是订单级别的固定金额折扣卡
72
+ */
73
+ export declare const isOrderLevelFixedAmountDiscount: (discount: Discount) => boolean;
74
+ /**
75
+ * 计算订单级别固定金额折扣卡的分摊结果
76
+ * @param discount 折扣卡
77
+ * @param applicableProducts 适用商品列表 { productId, amount, quantity, parentQuantity }
78
+ * @returns 分摊结果 Map<productId, { discountAmount, difference }>
79
+ * 注意:
80
+ * - discountAmount 是单价折扣金额(不是总折扣金额)
81
+ * - difference(总差值)优先直接加到数量为1的单商品折扣上,如果没有则存储在metadata中
82
+ */
83
+ export declare const calculateOrderLevelDiscountAllocation: (discount: Discount, applicableProducts: Array<{
84
+ productId: string | number;
85
+ amount: number;
86
+ quantity: number;
87
+ parentQuantity?: number;
88
+ }>) => Map<string | number, {
89
+ discountAmount: number;
90
+ difference: number;
91
+ }>;
@@ -1,3 +1,9 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
1
7
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
2
8
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
3
9
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
@@ -45,7 +51,8 @@ export var getDiscountAmount = function getDiscountAmount(discount, total, price
45
51
 
46
52
  // 固定金额 小于0时返回0
47
53
  if (isFixedAmount) {
48
- return Math.max(new Decimal(price).minus(new Decimal(discount.par_value || 0)).toNumber(), 0);
54
+ var _discount$amount;
55
+ return Math.max(new Decimal(price).minus(new Decimal(((_discount$amount = discount.amount) !== null && _discount$amount !== void 0 ? _discount$amount : discount.par_value) || 0)).toNumber(), 0);
49
56
  }
50
57
 
51
58
  // 百分比:根据折扣卡金额计算
@@ -462,4 +469,132 @@ export var filterDiscountListByBookingTime = function filterDiscountListByBookin
462
469
  return true;
463
470
  }
464
471
  });
472
+ };
473
+
474
+ /**
475
+ * 判断是否是订单级别的固定金额折扣卡
476
+ * @param discount 折扣
477
+ * @returns 是否是订单级别的固定金额折扣卡
478
+ */
479
+ export var isOrderLevelFixedAmountDiscount = function isOrderLevelFixedAmountDiscount(discount) {
480
+ var _discount$metadata3, _discount$metadata4;
481
+ return discount.tag === 'product_discount_card' && (discount === null || discount === void 0 || (_discount$metadata3 = discount.metadata) === null || _discount$metadata3 === void 0 ? void 0 : _discount$metadata3.discount_card_type) === 'fixed_amount' && (discount === null || discount === void 0 || (_discount$metadata4 = discount.metadata) === null || _discount$metadata4 === void 0 ? void 0 : _discount$metadata4.discount_calculation_mode) === 'order_level';
482
+ };
483
+
484
+ /**
485
+ * 计算订单级别固定金额折扣卡的分摊结果
486
+ * @param discount 折扣卡
487
+ * @param applicableProducts 适用商品列表 { productId, amount, quantity, parentQuantity }
488
+ * @returns 分摊结果 Map<productId, { discountAmount, difference }>
489
+ * 注意:
490
+ * - discountAmount 是单价折扣金额(不是总折扣金额)
491
+ * - difference(总差值)优先直接加到数量为1的单商品折扣上,如果没有则存储在metadata中
492
+ */
493
+ export var calculateOrderLevelDiscountAllocation = function calculateOrderLevelDiscountAllocation(discount, applicableProducts) {
494
+ var result = new Map();
495
+ if (applicableProducts.length === 0) {
496
+ return result;
497
+ }
498
+
499
+ // 计算适用商品的总金额(数量 × 单价)
500
+ var totalAmount = applicableProducts.reduce(function (acc, product) {
501
+ return new Decimal(acc).plus(new Decimal(product.amount).mul(product.quantity)).toNumber();
502
+ }, 0);
503
+ if (totalAmount <= 0) {
504
+ return result;
505
+ }
506
+
507
+ // 固定减免金额
508
+ var fixedAmount = new Decimal(discount.par_value || 0).toNumber();
509
+
510
+ // 如果固定金额 >= 商品总金额,折扣最高为商品金额(免费)
511
+ var actualDiscountTotal = Math.min(fixedAmount, totalAmount);
512
+
513
+ // 计算每个商品的单价折扣金额
514
+ var allocatedTotal = new Decimal(0);
515
+ applicableProducts.forEach(function (product) {
516
+ // 🔥 分摊公式改为:(单价 / 适用商品总金额) × 固定金额
517
+ // 这样只有一次取整,避免精度损失
518
+ var rawDiscountPerItem = new Decimal(product.amount).div(totalAmount).mul(actualDiscountTotal);
519
+
520
+ // 保留两位小数,向下取整(单价折扣)
521
+ var discountAmountPerItem = rawDiscountPerItem.toDecimalPlaces(2, Decimal.ROUND_DOWN).toNumber();
522
+ result.set(product.productId, {
523
+ discountAmount: discountAmountPerItem,
524
+ // 单价折扣金额
525
+ difference: 0 // 默认差值为0
526
+ });
527
+
528
+ // 累加实际分配的总折扣金额(单价折扣 × 数量)
529
+ allocatedTotal = allocatedTotal.plus(new Decimal(discountAmountPerItem).mul(product.quantity));
530
+ });
531
+
532
+ // 🔥 计算总差值
533
+ // 总差值 = 固定金额 - 所有商品的 (单价折扣 × 数量) 之和
534
+ var totalDifference = new Decimal(actualDiscountTotal).minus(allocatedTotal).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
535
+ if (totalDifference > 0) {
536
+ // 🔥 判断商品是否是真正的"数量为1"
537
+ // 主商品:quantity === 1
538
+ // 子商品:quantity === 1 且 parentQuantity === 1
539
+ var isSingleQuantity = function isSingleQuantity(product) {
540
+ if (product.parentQuantity !== undefined) {
541
+ // 子商品:需要同时满足自身数量为1且主商品数量为1
542
+ return product.quantity === 1 && product.parentQuantity === 1;
543
+ }
544
+ // 主商品:只需要自身数量为1
545
+ return product.quantity === 1;
546
+ };
547
+
548
+ // 🔥 筛选出数量为1的商品
549
+ var singleQuantityProducts = applicableProducts.filter(isSingleQuantity);
550
+ if (singleQuantityProducts.length > 0) {
551
+ // 🔥 优先级1:找到有足够剩余空间且金额最大的商品
552
+ // 剩余空间 = 商品价格 - 当前折扣金额 >= 差值
553
+ var productsWithEnoughSpace = singleQuantityProducts.filter(function (product) {
554
+ var allocation = result.get(product.productId);
555
+ if (!allocation) return false;
556
+ var remainingSpace = new Decimal(product.amount).minus(allocation.discountAmount).toNumber();
557
+ return remainingSpace >= totalDifference;
558
+ });
559
+ if (productsWithEnoughSpace.length > 0) {
560
+ // 按金额降序排序,选择金额最大的
561
+ productsWithEnoughSpace.sort(function (a, b) {
562
+ return b.amount - a.amount;
563
+ });
564
+ var targetProduct = productsWithEnoughSpace[0];
565
+ var targetAllocation = result.get(targetProduct.productId);
566
+ if (targetAllocation) {
567
+ // 差值直接加到折扣金额上
568
+ result.set(targetProduct.productId, {
569
+ discountAmount: new Decimal(targetAllocation.discountAmount).plus(totalDifference).toNumber(),
570
+ difference: 0 // 不需要存储差值
571
+ });
572
+ }
573
+ } else {
574
+ // 🔥 优先级2:所有数量为1的商品都没有足够剩余空间
575
+ // 选择金额最大的商品,差值存储在metadata中
576
+ singleQuantityProducts.sort(function (a, b) {
577
+ return b.amount - a.amount;
578
+ });
579
+ var _targetProduct = singleQuantityProducts[0];
580
+ var _targetAllocation = result.get(_targetProduct.productId);
581
+ if (_targetAllocation) {
582
+ result.set(_targetProduct.productId, _objectSpread(_objectSpread({}, _targetAllocation), {}, {
583
+ difference: totalDifference
584
+ }));
585
+ }
586
+ }
587
+ } else {
588
+ // 🔥 优先级3:没有数量为1的商品,走原有逻辑
589
+ // 差值存储在最后一个商品的metadata中
590
+ var lastProduct = applicableProducts[applicableProducts.length - 1];
591
+ var lastProductAllocation = result.get(lastProduct.productId);
592
+ if (lastProductAllocation) {
593
+ result.set(lastProduct.productId, _objectSpread(_objectSpread({}, lastProductAllocation), {}, {
594
+ difference: totalDifference
595
+ }));
596
+ }
597
+ }
598
+ }
599
+ return result;
465
600
  };
@@ -139,7 +139,7 @@ var formatProductToCartItem = (params) => {
139
139
  return cartItem;
140
140
  };
141
141
  var formatProductToCartItemOrigin = (params) => {
142
- var _a, _b, _c, _d;
142
+ var _a, _b, _c, _d, _e;
143
143
  const {
144
144
  cartItem,
145
145
  product,
@@ -149,17 +149,27 @@ var formatProductToCartItemOrigin = (params) => {
149
149
  quantity = 1
150
150
  } = params;
151
151
  let origin = cartItem._origin;
152
+ const product_discount_difference = (((_a = origin.product) == null ? void 0 : _a.discount_list) || []).filter((item) => {
153
+ var _a2;
154
+ return !((_a2 = item == null ? void 0 : item.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id);
155
+ }).reduce((pre, cur) => {
156
+ var _a2;
157
+ return pre + (((_a2 = cur == null ? void 0 : cur.metadata) == null ? void 0 : _a2.product_discount_difference) || 0);
158
+ }, 0);
152
159
  if (product) {
153
160
  origin.product = {
154
161
  ...origin.product || {},
155
162
  num: quantity,
156
163
  product_id: product.id,
157
164
  product_variant_id: product_variant_id || 0,
158
- product_bundle: ((_a = origin.product) == null ? void 0 : _a.product_bundle) || [],
159
- product_option_item: ((_b = origin.product) == null ? void 0 : _b.product_option_item) || []
165
+ product_bundle: ((_b = origin.product) == null ? void 0 : _b.product_bundle) || [],
166
+ product_option_item: ((_c = origin.product) == null ? void 0 : _c.product_option_item) || [],
167
+ metadata: {
168
+ product_discount_difference
169
+ }
160
170
  };
161
- origin.sub_type = (_c = product == null ? void 0 : product.duration) == null ? void 0 : _c.type;
162
- origin.duration = (_d = product == null ? void 0 : product.duration) == null ? void 0 : _d.value;
171
+ origin.sub_type = (_d = product == null ? void 0 : product.duration) == null ? void 0 : _d.type;
172
+ origin.duration = (_e = product == null ? void 0 : product.duration) == null ? void 0 : _e.value;
163
173
  if (bundle == null ? void 0 : bundle.length) {
164
174
  origin.product.product_bundle = formatBundleToOrigin(bundle);
165
175
  }
@@ -176,6 +186,7 @@ var getProductTotalPrice = (params) => {
176
186
  discounts.forEach((currentValue) => {
177
187
  var _a;
178
188
  price = (0, import_utils2.getDiscountAmount)({
189
+ amount: currentValue.amount,
179
190
  tag: currentValue.type,
180
191
  par_value: currentValue.discount.percent,
181
192
  metadata: {
@@ -272,6 +283,10 @@ var formatBundleToOrigin = (bundle) => {
272
283
  var _a;
273
284
  return (d == null ? void 0 : d[key]) || ((_a = d == null ? void 0 : d.originBundleItem) == null ? void 0 : _a[key]);
274
285
  };
286
+ const product_discount_difference = ((d == null ? void 0 : d.discount_list) || []).reduce((pre, cur) => {
287
+ var _a;
288
+ return pre + (((_a = cur == null ? void 0 : cur.metadata) == null ? void 0 : _a.product_discount_difference) || 0);
289
+ }, 0);
275
290
  return {
276
291
  bundle_group_id: getBundleValueByKey("group_id"),
277
292
  bundle_id: d.id,
@@ -284,7 +299,8 @@ var formatBundleToOrigin = (bundle) => {
284
299
  discount_list: d.discount_list,
285
300
  "bundle_selling_price": d == null ? void 0 : d.price,
286
301
  metadata: {
287
- custom_product_bundle_map_id: d._id
302
+ custom_product_bundle_map_id: d._id,
303
+ product_discount_difference
288
304
  }
289
305
  };
290
306
  });
@@ -176,9 +176,9 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
176
176
  }
177
177
  if (discount.appliedProductDetails) {
178
178
  return discount.appliedProductDetails.reduce((total, product) => {
179
- var _a;
179
+ var _a, _b;
180
180
  const price = new import_decimal.default(((_a = product == null ? void 0 : product.discount) == null ? void 0 : _a.fixed_amount) || 0).mul((product == null ? void 0 : product._num) || 1);
181
- return new import_decimal.default(total).plus(price).toNumber();
181
+ return new import_decimal.default(total).plus(price).add(((_b = product == null ? void 0 : product.metadata) == null ? void 0 : _b.product_discount_difference) || 0).toNumber();
182
182
  }, 0);
183
183
  }
184
184
  }
@@ -33,6 +33,9 @@ interface ApplicableProductDetails {
33
33
  title: string;
34
34
  original_amount: string;
35
35
  num: number;
36
+ metadata?: {
37
+ product_discount_difference?: number;
38
+ };
36
39
  discount?: {
37
40
  fixed_amount?: number;
38
41
  product_id?: number;
@@ -81,6 +84,10 @@ export interface Discount {
81
84
  discount_card_type?: 'fixed_amount' | 'percent';
82
85
  custom_product_bundle_map_id?: string;
83
86
  validity_type?: "custom_schedule_validity" | "fixed_validity";
87
+ discount_calculation_mode: 'item_level' | 'order_level';
88
+ holder: {
89
+ type: "customer" | "custom";
90
+ };
84
91
  };
85
92
  product: Product;
86
93
  type: "product" | 'good_pass';
@@ -89,7 +96,9 @@ export interface Discount {
89
96
  isEditMode?: boolean;
90
97
  isScan?: boolean;
91
98
  discount?: {
99
+ discount_product_id: number;
92
100
  resource_id: number;
101
+ discount_calculation_mode: 'item_level' | 'order_level';
93
102
  };
94
103
  isManualSelect?: boolean;
95
104
  isDisabled?: boolean;