@pisell/pisellos 3.0.65 → 3.0.66
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/solution/BookingByStep/index.d.ts +16 -4
- package/dist/solution/BookingByStep/index.js +702 -110
- package/dist/solution/BookingByStep/utils/capacity.d.ts +23 -0
- package/dist/solution/BookingByStep/utils/capacity.js +230 -1
- package/dist/solution/BookingByStep/utils/resources.d.ts +15 -0
- package/dist/solution/BookingByStep/utils/resources.js +1 -1
- package/dist/solution/BookingByStep/utils/stock.d.ts +29 -0
- package/dist/solution/BookingByStep/utils/stock.js +126 -0
- package/lib/solution/BookingByStep/index.d.ts +16 -4
- package/lib/solution/BookingByStep/index.js +387 -9
- package/lib/solution/BookingByStep/utils/capacity.d.ts +23 -0
- package/lib/solution/BookingByStep/utils/capacity.js +166 -0
- package/lib/solution/BookingByStep/utils/resources.d.ts +15 -0
- package/lib/solution/BookingByStep/utils/resources.js +2 -0
- package/lib/solution/BookingByStep/utils/stock.d.ts +29 -0
- package/lib/solution/BookingByStep/utils/stock.js +89 -0
- package/package.json +1 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __export = (target, all) => {
|
|
6
8
|
for (var name in all)
|
|
@@ -14,18 +16,30 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
14
16
|
}
|
|
15
17
|
return to;
|
|
16
18
|
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
17
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
28
|
|
|
19
29
|
// src/solution/BookingByStep/utils/capacity.ts
|
|
20
30
|
var capacity_exports = {};
|
|
21
31
|
__export(capacity_exports, {
|
|
32
|
+
calculateCartItemsCapacityUsageByResourceType: () => calculateCartItemsCapacityUsageByResourceType,
|
|
22
33
|
checkResourceCanUseByCapacity: () => checkResourceCanUseByCapacity,
|
|
23
34
|
checkSubResourcesCapacity: () => checkSubResourcesCapacity,
|
|
35
|
+
checkTimeSlotCapacity: () => checkTimeSlotCapacity,
|
|
24
36
|
formatDefaultCapacitys: () => formatDefaultCapacitys,
|
|
25
37
|
getCapacityInfoByCartItem: () => getCapacityInfoByCartItem,
|
|
38
|
+
getResourcesIdsByProduct: () => getResourcesIdsByProduct,
|
|
26
39
|
getSumCapacity: () => getSumCapacity
|
|
27
40
|
});
|
|
28
41
|
module.exports = __toCommonJS(capacity_exports);
|
|
42
|
+
var import_dayjs = __toESM(require("dayjs"));
|
|
29
43
|
var formatDefaultCapacitys = ({
|
|
30
44
|
capacity,
|
|
31
45
|
product_bundle
|
|
@@ -96,11 +110,163 @@ var checkResourceCanUseByCapacity = (currentCapacity, requiredCapacity, maxCapac
|
|
|
96
110
|
}
|
|
97
111
|
return currentCapacity + requiredCapacity <= maxCapacity;
|
|
98
112
|
};
|
|
113
|
+
function calculateCartItemsCapacityUsageByResourceType({
|
|
114
|
+
cartItems,
|
|
115
|
+
timeSlotStart,
|
|
116
|
+
timeSlotEnd,
|
|
117
|
+
allProductResources
|
|
118
|
+
}) {
|
|
119
|
+
const resourceTypeMap = {};
|
|
120
|
+
allProductResources.forEach((resource) => {
|
|
121
|
+
var _a;
|
|
122
|
+
const formId = ((_a = resource.form_id) == null ? void 0 : _a.toString()) || "default";
|
|
123
|
+
if (!resourceTypeMap[formId]) {
|
|
124
|
+
resourceTypeMap[formId] = [];
|
|
125
|
+
}
|
|
126
|
+
resourceTypeMap[formId].push(resource);
|
|
127
|
+
});
|
|
128
|
+
const capacityUsageByType = {};
|
|
129
|
+
Object.keys(resourceTypeMap).forEach((formId) => {
|
|
130
|
+
let totalUsage = 0;
|
|
131
|
+
const resourcesInThisType = resourceTypeMap[formId];
|
|
132
|
+
const resourceIdsInThisType = resourcesInThisType.map((r) => r.id);
|
|
133
|
+
cartItems.forEach((cartItem) => {
|
|
134
|
+
if (!cartItem.start_time || !cartItem.end_time)
|
|
135
|
+
return;
|
|
136
|
+
const itemStart = `${cartItem.start_date} ${cartItem.start_time}`;
|
|
137
|
+
const itemEnd = `${cartItem.end_date || cartItem.start_date} ${cartItem.end_time}`;
|
|
138
|
+
const hasTimeOverlap = !((0, import_dayjs.default)(itemEnd).isBefore((0, import_dayjs.default)(timeSlotStart)) || (0, import_dayjs.default)(itemStart).isAfter((0, import_dayjs.default)(timeSlotEnd)));
|
|
139
|
+
if (!hasTimeOverlap)
|
|
140
|
+
return;
|
|
141
|
+
const productResourceIds = getResourcesIdsByProduct(cartItem._productOrigin);
|
|
142
|
+
const hasResourceTypeOverlap = productResourceIds.some(
|
|
143
|
+
(id) => resourceIdsInThisType.includes(id)
|
|
144
|
+
);
|
|
145
|
+
if (!hasResourceTypeOverlap)
|
|
146
|
+
return;
|
|
147
|
+
const { currentCapacity } = getCapacityInfoByCartItem(cartItem);
|
|
148
|
+
totalUsage += currentCapacity;
|
|
149
|
+
});
|
|
150
|
+
capacityUsageByType[formId] = totalUsage;
|
|
151
|
+
});
|
|
152
|
+
return capacityUsageByType;
|
|
153
|
+
}
|
|
154
|
+
function getResourcesIdsByProduct(product) {
|
|
155
|
+
var _a, _b, _c;
|
|
156
|
+
const tempResourceIds = [];
|
|
157
|
+
(_c = (_b = (_a = product == null ? void 0 : product.product_resource) == null ? void 0 : _a.resources) == null ? void 0 : _b.forEach) == null ? void 0 : _c.call(_b, (resource) => {
|
|
158
|
+
var _a2, _b2;
|
|
159
|
+
if ((resource == null ? void 0 : resource.status) == 1) {
|
|
160
|
+
if ((_a2 = resource == null ? void 0 : resource.default_resource) == null ? void 0 : _a2.length) {
|
|
161
|
+
tempResourceIds.push(...resource == null ? void 0 : resource.default_resource);
|
|
162
|
+
} else if ((_b2 = resource == null ? void 0 : resource.optional_resource) == null ? void 0 : _b2.length) {
|
|
163
|
+
tempResourceIds.push(...resource == null ? void 0 : resource.optional_resource);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
return tempResourceIds;
|
|
168
|
+
}
|
|
169
|
+
function checkTimeSlotCapacity(timeSlotStart, timeSlotEnd, cartItems, allResources) {
|
|
170
|
+
var _a, _b;
|
|
171
|
+
const resourceTypeMap = {};
|
|
172
|
+
allResources.forEach((resource) => {
|
|
173
|
+
var _a2;
|
|
174
|
+
const formId = ((_a2 = resource.form_id) == null ? void 0 : _a2.toString()) || "default";
|
|
175
|
+
if (!resourceTypeMap[formId]) {
|
|
176
|
+
resourceTypeMap[formId] = [];
|
|
177
|
+
}
|
|
178
|
+
resourceTypeMap[formId].push(resource);
|
|
179
|
+
});
|
|
180
|
+
const requiredCapacityByType = {};
|
|
181
|
+
cartItems.forEach((cartItem) => {
|
|
182
|
+
const productResourceIds = getResourcesIdsByProduct(cartItem._productOrigin);
|
|
183
|
+
const { currentCapacity } = getCapacityInfoByCartItem(cartItem);
|
|
184
|
+
Object.keys(resourceTypeMap).forEach((formId) => {
|
|
185
|
+
var _a2, _b2, _c, _d;
|
|
186
|
+
const resourcesInType = resourceTypeMap[formId];
|
|
187
|
+
const resourceIdsInType = resourcesInType.map((r) => r.id);
|
|
188
|
+
const selectType = (_d = (_c = (_b2 = (_a2 = cartItem._productOrigin) == null ? void 0 : _a2.product_resource) == null ? void 0 : _b2.resources) == null ? void 0 : _c.find((r) => {
|
|
189
|
+
var _a3;
|
|
190
|
+
return ((_a3 = r.id) == null ? void 0 : _a3.toString()) === formId;
|
|
191
|
+
})) == null ? void 0 : _d.type;
|
|
192
|
+
const needsThisResourceType = productResourceIds.some(
|
|
193
|
+
(id) => resourceIdsInType.includes(id)
|
|
194
|
+
);
|
|
195
|
+
if (needsThisResourceType) {
|
|
196
|
+
if (selectType === "single") {
|
|
197
|
+
requiredCapacityByType[formId] = (requiredCapacityByType[formId] || 0) + 1;
|
|
198
|
+
} else {
|
|
199
|
+
requiredCapacityByType[formId] = (requiredCapacityByType[formId] || 0) + currentCapacity;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
for (const [formId, requiredCapacity] of Object.entries(requiredCapacityByType)) {
|
|
205
|
+
const resourcesInType = resourceTypeMap[formId];
|
|
206
|
+
if (resourcesInType.length === 0)
|
|
207
|
+
continue;
|
|
208
|
+
let resourceTypeConfig = null;
|
|
209
|
+
for (const cartItem of cartItems) {
|
|
210
|
+
if ((_b = (_a = cartItem._productOrigin) == null ? void 0 : _a.product_resource) == null ? void 0 : _b.resources) {
|
|
211
|
+
resourceTypeConfig = cartItem._productOrigin.product_resource.resources.find(
|
|
212
|
+
(r) => {
|
|
213
|
+
var _a2;
|
|
214
|
+
return ((_a2 = r.id) == null ? void 0 : _a2.toString()) === formId && r.status === 1;
|
|
215
|
+
}
|
|
216
|
+
);
|
|
217
|
+
if (resourceTypeConfig)
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
const isMultipleBooking = (resourceTypeConfig == null ? void 0 : resourceTypeConfig.type) === "multiple";
|
|
222
|
+
console.log(`capacity.ts - 资源类型 ${formId} 配置:`, {
|
|
223
|
+
resourceTypeConfig,
|
|
224
|
+
type: resourceTypeConfig == null ? void 0 : resourceTypeConfig.type,
|
|
225
|
+
isMultipleBooking,
|
|
226
|
+
requiredCapacity
|
|
227
|
+
});
|
|
228
|
+
if (isMultipleBooking) {
|
|
229
|
+
let totalAvailableCapacity = 0;
|
|
230
|
+
resourcesInType.forEach((resource) => {
|
|
231
|
+
const availableTimes = resource.times.filter((time) => {
|
|
232
|
+
return !(0, import_dayjs.default)(time.start_at).isAfter((0, import_dayjs.default)(timeSlotStart), "minute") && !(0, import_dayjs.default)(time.end_at).isBefore((0, import_dayjs.default)(timeSlotEnd), "minute") || (0, import_dayjs.default)(time.start_at).isBefore((0, import_dayjs.default)(timeSlotEnd), "minute") && (0, import_dayjs.default)(time.end_at).isAfter((0, import_dayjs.default)(timeSlotStart), "minute");
|
|
233
|
+
});
|
|
234
|
+
if (availableTimes.length > 0) {
|
|
235
|
+
totalAvailableCapacity += resource.capacity || 0;
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
console.log(`capacity.ts - 资源类型 ${formId} 多个预约检查: 总容量 ${totalAvailableCapacity}, 需求 ${requiredCapacity}`);
|
|
239
|
+
if (totalAvailableCapacity < requiredCapacity) {
|
|
240
|
+
console.log(`资源类型 ${formId} 容量不足: 需要 ${requiredCapacity}, 可用 ${totalAvailableCapacity}`);
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
} else {
|
|
244
|
+
let availableResourceCount = 0;
|
|
245
|
+
resourcesInType.forEach((resource) => {
|
|
246
|
+
const availableTimes = resource.times.filter((time) => {
|
|
247
|
+
return !(0, import_dayjs.default)(time.start_at).isAfter((0, import_dayjs.default)(timeSlotStart), "minute") && !(0, import_dayjs.default)(time.end_at).isBefore((0, import_dayjs.default)(timeSlotEnd), "minute") || (0, import_dayjs.default)(time.start_at).isBefore((0, import_dayjs.default)(timeSlotEnd), "minute") && (0, import_dayjs.default)(time.end_at).isAfter((0, import_dayjs.default)(timeSlotStart), "minute");
|
|
248
|
+
});
|
|
249
|
+
if (availableTimes.length > 0) {
|
|
250
|
+
availableResourceCount++;
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
console.log(`capacity.ts - 资源类型 ${formId} 单个预约检查: 可用资源数 ${availableResourceCount}, 需求 ${requiredCapacity}`);
|
|
254
|
+
if (availableResourceCount < requiredCapacity) {
|
|
255
|
+
console.log(`资源类型 ${formId} 数量不足: 需要 ${requiredCapacity}, 可用 ${availableResourceCount}`);
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
99
262
|
// Annotate the CommonJS export names for ESM import in node:
|
|
100
263
|
0 && (module.exports = {
|
|
264
|
+
calculateCartItemsCapacityUsageByResourceType,
|
|
101
265
|
checkResourceCanUseByCapacity,
|
|
102
266
|
checkSubResourcesCapacity,
|
|
267
|
+
checkTimeSlotCapacity,
|
|
103
268
|
formatDefaultCapacitys,
|
|
104
269
|
getCapacityInfoByCartItem,
|
|
270
|
+
getResourcesIdsByProduct,
|
|
105
271
|
getSumCapacity
|
|
106
272
|
});
|
|
@@ -20,6 +20,21 @@ export interface ResourceItem {
|
|
|
20
20
|
interface BookingItem {
|
|
21
21
|
[key: string]: any;
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* @title: 判断两个时间段是否有重叠
|
|
25
|
+
* @description:
|
|
26
|
+
* @param {object} event
|
|
27
|
+
* @param {object} current
|
|
28
|
+
* @return {*}
|
|
29
|
+
* @Author: zhiwei.Wang
|
|
30
|
+
*/
|
|
31
|
+
export declare const isConflict: (event: {
|
|
32
|
+
start_at: DateType;
|
|
33
|
+
end_at: DateType;
|
|
34
|
+
}, current: {
|
|
35
|
+
start_at: DateType;
|
|
36
|
+
end_at?: DateType;
|
|
37
|
+
}) => boolean;
|
|
23
38
|
/**
|
|
24
39
|
* @title: 获取时间切片是否可用
|
|
25
40
|
* @description: 根据时间切片、资源、当前预约量判断时间切片是否可用
|
|
@@ -43,6 +43,7 @@ __export(resources_exports, {
|
|
|
43
43
|
getTimeSlicesByResource: () => getTimeSlicesByResource,
|
|
44
44
|
getTimeSlicesByResources: () => getTimeSlicesByResources,
|
|
45
45
|
getTimesIntersection: () => getTimesIntersection,
|
|
46
|
+
isConflict: () => isConflict,
|
|
46
47
|
mergeSubResourcesTimeSlices: () => mergeSubResourcesTimeSlices,
|
|
47
48
|
sortCombinedResources: () => sortCombinedResources
|
|
48
49
|
});
|
|
@@ -636,6 +637,7 @@ function checkTwoResourcesIntersection(resource1, resource2) {
|
|
|
636
637
|
getTimeSlicesByResource,
|
|
637
638
|
getTimeSlicesByResources,
|
|
638
639
|
getTimesIntersection,
|
|
640
|
+
isConflict,
|
|
639
641
|
mergeSubResourcesTimeSlices,
|
|
640
642
|
sortCombinedResources
|
|
641
643
|
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { CartItem } from '../../../modules';
|
|
2
|
+
/**
|
|
3
|
+
* 检测商品库存是否足够
|
|
4
|
+
*
|
|
5
|
+
* 只有同时满足以下条件时才会进行库存检测:
|
|
6
|
+
* - is_track 开启(值为 1 或 true)
|
|
7
|
+
* - over_sold 为 0(不允许超卖)
|
|
8
|
+
*
|
|
9
|
+
* 对于多规格商品:
|
|
10
|
+
* - 如果有 product_variant_id,则从 productData.variant 数组中查找对应规格
|
|
11
|
+
* - 使用规格的 is_track, over_sold, stock_quantity 而不是主商品的
|
|
12
|
+
*
|
|
13
|
+
* @param productData 商品数据(需包含 is_track, over_sold, stock_quantity 字段,多规格商品需包含 variant 数组)
|
|
14
|
+
* @param product_variant_id 商品变体ID,如果存在则为多规格商品
|
|
15
|
+
* @param quantity 需要添加的数量
|
|
16
|
+
* @param bundle 套餐配置(子商品需包含 is_track, over_sold, stock_quantity 字段)
|
|
17
|
+
* @param currentCartItems 当前购物车商品列表
|
|
18
|
+
* @returns 库存检测结果
|
|
19
|
+
*/
|
|
20
|
+
export declare function checkProductStock({ productData, product_variant_id, quantity, bundle, currentCartItems }: {
|
|
21
|
+
productData: any;
|
|
22
|
+
product_variant_id?: any;
|
|
23
|
+
quantity: number;
|
|
24
|
+
bundle?: any[];
|
|
25
|
+
currentCartItems: CartItem[];
|
|
26
|
+
}): {
|
|
27
|
+
success: boolean;
|
|
28
|
+
errorCode?: string;
|
|
29
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/solution/BookingByStep/utils/stock.ts
|
|
20
|
+
var stock_exports = {};
|
|
21
|
+
__export(stock_exports, {
|
|
22
|
+
checkProductStock: () => checkProductStock
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(stock_exports);
|
|
25
|
+
function checkProductStock({
|
|
26
|
+
productData,
|
|
27
|
+
product_variant_id,
|
|
28
|
+
quantity,
|
|
29
|
+
bundle,
|
|
30
|
+
currentCartItems
|
|
31
|
+
}) {
|
|
32
|
+
let mainProductConfig = productData;
|
|
33
|
+
if (product_variant_id && productData.variant && Array.isArray(productData.variant)) {
|
|
34
|
+
const variant = productData.variant.find((v) => v.id === product_variant_id);
|
|
35
|
+
if (variant) {
|
|
36
|
+
mainProductConfig = variant;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const isMainProductTrackingEnabled = mainProductConfig.is_track === 1 || mainProductConfig.is_track === true;
|
|
40
|
+
const isMainProductOverSoldDisabled = mainProductConfig.over_sold === 0;
|
|
41
|
+
if (isMainProductTrackingEnabled && isMainProductOverSoldDisabled) {
|
|
42
|
+
const existingQuantity = currentCartItems.reduce((total, cartItem) => {
|
|
43
|
+
var _a, _b, _c;
|
|
44
|
+
const isSameProduct = ((_a = cartItem._productOrigin) == null ? void 0 : _a.id) === productData.id;
|
|
45
|
+
const isSameVariant = !product_variant_id && !((_b = cartItem._productOrigin) == null ? void 0 : _b.product_variant_id) || ((_c = cartItem._productOrigin) == null ? void 0 : _c.product_variant_id) === product_variant_id;
|
|
46
|
+
if (isSameProduct && isSameVariant) {
|
|
47
|
+
return total + (cartItem.num || 0);
|
|
48
|
+
}
|
|
49
|
+
return total;
|
|
50
|
+
}, 0);
|
|
51
|
+
const totalQuantity = existingQuantity + quantity;
|
|
52
|
+
const stockQuantity = mainProductConfig.stock_quantity;
|
|
53
|
+
if (stockQuantity !== void 0 && stockQuantity !== null && totalQuantity > stockQuantity) {
|
|
54
|
+
return { success: false, errorCode: "not_enough_stock" };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (bundle && Array.isArray(bundle)) {
|
|
58
|
+
for (const bundleItem of bundle) {
|
|
59
|
+
const bundleProductId = bundleItem.bundle_product_id;
|
|
60
|
+
const bundleStockQuantity = bundleItem.stock_quantity;
|
|
61
|
+
const bundleRequiredQuantity = (bundleItem.num || 1) * quantity;
|
|
62
|
+
const isBundleTrackingEnabled = bundleItem.is_track === 1 || bundleItem.is_track === true;
|
|
63
|
+
const isBundleOverSoldDisabled = bundleItem.over_sold === 0;
|
|
64
|
+
if (!isBundleTrackingEnabled || !isBundleOverSoldDisabled)
|
|
65
|
+
continue;
|
|
66
|
+
if (bundleStockQuantity === void 0 || bundleStockQuantity === null)
|
|
67
|
+
continue;
|
|
68
|
+
const existingBundleQuantity = currentCartItems.reduce((total, cartItem) => {
|
|
69
|
+
if (!cartItem._bundleOrigin || !Array.isArray(cartItem._bundleOrigin))
|
|
70
|
+
return total;
|
|
71
|
+
cartItem._bundleOrigin.forEach((cartBundleItem) => {
|
|
72
|
+
if (cartBundleItem.bundle_product_id === bundleProductId) {
|
|
73
|
+
total += (cartBundleItem.num || 1) * (cartItem.num || 1);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
return total;
|
|
77
|
+
}, 0);
|
|
78
|
+
const totalBundleQuantity = existingBundleQuantity + bundleRequiredQuantity;
|
|
79
|
+
if (totalBundleQuantity > bundleStockQuantity) {
|
|
80
|
+
return { success: false, errorCode: "not_enough_stock" };
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return { success: true };
|
|
85
|
+
}
|
|
86
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
87
|
+
0 && (module.exports = {
|
|
88
|
+
checkProductStock
|
|
89
|
+
});
|