@managesome/eposmatic-toolkit 0.2.373 → 0.2.375

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.
@@ -83,7 +83,7 @@ export declare function getUpdateCartInfoData(data: Partial<IOrder>, payload: Pa
83
83
  export declare function getRemoveItemFromCartData(data: Partial<IOrder>, payload: {
84
84
  _id: string;
85
85
  void_reason?: string;
86
- }, courses: ICourse[], listnerSettings: ICartListnerSettings): Partial<IOrder>;
86
+ }, courses: ICourse[], listnerSettings: ICartListnerSettings, appliedCustomDiscounts?: IAppliedCustomDiscount[]): Partial<IOrder>;
87
87
  export declare function getUpdatedCartInfoOnInit(data: Partial<IOrder>, order: Partial<IOrder>, courses: ICourse[], platform: PLATFORMS_ENUM | undefined, categories: IOrderCategory[] | undefined, mappedItems: Record<string, IItem>, tenantId: string | undefined, listnerSettings: ICartListnerSettings, offers: IOffer[] | undefined): Partial<IOrder>;
88
88
  /**
89
89
  * Drop entries from `redeemed_offers` (and any related discount/wallet state)
@@ -2032,10 +2032,34 @@ function getSyncedOrderDiscountDetailsWithCaps({ orderDiscountDetails, appliedCu
2032
2032
  }
2033
2033
  const discountValue = matchedOrderDiscount.value[platform] ?? matchedOrderDiscount.value.BASE_PRICE;
2034
2034
  let recalculatedDiscount;
2035
+ let isSpecialDiscountPercentage = matchedOrderDiscount.is_percentage;
2035
2036
  if (matchedOrderDiscount.is_percentage) {
2036
- // Percentage discount — keep the raw percentage value.
2037
- // getDiscountDetails will compute the absolute amount against the current subtotal.
2038
- recalculatedDiscount = discountValue;
2037
+ // Clamp percentage to 100% to match apply-time logic in CustomDiscountItem.tsx
2038
+ let discountPercentage = discountValue;
2039
+ if (discountPercentage > 100)
2040
+ discountPercentage = 100;
2041
+ const maxAmount = matchedOrderDiscount.max_amount
2042
+ ? (matchedOrderDiscount.max_amount[platform] ?? matchedOrderDiscount.max_amount.BASE_PRICE)
2043
+ : null;
2044
+ const hasCap = maxAmount != null && Number.isFinite(maxAmount) && maxAmount > 0;
2045
+ if (hasCap) {
2046
+ const computedDiscount = (discountPercentage / 100) * currentSubtotal;
2047
+ if (computedDiscount > maxAmount && maxAmount <= currentSubtotal) {
2048
+ // Cap exceeded — store as fixed amount equal to the cap
2049
+ recalculatedDiscount = maxAmount;
2050
+ isSpecialDiscountPercentage = false;
2051
+ }
2052
+ else {
2053
+ // Within cap — keep as percentage
2054
+ recalculatedDiscount = discountPercentage;
2055
+ isSpecialDiscountPercentage = true;
2056
+ }
2057
+ }
2058
+ else {
2059
+ // No cap configured — keep as percentage
2060
+ recalculatedDiscount = discountPercentage;
2061
+ isSpecialDiscountPercentage = true;
2062
+ }
2039
2063
  }
2040
2064
  else {
2041
2065
  // Fixed discount — amount stays as-is, but still subject to max_amount cap
@@ -2053,7 +2077,7 @@ function getSyncedOrderDiscountDetailsWithCaps({ orderDiscountDetails, appliedCu
2053
2077
  return {
2054
2078
  ...orderDiscountDetails,
2055
2079
  special_discount: (0, utils_1.parseNum)(recalculatedDiscount),
2056
- is_special_discount_percentage: matchedOrderDiscount.is_percentage,
2080
+ is_special_discount_percentage: isSpecialDiscountPercentage,
2057
2081
  total_discount: 0,
2058
2082
  };
2059
2083
  }
@@ -2087,10 +2111,34 @@ function getUpdateItemInCartData(data, payload, courses, listnerSettings, applie
2087
2111
  const platform = data.platform;
2088
2112
  const discountValue = matchedDiscount.value[platform] ?? matchedDiscount.value.BASE_PRICE;
2089
2113
  let recalculatedSpecialDiscount;
2114
+ let isItemDiscountPercentage = matchedDiscount.is_percentage;
2090
2115
  if (matchedDiscount.is_percentage) {
2091
- // Percentage discount — keep the raw percentage value.
2092
- // getDiscountDetails will compute the absolute amount against the current subtotal.
2093
- recalculatedSpecialDiscount = discountValue;
2116
+ // Clamp percentage to 100% to match apply-time logic in CustomDiscountItem.tsx
2117
+ let discountPercentage = discountValue;
2118
+ if (discountPercentage > 100)
2119
+ discountPercentage = 100;
2120
+ const maxAmount = matchedDiscount.max_amount
2121
+ ? (matchedDiscount.max_amount[platform] ?? matchedDiscount.max_amount.BASE_PRICE)
2122
+ : null;
2123
+ const hasCap = maxAmount != null && Number.isFinite(maxAmount) && maxAmount > 0;
2124
+ if (hasCap) {
2125
+ const computedDiscount = (discountPercentage / 100) * itemTotalWithoutTax;
2126
+ if (computedDiscount > maxAmount && maxAmount <= itemTotalWithoutTax) {
2127
+ // Cap exceeded — store as fixed amount equal to the cap
2128
+ recalculatedSpecialDiscount = maxAmount;
2129
+ isItemDiscountPercentage = false;
2130
+ }
2131
+ else {
2132
+ // Within cap — keep as percentage
2133
+ recalculatedSpecialDiscount = discountPercentage;
2134
+ isItemDiscountPercentage = true;
2135
+ }
2136
+ }
2137
+ else {
2138
+ // No cap configured — keep as percentage
2139
+ recalculatedSpecialDiscount = discountPercentage;
2140
+ isItemDiscountPercentage = true;
2141
+ }
2094
2142
  }
2095
2143
  else {
2096
2144
  // Fixed discount — the amount should NOT scale with quantity.
@@ -2110,7 +2158,7 @@ function getUpdateItemInCartData(data, payload, courses, listnerSettings, applie
2110
2158
  item_discount_details: {
2111
2159
  ...newItem.item_discount_details,
2112
2160
  special_discount: (0, utils_1.parseNum)(recalculatedSpecialDiscount),
2113
- is_special_discount_percentage: matchedDiscount.is_percentage,
2161
+ is_special_discount_percentage: isItemDiscountPercentage,
2114
2162
  total_discount: 0,
2115
2163
  },
2116
2164
  };
@@ -2242,7 +2290,7 @@ function getUpdateCartInfoData(data, payload, courses, listnerSettings, syncCont
2242
2290
  };
2243
2291
  }
2244
2292
  /* ======================><====================== */
