@pisell/pisellos 0.0.338 → 0.0.339

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.
@@ -174,18 +174,6 @@ export var getProductTotalPrice = function getProductTotalPrice(params) {
174
174
  discounts = params.discounts;
175
175
  // const num = params.num || 1;
176
176
  var price = Number(product.price);
177
- if (bundle !== null && bundle !== void 0 && bundle.length) {
178
- price = bundle.reduce(function (accumulator, currentValue) {
179
- return accumulator + Number(currentValue.price) * Number(currentValue.num);
180
- }, price);
181
- }
182
-
183
- // 单规格
184
- if (options !== null && options !== void 0 && options.length) {
185
- price = options.reduce(function (accumulator, currentValue) {
186
- return accumulator + Number(currentValue.price) * Number(currentValue.num);
187
- }, price);
188
- }
189
177
 
190
178
  // 如果商品有折扣,则计算折扣
191
179
  if (discounts !== null && discounts !== void 0 && discounts.length) {
@@ -204,6 +192,18 @@ export var getProductTotalPrice = function getProductTotalPrice(params) {
204
192
  }
205
193
  });
206
194
  }
195
+ if (bundle !== null && bundle !== void 0 && bundle.length) {
196
+ price = bundle.reduce(function (accumulator, currentValue) {
197
+ return accumulator + Number(currentValue.price) * Number(currentValue.num);
198
+ }, price);
199
+ }
200
+
201
+ // 单规格
202
+ if (options !== null && options !== void 0 && options.length) {
203
+ price = options.reduce(function (accumulator, currentValue) {
204
+ return accumulator + Number(currentValue.price) * Number(currentValue.num);
205
+ }, price);
206
+ }
207
207
  return price;
208
208
  };
209
209
 
@@ -284,24 +284,39 @@ export var formatBundle = function formatBundle(bundle) {
284
284
  price: item === null || item === void 0 ? void 0 : item.price,
285
285
  total: item === null || item === void 0 ? void 0 : item.price,
286
286
  price_type: item === null || item === void 0 ? void 0 : item.price_type,
287
+ original_price: item === null || item === void 0 ? void 0 : item.original_price,
288
+ original_total: item === null || item === void 0 ? void 0 : item.original_total,
289
+ price_type_ext: item === null || item === void 0 ? void 0 : item.price_type_ext,
287
290
  bundle_sum_price: item === null || item === void 0 ? void 0 : item.bundle_sum_price,
288
291
  bundle_sum_type: item === null || item === void 0 ? void 0 : item.bundle_sum_type,
289
- options: formatOptions(item === null || item === void 0 ? void 0 : item.option)
292
+ options: formatOptions(item === null || item === void 0 ? void 0 : item.option),
293
+ _bundle_product_id: item._bundle_product_id,
294
+ discount_list: item.discount_list,
295
+ originBundleItem: item
290
296
  };
291
297
  });
292
298
  };
293
299
  export var formatBundleToOrigin = function formatBundleToOrigin(bundle) {
294
300
  if (!(bundle !== null && bundle !== void 0 && bundle.length)) return [];
295
301
  return bundle.map(function (d) {
302
+ var getBundleValueByKey = function getBundleValueByKey(key) {
303
+ var _d$originBundleItem;
304
+ return (d === null || d === void 0 ? void 0 : d[key]) || (d === null || d === void 0 || (_d$originBundleItem = d.originBundleItem) === null || _d$originBundleItem === void 0 ? void 0 : _d$originBundleItem[key]);
305
+ };
296
306
  return {
297
- bundle_group_id: d.group_id,
307
+ bundle_group_id: getBundleValueByKey('group_id'),
298
308
  bundle_id: d.id,
299
- bundle_product_id: (d === null || d === void 0 ? void 0 : d._bundle_product_id) || (d === null || d === void 0 ? void 0 : d.product_id),
300
- bundle_variant_id: d.bundle_variant_id,
309
+ bundle_product_id: getBundleValueByKey('_bundle_product_id') || getBundleValueByKey('product_id'),
310
+ bundle_variant_id: getBundleValueByKey('bundle_variant_id'),
301
311
  num: d.num,
302
- extension_id: d.extension_id,
303
- extension_type: d.extension_type,
304
- option: formatOptionsToOrigin(d.option)
312
+ extension_id: getBundleValueByKey('extension_id'),
313
+ extension_type: getBundleValueByKey('extension_type'),
314
+ option: formatOptionsToOrigin(getBundleValueByKey('option')),
315
+ discount_list: d.discount_list,
316
+ "bundle_selling_price": d === null || d === void 0 ? void 0 : d.price,
317
+ metadata: {
318
+ custom_product_bundle_map_id: d._id
319
+ }
305
320
  };
306
321
  });
307
322
  };
