@pisell/pisellos 2.0.51 → 2.0.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/modules/Cart/utils/cartProduct.js +33 -9
- package/dist/modules/Cart/utils/changePrice.js +22 -4
- package/dist/solution/ShopDiscount/index.js +9 -8
- package/lib/modules/Cart/utils/cartProduct.js +29 -9
- package/lib/modules/Cart/utils/changePrice.js +20 -3
- package/lib/solution/ShopDiscount/index.js +6 -6
- package/package.json +1 -1
|
@@ -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$
|
|
92
|
-
var sku_key = (_product$
|
|
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$
|
|
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
|
|
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 =
|
|
356
|
-
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;
|
|
@@ -23,8 +23,8 @@ function _updateAllCartItemPrice() {
|
|
|
23
23
|
_iterator = _createForOfIteratorHelper(cartItems);
|
|
24
24
|
_context2.prev = 1;
|
|
25
25
|
_loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
|
|
26
|
-
var _bundle;
|
|
27
|
-
var item, targetProduct, cartProduct, productInfo, bundle;
|
|
26
|
+
var _item$_productOrigin, _bundle;
|
|
27
|
+
var item, targetProduct, cartProduct, productInfo, bundle, _productInfo$variant;
|
|
28
28
|
return _regeneratorRuntime().wrap(function _loop$(_context) {
|
|
29
29
|
while (1) switch (_context.prev = _context.next) {
|
|
30
30
|
case 0:
|
|
@@ -40,6 +40,7 @@ function _updateAllCartItemPrice() {
|
|
|
40
40
|
bundle = item._bundleOrigin;
|
|
41
41
|
productInfo.price = targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.price;
|
|
42
42
|
productInfo.base_price = targetProduct === null || targetProduct === void 0 ? void 0 : targetProduct.base_price;
|
|
43
|
+
productInfo.product_variant_id = (_item$_productOrigin = item._productOrigin) === null || _item$_productOrigin === void 0 ? void 0 : _item$_productOrigin.product_variant_id;
|
|
43
44
|
bundle = (_bundle = bundle) === null || _bundle === void 0 ? void 0 : _bundle.map(function (n) {
|
|
44
45
|
var _targetProduct$bundle;
|
|
45
46
|
// 更新 bundle 的价格
|
|
@@ -62,12 +63,29 @@ function _updateAllCartItemPrice() {
|
|
|
62
63
|
}
|
|
63
64
|
return n;
|
|
64
65
|
});
|
|
66
|
+
// 如果有返回variant,则把对应variant的数据也补充进去
|
|
67
|
+
if (targetProduct !== null && targetProduct !== void 0 && targetProduct.variant) {
|
|
68
|
+
productInfo.variant = (_productInfo$variant = productInfo.variant) === null || _productInfo$variant === void 0 ? void 0 : _productInfo$variant.map(function (n) {
|
|
69
|
+
var _targetProduct$varian;
|
|
70
|
+
var targetVariant = (_targetProduct$varian = targetProduct.variant) === null || _targetProduct$varian === void 0 ? void 0 : _targetProduct$varian.find(function (m) {
|
|
71
|
+
return m.id === n.id;
|
|
72
|
+
});
|
|
73
|
+
if (targetVariant) {
|
|
74
|
+
return _objectSpread(_objectSpread({}, n), {}, {
|
|
75
|
+
price: targetVariant.price,
|
|
76
|
+
base_price: targetVariant.base_price
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
return n;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
65
82
|
updateCart({
|
|
66
83
|
_id: item._id,
|
|
67
84
|
product: productInfo,
|
|
68
|
-
bundle: bundle
|
|
85
|
+
bundle: bundle,
|
|
86
|
+
options: item._optionsOrigin
|
|
69
87
|
});
|
|
70
|
-
case
|
|
88
|
+
case 13:
|
|
71
89
|
case "end":
|
|
72
90
|
return _context.stop();
|
|
73
91
|
}
|
|
@@ -489,6 +489,15 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
489
489
|
var newDiscountList = [].concat(editModeDiscountList, _toConsumableArray(discountList.filter(function (item) {
|
|
490
490
|
return !item.isDisabled;
|
|
491
491
|
})));
|
|
492
|
+
var isProductFree = function isProductFree(id) {
|
|
493
|
+
var _this3$hooks2;
|
|
494
|
+
var targetProduct = productList.find(function (n) {
|
|
495
|
+
return n.id === id;
|
|
496
|
+
});
|
|
497
|
+
var product = (_this3$hooks2 = _this3.hooks) === null || _this3$hooks2 === void 0 ? void 0 : _this3$hooks2.getProduct(targetProduct);
|
|
498
|
+
// 如果 product.total 是 0有可能是她已经用过商品券或者折扣卡导致的 0,所以此时还需要判断 origin_total 是否为 0
|
|
499
|
+
return Number(product === null || product === void 0 ? void 0 : product.total) === 0 && (Number(product === null || product === void 0 ? void 0 : product.origin_total) === 0 || !(product !== null && product !== void 0 && product.origin_total));
|
|
500
|
+
};
|
|
492
501
|
var allUsedProductIds = newDiscountList.map(function (n) {
|
|
493
502
|
var _n$appliedProductDeta;
|
|
494
503
|
return n.isSelected ? (_n$appliedProductDeta = n.appliedProductDetails) === null || _n$appliedProductDeta === void 0 ? void 0 : _n$appliedProductDeta.map(function (n) {
|
|
@@ -498,14 +507,6 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
498
507
|
}).flat();
|
|
499
508
|
newDiscountList.forEach(function (item) {
|
|
500
509
|
var _item$applicableProdu;
|
|
501
|
-
var isProductFree = function isProductFree(id) {
|
|
502
|
-
var _this3$hooks2;
|
|
503
|
-
var targetProduct = productList.find(function (n) {
|
|
504
|
-
return n.id === id;
|
|
505
|
-
});
|
|
506
|
-
var product = (_this3$hooks2 = _this3.hooks) === null || _this3$hooks2 === void 0 ? void 0 : _this3$hooks2.getProduct(targetProduct);
|
|
507
|
-
return Number(product === null || product === void 0 ? void 0 : product.total) === 0;
|
|
508
|
-
};
|
|
509
510
|
var isAllProductUsedOrFree = (_item$applicableProdu = item.applicableProductIds) === null || _item$applicableProdu === void 0 ? void 0 : _item$applicableProdu.every(function (id) {
|
|
510
511
|
var _item$applicableProdu2;
|
|
511
512
|
// 检查当前 id是否在 item.applicableProductIds 里出现了几次,且要求次数和 item.applicableProductIds 里出现的次数一致
|
|
@@ -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 :
|
|
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 = (
|
|
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 (((
|
|
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;
|
|
@@ -34,6 +34,7 @@ __export(changePrice_exports, {
|
|
|
34
34
|
module.exports = __toCommonJS(changePrice_exports);
|
|
35
35
|
var import_decimal = __toESM(require("decimal.js"));
|
|
36
36
|
async function updateAllCartItemPrice(cartItems, priceData, getProduct, updateCart) {
|
|
37
|
+
var _a, _b;
|
|
37
38
|
for (const item of cartItems) {
|
|
38
39
|
const targetProduct = priceData.find((n) => n.id === item.id);
|
|
39
40
|
const cartProduct = await getProduct(
|
|
@@ -43,9 +44,10 @@ async function updateAllCartItemPrice(cartItems, priceData, getProduct, updateCa
|
|
|
43
44
|
let bundle = item._bundleOrigin;
|
|
44
45
|
productInfo.price = targetProduct == null ? void 0 : targetProduct.price;
|
|
45
46
|
productInfo.base_price = targetProduct == null ? void 0 : targetProduct.base_price;
|
|
47
|
+
productInfo.product_variant_id = (_a = item._productOrigin) == null ? void 0 : _a.product_variant_id;
|
|
46
48
|
bundle = bundle == null ? void 0 : bundle.map((n) => {
|
|
47
|
-
var
|
|
48
|
-
const targetBundle = (
|
|
49
|
+
var _a2;
|
|
50
|
+
const targetBundle = (_a2 = targetProduct == null ? void 0 : targetProduct.bundle_group) == null ? void 0 : _a2.find(
|
|
49
51
|
(m) => m.id === n.group_id
|
|
50
52
|
);
|
|
51
53
|
if (targetBundle) {
|
|
@@ -65,10 +67,25 @@ async function updateAllCartItemPrice(cartItems, priceData, getProduct, updateCa
|
|
|
65
67
|
}
|
|
66
68
|
return n;
|
|
67
69
|
});
|
|
70
|
+
if (targetProduct == null ? void 0 : targetProduct.variant) {
|
|
71
|
+
productInfo.variant = (_b = productInfo.variant) == null ? void 0 : _b.map((n) => {
|
|
72
|
+
var _a2;
|
|
73
|
+
const targetVariant = (_a2 = targetProduct.variant) == null ? void 0 : _a2.find((m) => m.id === n.id);
|
|
74
|
+
if (targetVariant) {
|
|
75
|
+
return {
|
|
76
|
+
...n,
|
|
77
|
+
price: targetVariant.price,
|
|
78
|
+
base_price: targetVariant.base_price
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
return n;
|
|
82
|
+
});
|
|
83
|
+
}
|
|
68
84
|
updateCart({
|
|
69
85
|
_id: item._id,
|
|
70
86
|
product: productInfo,
|
|
71
|
-
bundle
|
|
87
|
+
bundle,
|
|
88
|
+
options: item._optionsOrigin
|
|
72
89
|
});
|
|
73
90
|
}
|
|
74
91
|
}
|
|
@@ -333,6 +333,12 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
333
333
|
...editModeDiscountList,
|
|
334
334
|
...discountList.filter((item) => !item.isDisabled)
|
|
335
335
|
];
|
|
336
|
+
const isProductFree = (id) => {
|
|
337
|
+
var _a2;
|
|
338
|
+
const targetProduct = productList.find((n) => n.id === id);
|
|
339
|
+
const product = (_a2 = this.hooks) == null ? void 0 : _a2.getProduct(targetProduct);
|
|
340
|
+
return Number(product == null ? void 0 : product.total) === 0 && (Number(product == null ? void 0 : product.origin_total) === 0 || !(product == null ? void 0 : product.origin_total));
|
|
341
|
+
};
|
|
336
342
|
const allUsedProductIds = newDiscountList.map((n) => {
|
|
337
343
|
var _a2;
|
|
338
344
|
return n.isSelected ? (_a2 = n.appliedProductDetails) == null ? void 0 : _a2.map((n2) => {
|
|
@@ -342,12 +348,6 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
342
348
|
}).flat();
|
|
343
349
|
newDiscountList.forEach((item) => {
|
|
344
350
|
var _a2;
|
|
345
|
-
const isProductFree = (id) => {
|
|
346
|
-
var _a3;
|
|
347
|
-
const targetProduct = productList.find((n) => n.id === id);
|
|
348
|
-
const product = (_a3 = this.hooks) == null ? void 0 : _a3.getProduct(targetProduct);
|
|
349
|
-
return Number(product == null ? void 0 : product.total) === 0;
|
|
350
|
-
};
|
|
351
351
|
const isAllProductUsedOrFree = (_a2 = item.applicableProductIds) == null ? void 0 : _a2.every((id) => {
|
|
352
352
|
var _a3;
|
|
353
353
|
const sameIdTimes = ((_a3 = item.applicableProductIds) == null ? void 0 : _a3.filter((n) => n === id).length) || 1;
|