@managesome/eposmatic-toolkit 0.2.288 → 0.2.289

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.
@@ -454,7 +454,8 @@ function getReconciledRedeemedOffersMap({ existingRedeemedOffers, categories, of
454
454
  if (applicableQuantity == null)
455
455
  continue;
456
456
  const selectedItemsCount = getTotalSelectedOfferItemsAgainstOffer(categories, normalizedOfferId);
457
- const redeemedTimes = Math.floor(selectedItemsCount / applicableQuantity);
457
+ // Percentage strategy: any partial usage of an item reward counts as a redeemed slot.
458
+ const redeemedTimes = selectedItemsCount > 0 ? Math.ceil(selectedItemsCount / applicableQuantity) : 0;
458
459
  if (redeemedTimes > 0) {
459
460
  nextRedeemedOffers[normalizedOfferId] = redeemedTimes;
460
461
  }
@@ -2097,6 +2098,12 @@ offers) {
2097
2098
  const orderLevelDiscountBaseAmount = (0, utils_1.getOrderSubtotalFromCategories)(categories);
2098
2099
  let order_discount_details = data.order_discount_details;
2099
2100
  let redeemed_offers = getNormalizedRedeemedOffersMap(data.redeemed_offers);
2101
+ const redeemedOffersPresenceMap = getReconciledRedeemedOffersMap({
2102
+ existingRedeemedOffers: redeemed_offers,
2103
+ categories,
2104
+ offers,
2105
+ removedOfferIds: new Set(),
2106
+ });
2100
2107
  const clearOrderLevelDiscount = (discountType) => {
2101
2108
  if (order_discount_details == null) {
2102
2109
  return;
@@ -2132,7 +2139,12 @@ offers) {
2132
2139
  // we check if either the loyalty_discount_id or voucher_discount_id
2133
2140
  const loyaltyDiscountId = order_discount_details.loyalty_discount_id;
2134
2141
  if (loyaltyDiscountId != null) {
2135
- if (unlockedOffersMap[loyaltyDiscountId] == null || unlockedOffersMap[loyaltyDiscountId] <= 0) {
2142
+ const normalizedLoyaltyDiscountId = getNormalizedOfferId(loyaltyDiscountId);
2143
+ const hasRedeemedEntryForLoyalty = normalizedLoyaltyDiscountId != null && (redeemedOffersPresenceMap?.[normalizedLoyaltyDiscountId] ?? 0) > 0;
2144
+ if (!hasRedeemedEntryForLoyalty) {
2145
+ clearOrderLevelDiscount('loyalty');
2146
+ }
2147
+ else if (unlockedOffersMap[loyaltyDiscountId] == null || unlockedOffersMap[loyaltyDiscountId] <= 0) {
2136
2148
  clearOrderLevelDiscount('loyalty');
2137
2149
  }
2138
2150
  else {
@@ -2188,7 +2200,12 @@ offers) {
2188
2200
  }
2189
2201
  const voucherDiscountId = order_discount_details.voucher_discount_id;
2190
2202
  if (voucherDiscountId != null) {
2191
- if (unlockedOffersMap[voucherDiscountId] == null || unlockedOffersMap[voucherDiscountId] <= 0) {
2203
+ const normalizedVoucherDiscountId = getNormalizedOfferId(voucherDiscountId);
2204
+ const hasRedeemedEntryForVoucher = normalizedVoucherDiscountId != null && (redeemedOffersPresenceMap?.[normalizedVoucherDiscountId] ?? 0) > 0;
2205
+ if (!hasRedeemedEntryForVoucher) {
2206
+ clearOrderLevelDiscount('voucher');
2207
+ }
2208
+ else if (unlockedOffersMap[voucherDiscountId] == null || unlockedOffersMap[voucherDiscountId] <= 0) {
2192
2209
  clearOrderLevelDiscount('voucher');
2193
2210
  }
2194
2211
  else {
@@ -2255,9 +2272,17 @@ offers) {
2255
2272
  if (item.item_discount_details != null) {
2256
2273
  const loyaltyDiscountId = item.item_discount_details.loyalty_discount_id;
2257
2274
  if (loyaltyDiscountId != null) {
2275
+ const normalizedLoyaltyDiscountId = getNormalizedOfferId(loyaltyDiscountId);
2276
+ const hasRedeemedEntryForLoyalty = normalizedLoyaltyDiscountId != null && (redeemedOffersPresenceMap?.[normalizedLoyaltyDiscountId] ?? 0) > 0;
2277
+ if (!hasRedeemedEntryForLoyalty) {
2278
+ hasChanges = true;
2279
+ if (normalizedLoyaltyDiscountId != null) {
2280
+ removedOfferIds.add(normalizedLoyaltyDiscountId);
2281
+ }
2282
+ continue;
2283
+ }
2258
2284
  if (unlockedOffersMap[loyaltyDiscountId] == null || unlockedOffersMap[loyaltyDiscountId] <= 0) {
2259
2285
  hasChanges = true;
2260
- const normalizedLoyaltyDiscountId = getNormalizedOfferId(loyaltyDiscountId);
2261
2286
  if (normalizedLoyaltyDiscountId != null) {
2262
2287
  removedOfferIds.add(normalizedLoyaltyDiscountId);
2263
2288
  }
@@ -2269,9 +2294,17 @@ offers) {
2269
2294
  }
2270
2295
  const voucherDiscountId = item.item_discount_details.voucher_discount_id;
2271
2296
  if (voucherDiscountId != null) {
2297
+ const normalizedVoucherDiscountId = getNormalizedOfferId(voucherDiscountId);
2298
+ const hasRedeemedEntryForVoucher = normalizedVoucherDiscountId != null && (redeemedOffersPresenceMap?.[normalizedVoucherDiscountId] ?? 0) > 0;
2299
+ if (!hasRedeemedEntryForVoucher) {
2300
+ hasChanges = true;
2301
+ if (normalizedVoucherDiscountId != null) {
2302
+ removedOfferIds.add(normalizedVoucherDiscountId);
2303
+ }
2304
+ continue;
2305
+ }
2272
2306
  if (unlockedOffersMap[voucherDiscountId] == null || unlockedOffersMap[voucherDiscountId] <= 0) {
2273
2307
  hasChanges = true;
2274
- const normalizedVoucherDiscountId = getNormalizedOfferId(voucherDiscountId);
2275
2308
  if (normalizedVoucherDiscountId != null) {
2276
2309
  removedOfferIds.add(normalizedVoucherDiscountId);
2277
2310
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.2.288",
3
+ "version": "0.2.289",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",