@pisell/pisellos 3.0.50 → 3.0.52

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.
@@ -28,6 +28,7 @@ export declare class CartModule extends BaseModule implements Module, CartModule
28
28
  * 更新购物车信息
29
29
  */
30
30
  updateItem(params: IUpdateItemParams): Promise<void>;
31
+ updateItemInitInfo(params: IUpdateItemParams): Promise<void>;
31
32
  /**
32
33
  * 格式化数据到购物车
33
34
  */
@@ -211,11 +211,39 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
211
211
  return _updateItem.apply(this, arguments);
212
212
  }
213
213
  return updateItem;
214
+ }() // 更新购物车中商品的初始信息
215
+ // 为什么会有这个操作,主要服务于报价单和商品券
216
+ // 商品券那边会使用 init 的 price 做计算,而报价单那边就需要修改 init 的 price 来辅助商品计算
217
+ )
218
+ }, {
219
+ key: "updateItemInitInfo",
220
+ value: function () {
221
+ var _updateItemInitInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(params) {
222
+ var _id, product, cartItem;
223
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
224
+ while (1) switch (_context4.prev = _context4.next) {
225
+ case 0:
226
+ _id = params._id, product = params.product;
227
+ cartItem = this.store.list.find(function (i) {
228
+ return i._id === _id;
229
+ });
230
+ if (cartItem) {
231
+ cartItem._productInit = cloneDeep(product);
232
+ }
233
+ case 3:
234
+ case "end":
235
+ return _context4.stop();
236
+ }
237
+ }, _callee4, this);
238
+ }));
239
+ function updateItemInitInfo(_x5) {
240
+ return _updateItemInitInfo.apply(this, arguments);
241
+ }
242
+ return updateItemInitInfo;
214
243
  }()
215
244
  /**
216
245
  * 格式化数据到购物车
217
246
  */
218
- )
219
247
  }, {
220
248
  key: "formatCartItem",
221
249
  value: function formatCartItem(params) {
@@ -305,18 +333,18 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
305
333
  }, {
306
334
  key: "batchSetItems",
307
335
  value: (function () {
308
- var _batchSetItems = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(items) {
309
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
310
- while (1) switch (_context4.prev = _context4.next) {
336
+ var _batchSetItems = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(items) {
337
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
338
+ while (1) switch (_context5.prev = _context5.next) {
311
339
  case 0:
312
340
  this.store.list = _toConsumableArray(items || []);
313
341
  case 1:
314
342
  case "end":
315
- return _context4.stop();
343
+ return _context5.stop();
316
344
  }
317
- }, _callee4, this);
345
+ }, _callee5, this);
318
346
  }));
319
- function batchSetItems(_x5) {
347
+ function batchSetItems(_x6) {
320
348
  return _batchSetItems.apply(this, arguments);
321
349
  }
322
350
  return batchSetItems;
@@ -359,24 +387,24 @@ export var CartModule = /*#__PURE__*/function (_BaseModule) {
359
387
  }, {
360
388
  key: "removeItem",
361
389
  value: (function () {
362
- var _removeItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(id) {
390
+ var _removeItem = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(id) {
363
391
  var items;
364
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
365
- while (1) switch (_context5.prev = _context5.next) {
392
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
393
+ while (1) switch (_context6.prev = _context6.next) {
366
394
  case 0:
367
395
  items = this.store.list.filter(function (i) {
368
396
  return i._id !== id;
369
397
  });
370
398
  this.store.list = items;
371
- _context5.next = 4;
399
+ _context6.next = 4;
372
400
  return this.core.effects.emit("".concat(this.name, ":onRemoveItem"), items);
373
401
  case 4:
374
402
  case "end":
375
- return _context5.stop();
403
+ return _context6.stop();
376
404
  }
377
- }, _callee5, this);
405
+ }, _callee6, this);
378
406
  }));
