@pisell/pisellos 2.1.108 → 2.1.109

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.
@@ -46,6 +46,18 @@ var import_decimal = __toESM(require("decimal.js"));
46
46
  var import_utils = require("../../Product/utils");
47
47
  var import_utils2 = require("../../../solution/ShopDiscount/utils");
48
48
  var import_utils3 = require("../../Summary/utils");
49
+ var toDiscountPayload = (discountItem) => {
50
+ var _a, _b;
51
+ return {
52
+ amount: discountItem.amount,
53
+ tag: discountItem.type,
54
+ par_value: (_a = discountItem.discount) == null ? void 0 : _a.percent,
55
+ config: discountItem.config,
56
+ metadata: {
57
+ discount_card_type: (_b = discountItem == null ? void 0 : discountItem.discount) == null ? void 0 : _b.discount_card_type
58
+ }
59
+ };
60
+ };
49
61
  var handleVariantProduct = (product) => {
50
62
  var _a;
51
63
  if (product == null ? void 0 : product.product_variant_id) {
@@ -192,18 +204,24 @@ var formatProductToCartItemOrigin = (params) => {
192
204
  var getProductTotalPrice = (params) => {
193
205
  const { product, bundle, options, discounts } = params;
194
206
  let price = Number(product.price);
207
+ const optionRows = (options == null ? void 0 : options.map((currentValue) => ({
208
+ unit: Number(currentValue.price ?? currentValue.add_price ?? 0),
209
+ num: Number(currentValue.num ?? currentValue.quantity ?? 1)
210
+ }))) ?? [];
195
211
  if (discounts == null ? void 0 : discounts.length) {
196
212
  discounts.forEach((currentValue) => {
197
213
  var _a;
198
- price = (0, import_utils2.getDiscountAmount)({
199
- amount: currentValue.amount,
200
- tag: currentValue.type,
201
- par_value: currentValue.discount.percent,
202
- config: currentValue.config,
203
- metadata: {
204
- discount_card_type: (_a = currentValue == null ? void 0 : currentValue.discount) == null ? void 0 : _a.discount_card_type
214
+ const payload = toDiscountPayload(currentValue);
215
+ price = (0, import_utils2.getDiscountAmount)(payload, price, price);
216
+ if (((_a = currentValue == null ? void 0 : currentValue.config) == null ? void 0 : _a.deductOptionPrice) && optionRows.length) {
217
+ for (let i = 0; i < optionRows.length; i++) {
218
+ const row = optionRows[i];
219
+ optionRows[i] = {
220
+ ...row,
221
+ unit: (0, import_utils2.getDiscountAmount)(payload, row.unit, row.unit)
222
+ };
205
223
  }
206
- }, price, price);
224
+ }
207
225
  });
208
226
  }
209
227
  if (bundle == null ? void 0 : bundle.length) {
@@ -211,10 +229,11 @@ var getProductTotalPrice = (params) => {
211
229
  return accumulator + Number(currentValue.price) * Number(currentValue.num);
212
230
  }, price);
213
231
  }
214
- if (options == null ? void 0 : options.length) {
215
- price = options.reduce((accumulator, currentValue) => {
216
- return accumulator + Number(currentValue.price) * Number(currentValue.num);
217
- }, price);
232
+ if (optionRows.length) {
233
+ price = optionRows.reduce(
234
+ (accumulator, row) => accumulator + row.unit * row.num,
235
+ price
236
+ );
218
237
  }
219
238
  return Math.max(0, price);
220
239
  };
@@ -120,6 +120,8 @@ export interface Discount {
120
120
  allowCrossProduct?: boolean;
121
121
  /** 可用商品数量上限 */
122
122
  applicableProductLimit?: number;
123
+ /** 是否抵扣单规格价格 (Option Price) */
124
+ deductOptionPrice?: boolean;
123
125
  };
124
126
  applicableProductIds?: number[];
125
127
  applicableProductDetails: ApplicableProductDetails[];
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
49
49
  getCategories(): ProductCategory[];
50
50
  setOtherParams(key: string, value: any): void;
51
51
  getOtherParams(): any;
52
- getProductType(): "duration" | "session" | "normal";
52
+ getProductType(): "normal" | "duration" | "session";
53
53
  }