2245
- function getRemoveItemFromCartData(data, payload, courses, listnerSettings) {
2293
+ function getRemoveItemFromCartData(data, payload, courses, listnerSettings, appliedCustomDiscounts) {
2246
2294
  const orderItemIdsMap = {};
2247
2295
  let categories;
2248
2296
  if (data.categories != null) {
@@ -2313,8 +2361,18 @@ function getRemoveItemFromCartData(data, payload, courses, listnerSettings) {
2313
2361
  iterations.push(firstIterationData);
2314
2362
  iterations.push(...restIterations);
2315
2363
  }
2364
+ // Re-evaluate order-wide custom discount cap after item removal
2365
+ const syncedOrderDiscountDetails = appliedCustomDiscounts && appliedCustomDiscounts.length > 0
2366
+ ? getSyncedOrderDiscountDetailsWithCaps({
2367
+ orderDiscountDetails: data.order_discount_details,
2368
+ appliedCustomDiscounts,
2369
+ categories,
2370
+ platform: data.platform,
2371
+ })
2372
+ : data.order_discount_details;
2316
2373
  const order = {
2317
2374
  ...data,
2375
+ order_discount_details: syncedOrderDiscountDetails,
2318
2376
  ...(iterations.length > 0 && { iterations }),
2319
2377
  categories,
2320
2378
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.2.373",
3
+ "version": "0.2.375",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",