UNPKG

@pisell/pisellos

Version:

一个可扩展的前端模块化SDK框架,支持插件系统

65 lines (63 loc) 2.33 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/modules/Cart/utils/changePrice.ts var changePrice_exports = {}; __export(changePrice_exports, { updateAllCartItemPrice: () => updateAllCartItemPrice }); module.exports = __toCommonJS(changePrice_exports); async function updateAllCartItemPrice(cartItems, priceData, getProduct, updateCart) { for (const item of cartItems) { const targetProduct = priceData.find((n) => n.id === item.id); const cartProduct = await getProduct( item.id ); const productInfo = cartProduct == null ? void 0 : cartProduct.getData(); let bundle = item._bundleOrigin; productInfo.price = targetProduct == null ? void 0 : targetProduct.price; productInfo.base_price = targetProduct == null ? void 0 : targetProduct.base_price; bundle = bundle == null ? void 0 : bundle.map((n) => { var _a; const targetBundle = (_a = targetProduct == null ? void 0 : targetProduct.bundle_group) == null ? void 0 : _a.find( (m) => m.id === n.group_id ); if (targetBundle) { const targetBundleItem = targetBundle.bundle_item.find( (m) => m.id === n.id ); if (targetBundleItem) { return { ...n, price: targetBundleItem.price, base_price: targetBundleItem.base_price }; } } return n; }); updateCart({ _id: item._id, product: productInfo, bundle }); } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { updateAllCartItemPrice });