@@ -15,11 +15,19 @@ interface Formattitle {
15
15
  'zh-CN'?: any;
16
16
  'zh-HK'?: any;
17
17
  }
18
+ interface PackageSubItemUsageRules {
19
+ type: 'universal_discount' | 'package_exclusive' | 'single_item_promo' | 'custom_usage_rules';
20
+ custom_usage_rules: {
21
+ types: ("standalone_product" | "package_sub_item")[];
22
+ package_sub_item_rules: ("original_price" | "markup_price")[];
23
+ };
24
+ }
18
25
  interface Limitedrelationproductdata {
19
26
  id: number;
20
27
  type: 'product_all' | 'products' | 'product_collection';
21
28
  product_ids: number[];
22
29
  product_collection_id: number[];
30
+ package_sub_item_usage_rules?: PackageSubItemUsageRules;
23
31
  }
24
32
  interface ApplicableProductDetails {
25
33
  amount: string;
@@ -73,6 +81,7 @@ export interface Discount {
73
81
  metadata?: {
74
82
  discount_card_type?: 'fixed_amount' | 'percent';
75
83
  validity_type?: "custom_schedule_validity" | "fixed_validity";
84
+ custom_product_bundle_map_id?: string;
76
85
  };
77
86
  product: Product;
78
87
  type: "product" | 'good_pass';
@@ -102,6 +111,7 @@ export interface Discount {
102
111
  custom_schedule_snapshot?: {
103
112
  data: any[];
104
113
  };
114
+ num?: number;
105
115
  }
106
116
  export interface DiscountState {
107
117
  discountList: Discount[];
@@ -24,7 +24,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
24
24
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
25
25
  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); }
26
26
  import { BaseModule } from "../BaseModule";
27
- import { generateDuration, mergeRelationForms } from "./utils";
27
+ import { generateDuration, getAllDiscountList, mergeRelationForms } from "./utils";
28
28
  import { isNormalProduct } from "../Product/utils";
29
29
  import dayjs from 'dayjs';
30
30
  export var OrderModule = /*#__PURE__*/function (_BaseModule) {
@@ -142,6 +142,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
142
142
  item._origin.duration = duration;
143
143
  item._origin.sub_type = durationType;
144
144
  }
145
+ var discountList = getAllDiscountList(item);
146
+ item._origin.product.discount_list = discountList;
147
+
145
148
  // 购物车是否为普通商品
146
149
  if (isNormalProduct(item._origin)) {
147
150
  var _order$relation_forms;
@@ -20,3 +20,4 @@ export declare const mergeRelationForms: (relationForms: {
20
20
  form_id: number;
21
21
  form_record_ids: number[];
22
22
  }[];
23
+ export declare const getAllDiscountList: (cartItem: CartItem) => any;
@@ -51,4 +51,13 @@ export var mergeRelationForms = function mergeRelationForms(relationForms) {
51
51
  }, {})).filter(function (item) {
52
52
  return item.form_record_ids.length > 0;
53
53
  }); // 过滤掉没有有效记录的表单
54
+ };
55
+ export var getAllDiscountList = function getAllDiscountList(cartItem) {
56
+ var _cartItem$_origin, _cartItem$_origin2;
57
+ var discountList = (cartItem === null || cartItem === void 0 || (_cartItem$_origin = cartItem._origin) === null || _cartItem$_origin === void 0 || (_cartItem$_origin = _cartItem$_origin.product) === null || _cartItem$_origin === void 0 ? void 0 : _cartItem$_origin.discount_list) || [];
58
+ ((cartItem === null || cartItem === void 0 || (_cartItem$_origin2 = cartItem._origin) === null || _cartItem$_origin2 === void 0 || (_cartItem$_origin2 = _cartItem$_origin2.product) === null || _cartItem$_origin2 === void 0 ? void 0 : _cartItem$_origin2.product_bundle) || []).forEach(function (item) {
59
+ discountList = [].concat(_toConsumableArray(discountList), _toConsumableArray(item.discount_list));
60
+ item.discount_list = undefined;
61
+ });
62
+ return discountList;
54
63
  };
@@ -30,6 +30,13 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
30
30
  selectedList?: SetDiscountSelectedParams[];
31
31
  scan?: boolean;
32
32
  }): DiscountResult;
33
+ /**
34
+ * 检查优惠是否符合 PackageSubItemUsageRules 配置
35
+ * @param discount 优惠券
36
+ * @param flatItem 扁平化后的商品项(可能是主商品或bundle子商品)
37
+ * @returns 是否可用
38
+ */
39
+ private checkPackageSubItemUsageRules;
33
40
  destroy(): Promise<void>;
34
41
  clear(): Promise<void>;
35
42
  }