379
- function removeItem(_x6) {
407
+ function removeItem(_x7) {
380
408
  return _removeItem.apply(this, arguments);
381
409
  }
382
410
  return removeItem;
@@ -22,8 +22,9 @@ import { isNormalProduct } from "../../Product/utils";
22
22
  export var handleVariantProduct = function handleVariantProduct(product) {
23
23
  // 判断组合商品,然后直接修改 product 里的价格和 is_charge_tax
24
24
  if (product !== null && product !== void 0 && product.product_variant_id) {
25
+ var _product$variant;
25
26
  // 还需要判断 能从 variant 里找到对应的组合规格信息,才可以替换
26
- var targetVariant = product.variant.find(function (n) {
27
+ var targetVariant = product === null || product === void 0 || (_product$variant = product.variant) === null || _product$variant === void 0 ? void 0 : _product$variant.find(function (n) {
27
28
  return n.id === product.product_variant_id;
28
29
  });
29
30
  if (targetVariant) {
@@ -45,6 +46,7 @@ export var handleVariantProduct = function handleVariantProduct(product) {
45
46
  */
46
47
  export var formatProductToCartItem = function formatProductToCartItem(params) {
47
48
  var _product$custom_depos;
49
+ console.log('formatProductToCartItem>>>>>>', params);
48
50
  var cartItem = params.cartItem,
49
51
  product = params.product,
50
52
  bundle = params.bundle,
@@ -88,17 +90,17 @@ export var formatProductToCartItem = function formatProductToCartItem(params) {
88
90
  }
89
91
  // 拼装出 product_option_string
90
92
  if (product_variant_id) {
91
- var _product$variant$find;
92
- var sku_key = (_product$variant$find = product.variant.find(function (n) {
93
+ var _product$variant2;
94
+ var sku_key = product === null || product === void 0 || (_product$variant2 = product.variant) === null || _product$variant2 === void 0 || (_product$variant2 = _product$variant2.find(function (n) {
93
95
  return n.id === product_variant_id;
94
- })) === null || _product$variant$find === void 0 ? void 0 : _product$variant$find.sku_key;
96
+ })) === null || _product$variant2 === void 0 ? void 0 : _product$variant2.sku_key;
95
97
  if (sku_key) {
96
98
  var sku_key_arr = sku_key.split('_');
97
99
  var product_option_string = [];
98
100
  sku_key_arr.forEach(function (item) {
99
- var _targetVariantGroup$v;
101
+ var _product$variant_grou, _targetVariantGroup$v;
100
102
  var keyMap = item.split(':');
101
- var targetVariantGroup = product.variant_group.find(function (n) {
103
+ var targetVariantGroup = product === null || product === void 0 || (_product$variant_grou = product.variant_group) === null || _product$variant_grou === void 0 ? void 0 : _product$variant_grou.find(function (n) {
102
104
  return String(n.position_id) === keyMap[0];
103
105
  });
104
106
  var targetVariantItem = targetVariantGroup === null || targetVariantGroup === void 0 || (_targetVariantGroup$v = targetVariantGroup.variant_item) === null || _targetVariantGroup$v === void 0 ? void 0 : _targetVariantGroup$v.find(function (n) {
@@ -344,16 +346,38 @@ export var getProductDeposit = function getProductDeposit(params) {
344
346
  productHasDeposit = true;
345
347
  }
346
348
  } else {
349
+ // 组合规格商品
350
+ if (product !== null && product !== void 0 && product.product_variant_id) {
351
+ var _product$variant3;
352
+ var variantProduct = product === null || product === void 0 || (_product$variant3 = product.variant) === null || _product$variant3 === void 0 ? void 0 : _product$variant3.find(function (item) {
353
+ return (item === null || item === void 0 ? void 0 : item.id) === (product === null || product === void 0 ? void 0 : product.product_variant_id);
354
+ });
355
+ if (variantProduct) {
356
+ var depositData = variantProduct === null || variantProduct === void 0 ? void 0 : variantProduct.custom_deposit_data;
357
+ var _handleProductDeposit2 = handleProductDeposit({
358
+ depositData: depositData,
359
+ total: (cartItem === null || cartItem === void 0 ? void 0 : cartItem.total) || 0,
360
+ num: num
361
+ }),
362
+ _depositTotal = _handleProductDeposit2.depositTotal,
363
+ _result = _handleProductDeposit2.result;
364
+ if (_result) {
365
+ total = _depositTotal;
366
+ protocolIds.push.apply(protocolIds, _toConsumableArray((depositData === null || depositData === void 0 ? void 0 : depositData.self_deposit_policy_ids) || []));
367
+ productHasDeposit = true;
368
+ }
369
+ }
370
+ }
347
371
  if (bundle !== null && bundle !== void 0 && bundle.length) {
348
372
  total = bundle.reduce(function (accumulator, currBundleProduct) {
349
373
  var depositData = currBundleProduct === null || currBundleProduct === void 0 ? void 0 : currBundleProduct.custom_deposit_data;
350
- var _handleProductDeposit2 = handleProductDeposit({
374
+ var _handleProductDeposit3 = handleProductDeposit({
351
375
  depositData: depositData,
352
376
  total: currBundleProduct === null || currBundleProduct === void 0 ? void 0 : currBundleProduct.price,
353
377
  num: (currBundleProduct === null || currBundleProduct === void 0 ? void 0 : currBundleProduct.num) || 1
354
378
  }),
355
- depositTotal = _handleProductDeposit2.depositTotal,
356
- result = _handleProductDeposit2.result;
379
+ depositTotal = _handleProductDeposit3.depositTotal,
380
+ result = _handleProductDeposit3.result;
357
381
  if (result) {
358
382
  protocolIds.push.apply(protocolIds, _toConsumableArray((depositData === null || depositData === void 0 ? void 0 : depositData.self_deposit_policy_ids) || []));
359
383
  productHasDeposit = true;
@@ -1,3 +1,3 @@
1
1
  import { Product } from "../../Product";
2
2
  import { CartItem, IUpdateItemParams } from "../types";
3
- export declare function updateAllCartItemPrice(cartItems: CartItem[], priceData: any, getProduct: (id: number) => Promise<Product | undefined>, updateCart: (item: IUpdateItemParams) => void): Promise<void>;
3
+ export declare function updateAllCartItemPrice(cartItems: CartItem[], priceData: any, getProduct: (id: number) => Promise<Product | undefined>, updateCart: (item: IUpdateItemParams) => void, updateItemInitInfo: (item: IUpdateItemParams) => void): Promise<void>;
@@ -11,11 +11,11 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
11
11
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
12
12
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
13
13
  import Decimal from "decimal.js";
14
- export function updateAllCartItemPrice(_x, _x2, _x3, _x4) {
14
+ export function updateAllCartItemPrice(_x, _x2, _x3, _x4, _x5) {
15
15
  return _updateAllCartItemPrice.apply(this, arguments);
16
16
  }
17
17
  function _updateAllCartItemPrice() {
18
- _updateAllCartItemPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(cartItems, priceData, getProduct, updateCart) {
18
+ _updateAllCartItemPrice = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(cartItems, priceData, getProduct, updateCart, updateItemInitInfo) {
19
19
  var _iterator, _step, _loop;
20
20
  return _regeneratorRuntime().wrap(function _callee$(_context2) {
21
21
  while (1) switch (_context2.prev = _context2.next) {
@@ -37,6 +37,9 @@ function _updateAllCartItemPrice() {
37
37
  case 4:
38
38
  cartProduct = _context.sent;
39
39
  productInfo = cartProduct === null || cartProduct === void 0 ? void 0 : cartProduct.getData();
40
+ if (!productInfo) {
41
+ productInfo = item._productOrigin;
42
+ }
40
43
  bundle = item._bundleOrigin;
41
44
  productInfo.price = targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.price;
42
45
  productInfo.base_price = targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.base_price;
@@ -79,13 +82,18 @@ function _updateAllCartItemPrice() {
79
82
  return n;
80
83
  });
81
84
  }
85
+ // 先把商品原始信息更新了
86
+ updateItemInitInfo({
87
+ _id: item._id,
88
+ product: productInfo
89
+ });
82
90
  updateCart({
83
91
  _id: item._id,
84
92
  product: productInfo,
85
93
  bundle: bundle,
86
94
  options: item._optionsOrigin
87
95
  });
88
- case 13:
96
+ case 15:
89
97
  case "end":
90
98
  return _context.stop();
91
99
  }
@@ -165,8 +165,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
165
165
  var _this3 = this;
166
166
  var discountList = _ref2.discountList,
167
167
  productList = _ref2.productList;
168
- // debugger
169
-
170
168
  // 识别出来是不是在编辑的界面里又新增了商品
171
169
  // 这种情况下,如果有可用的优惠券,也会自动勾选上
172
170
  var isEditModeAddNewProduct = productList.find(function (n) {
@@ -378,6 +378,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
378
378
  return _this3.store.products.getProduct(id);
379
379
  }, function (params) {
380
380
  return _this3.store.cart.updateItem(params);
381
+ }, function (params) {
382
+ return _this3.store.cart.updateItemInitInfo(params);
381
383
  });
382
384
  case 10:
383
385
  this.core.effects.emit("".concat(this.store.cart.name, ":onUpdateQuotationPrice"), {});
@@ -28,6 +28,7 @@ export declare class CartModule extends BaseModule implements Module, CartModule
28
28
  * 更新购物车信息
29
29
  */
30
30
  updateItem(params: IUpdateItemParams): Promise<void>;
31
+ updateItemInitInfo(params: IUpdateItemParams): Promise<void>;
31
32
  /**
32
33
  * 格式化数据到购物车
33
34
  */
@@ -119,6 +119,16 @@ var CartModule = class extends import_BaseModule.BaseModule {
119
119
  console.error("[CartModule] 更新购物车商品失败", error);
120
120
  }
121
121
  }
122
+ // 更新购物车中商品的初始信息
123
+ // 为什么会有这个操作,主要服务于报价单和商品券
124
+ // 商品券那边会使用 init 的 price 做计算,而报价单那边就需要修改 init 的 price 来辅助商品计算
125
+ async updateItemInitInfo(params) {
126
+ const { _id, product } = params;
127
+ const cartItem = this.store.list.find((i) => i._id === _id);
128
+ if (cartItem) {
129
+ cartItem._productInit = (0, import_lodash_es.cloneDeep)(product);
130
+ }
131
+ }
122
132
  /**
123
133
  * 格式化数据到购物车
124
134
  */
@@ -45,8 +45,9 @@ module.exports = __toCommonJS(cartProduct_exports);
45
45
  var import_decimal = __toESM(require("decimal.js"));
46
46
  var import_utils = require("../../Product/utils");
47
47
  var handleVariantProduct = (product) => {
48
+ var _a;
48
49
  if (product == null ? void 0 : product.product_variant_id) {
49
- const targetVariant = product.variant.find(
50
+ const targetVariant = (_a = product == null ? void 0 : product.variant) == null ? void 0 : _a.find(
50
51
  (n) => n.id === product.product_variant_id
51
52
  );
52
53
  if (targetVariant) {
@@ -60,7 +61,8 @@ var handleVariantProduct = (product) => {
60
61
  return product;
61
62
  };
62
63
  var formatProductToCartItem = (params) => {
63
- var _a, _b;
64
+ var _a, _b, _c;
65
+ console.log("formatProductToCartItem>>>>>>", params);
64
66
  const {
65
67
  cartItem,
66
68
  product,
@@ -98,19 +100,19 @@ var formatProductToCartItem = (params) => {
98
100
  cartItem.options = formatOptions(options);
99
101
  }
100
102
  if (product_variant_id) {
101
- const sku_key = (_a = product.variant.find(
103
+ const sku_key = (_b = (_a = product == null ? void 0 : product.variant) == null ? void 0 : _a.find(
102
104
  (n) => n.id === product_variant_id
103
- )) == null ? void 0 : _a.sku_key;
105
+ )) == null ? void 0 : _b.sku_key;
104
106
  if (sku_key) {
105
107
  const sku_key_arr = sku_key.split("_");
106
108
  const product_option_string = [];
107
109
  sku_key_arr.forEach((item) => {
108
- var _a2;
110
+ var _a2, _b2;
109
111
  const keyMap = item.split(":");
110
- const targetVariantGroup = product.variant_group.find(
112
+ const targetVariantGroup = (_a2 = product == null ? void 0 : product.variant_group) == null ? void 0 : _a2.find(
111
113
  (n) => String(n.position_id) === keyMap[0]
112
114
  );
113
- const targetVariantItem = (_a2 = targetVariantGroup == null ? void 0 : targetVariantGroup.variant_item) == null ? void 0 : _a2.find(
115
+ const targetVariantItem = (_b2 = targetVariantGroup == null ? void 0 : targetVariantGroup.variant_item) == null ? void 0 : _b2.find(
114
116
  (n) => String(n.position_id) === keyMap[1]
115
117
  );
116
118
  if (targetVariantGroup && targetVariantItem) {
@@ -122,7 +124,7 @@ var formatProductToCartItem = (params) => {
122
124
  cartItem.product_option_string = product_option_string.join(", ");
123
125
  }
124
126
  }
125
- if (((_b = product == null ? void 0 : product.custom_deposit_data) == null ? void 0 : _b.has_deposit) == 1) {
127
+ if (((_c = product == null ? void 0 : product.custom_deposit_data) == null ? void 0 : _c.has_deposit) == 1) {
126
128
  cartItem.deposit = getProductDeposit({
127
129
  cartItem,
128
130
  product,
@@ -268,7 +270,7 @@ var formatBundleToOrigin = (bundle) => {
268
270
  });
269
271
  };
270
272
  var getProductDeposit = (params) => {
271
- var _a;
273
+ var _a, _b;
272
274
  const { cartItem, product, bundle, options } = params;
273
275
  const num = (params == null ? void 0 : params.num) || 1;
274
276
  if (((_a = product == null ? void 0 : product.custom_deposit_data) == null ? void 0 : _a.has_deposit) == 1) {
@@ -294,6 +296,24 @@ var getProductDeposit = (params) => {
294
296
  productHasDeposit = true;
295
297
  }
296
298
  } else {
299
+ if (product == null ? void 0 : product.product_variant_id) {
300
+ const variantProduct = (_b = product == null ? void 0 : product.variant) == null ? void 0 : _b.find(
301
+ (item) => (item == null ? void 0 : item.id) === (product == null ? void 0 : product.product_variant_id)
302
+ );
303
+ if (variantProduct) {
304
+ const depositData = variantProduct == null ? void 0 : variantProduct.custom_deposit_data;
305
+ const { depositTotal, result } = handleProductDeposit({
306
+ depositData,
307
+ total: (cartItem == null ? void 0 : cartItem.total) || 0,
308
+ num
309
+ });
310
+ if (result) {
311
+ total = depositTotal;
312
+ protocolIds.push(...(depositData == null ? void 0 : depositData.self_deposit_policy_ids) || []);
313
+ productHasDeposit = true;
314
+ }
315
+ }
316
+ }
297
317
  if (bundle == null ? void 0 : bundle.length) {
298
318
  total = bundle.reduce((accumulator, currBundleProduct) => {
299
319
  const depositData = currBundleProduct == null ? void 0 : currBundleProduct.custom_deposit_data;
@@ -1,3 +1,3 @@
1
1
  import { Product } from "../../Product";
2
2
  import { CartItem, IUpdateItemParams } from "../types";
3
- export declare function updateAllCartItemPrice(cartItems: CartItem[], priceData: any, getProduct: (id: number) => Promise<Product | undefined>, updateCart: (item: IUpdateItemParams) => void): Promise<void>;
3
+ export declare function updateAllCartItemPrice(cartItems: CartItem[], priceData: any, getProduct: (id: number) => Promise<Product | undefined>, updateCart: (item: IUpdateItemParams) => void, updateItemInitInfo: (item: IUpdateItemParams) => void): Promise<void>;
@@ -33,14 +33,17 @@ __export(changePrice_exports, {
33
33
  });
34
34
  module.exports = __toCommonJS(changePrice_exports);
35
35
  var import_decimal = __toESM(require("decimal.js"));
36
- async function updateAllCartItemPrice(cartItems, priceData, getProduct, updateCart) {
36
+ async function updateAllCartItemPrice(cartItems, priceData, getProduct, updateCart, updateItemInitInfo) {
37
37
  var _a, _b;
38
38
  for (const item of cartItems) {
39
39
  const targetProduct = priceData.find((n) => n.id === item.id);
40
40
  const cartProduct = await getProduct(
41
41
  item.id
42
42
  );
43
- const productInfo = cartProduct == null ? void 0 : cartProduct.getData();
43
+ let productInfo = cartProduct == null ? void 0 : cartProduct.getData();
44
+ if (!productInfo) {
45
+ productInfo = item._productOrigin;
46
+ }
44
47
  let bundle = item._bundleOrigin;
45
48
  productInfo.price = targetProduct == null ? void 0 : targetProduct.price;
46
49
  productInfo.base_price = targetProduct == null ? void 0 : targetProduct.base_price;
@@ -81,6 +84,10 @@ async function updateAllCartItemPrice(cartItems, priceData, getProduct, updateCa
81
84
  return n;
82
85
  });
83
86
  }
87
+ updateItemInitInfo({
88
+ _id: item._id,
89
+ product: productInfo
90
+ });
84
91
  updateCart({
85
92
  _id: item._id,
86
93
  product: productInfo,
@@ -259,7 +259,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
259
259
  cartItems,
260
260
  res,
261
261
  (id) => this.store.products.getProduct(id),
262
- (params) => this.store.cart.updateItem(params)
262
+ (params) => this.store.cart.updateItem(params),
263
+ (params) => this.store.cart.updateItemInitInfo(params)
263
264
  );
264
265
  this.core.effects.emit(
265
266
  `${this.store.cart.name}:onUpdateQuotationPrice`,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "3.0.50",
4
+ "version": "3.0.52",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",