@managesome/eposmatic-toolkit 0.2.263 → 0.2.265
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.
|
@@ -376,15 +376,18 @@ function getRedeemedOffersMap(orderDiscountDetails, categories, existingRedeemed
|
|
|
376
376
|
incrementOfferCount(item.item_discount_details.voucher_discount_id, itemQuantity);
|
|
377
377
|
}
|
|
378
378
|
}
|
|
379
|
-
const redeemedOffers = {
|
|
380
|
-
...normalizedExistingRedeemedOffers,
|
|
381
|
-
};
|
|
379
|
+
const redeemedOffers = {};
|
|
382
380
|
const derivedOfferIds = Object.keys(derivedRedeemedOffers);
|
|
383
381
|
for (let i = 0; i < derivedOfferIds.length; i++) {
|
|
384
382
|
const offerId = derivedOfferIds[i];
|
|
385
383
|
const existingCount = normalizedExistingRedeemedOffers[offerId] ?? 0;
|
|
386
384
|
const derivedCount = derivedRedeemedOffers[offerId] ?? 0;
|
|
387
|
-
|
|
385
|
+
// Keep counts monotonic only for offers that are still derived from the
|
|
386
|
+
// current cart snapshot. This prevents stale redeemed badges from
|
|
387
|
+
// surviving after an offer is removed from cart/order discount details.
|
|
388
|
+
if (derivedCount > 0) {
|
|
389
|
+
redeemedOffers[offerId] = Math.max(existingCount, derivedCount);
|
|
390
|
+
}
|
|
388
391
|
}
|
|
389
392
|
return Object.keys(redeemedOffers).length > 0 ? redeemedOffers : null;
|
|
390
393
|
}
|
|
@@ -64,6 +64,8 @@ export declare function getOffersWithStats({ offers, customer, vouchers, custome
|
|
|
64
64
|
offersWithStats: IOfferWithStats[];
|
|
65
65
|
totalClaimableOffers: number;
|
|
66
66
|
unlockedOffersApplicableTimes: Record<string, number>;
|
|
67
|
+
offersWithStatsHashKey: string;
|
|
68
|
+
unlockedOffersApplicableTimesHashKey: string;
|
|
67
69
|
};
|
|
68
70
|
export declare const getAppliedOfferIds: (order_discount_details: IOrder["order_discount_details"] | undefined, categories: IOrderCategory[] | undefined) => string[];
|
|
69
71
|
export {};
|
|
@@ -625,6 +625,53 @@ function getActionHint(offer, claimable) {
|
|
|
625
625
|
return 'Select items for discount';
|
|
626
626
|
return 'Ready to apply';
|
|
627
627
|
}
|
|
628
|
+
function getUnlockedOffersApplicableTimesHashKey(map) {
|
|
629
|
+
const keys = Object.keys(map).sort();
|
|
630
|
+
if (keys.length === 0)
|
|
631
|
+
return 'unlock:v1:empty';
|
|
632
|
+
let result = 'unlock:v1:';
|
|
633
|
+
for (let i = 0; i < keys.length; i++) {
|
|
634
|
+
const key = keys[i];
|
|
635
|
+
result += `${key}:${map[key]};`;
|
|
636
|
+
}
|
|
637
|
+
return result;
|
|
638
|
+
}
|
|
639
|
+
function getRewardPreviewHashKey(rewardPreview) {
|
|
640
|
+
if (rewardPreview == null)
|
|
641
|
+
return '';
|
|
642
|
+
return [
|
|
643
|
+
rewardPreview.type,
|
|
644
|
+
rewardPreview.label,
|
|
645
|
+
rewardPreview.discount_value ?? '',
|
|
646
|
+
rewardPreview.is_percentage ?? '',
|
|
647
|
+
rewardPreview.max_discount_amount ?? '',
|
|
648
|
+
rewardPreview.max_discount_percentage ?? '',
|
|
649
|
+
rewardPreview.free_items_count ?? '',
|
|
650
|
+
rewardPreview.points_value ?? '',
|
|
651
|
+
rewardPreview.cashback_value ?? '',
|
|
652
|
+
rewardPreview.gift_card_value ?? '',
|
|
653
|
+
].join('|');
|
|
654
|
+
}
|
|
655
|
+
// HASH KEY RULE: Every field on IOfferStats that can change must be included in the hash key below.
|
|
656
|
+
// If you add or rename a field on IOfferStats, you MUST add it to the hash string concatenation.
|
|
657
|
+
// Failing to do so will cause the frontend (OffersProvider) to miss state changes —
|
|
658
|
+
// it compares hash key strings to decide whether to update React state / dispatch Redux actions.
|
|
659
|
+
// The same rule applies to getUnlockedOffersApplicableTimesHashKey and getRewardPreviewHashKey.
|
|
660
|
+
function getOffersWithStatsHashKey(offersWithStats, totalClaimableOffers) {
|
|
661
|
+
if (offersWithStats.length === 0) {
|
|
662
|
+
return `offers:v1:empty:${totalClaimableOffers}`;
|
|
663
|
+
}
|
|
664
|
+
const sortedOffers = [...offersWithStats].sort((a, b) => a.offer._id.localeCompare(b.offer._id));
|
|
665
|
+
let result = `offers:v1:${totalClaimableOffers}|`;
|
|
666
|
+
for (let i = 0; i < sortedOffers.length; i++) {
|
|
667
|
+
const { offer, stats } = sortedOffers[i];
|
|
668
|
+
const eligibleItemIds = [...stats.eligible_item_ids].sort().join(',');
|
|
669
|
+
const eligibleCategoryIds = [...stats.eligible_category_ids].sort().join(',');
|
|
670
|
+
const rewardPreviewKey = getRewardPreviewHashKey(stats.reward_preview);
|
|
671
|
+
result += `${offer._id}:${stats.progress}:${stats.message}:${stats.invalid_offer ? 1 : 0}:${stats.redeemed_times}:${stats.claimable ? 1 : 0}:${stats.applicable_quantity}:${stats.action_hint ?? ''}:${stats.auto_apply ? 1 : 0}:${eligibleItemIds}:${eligibleCategoryIds}:${rewardPreviewKey};`;
|
|
672
|
+
}
|
|
673
|
+
return result;
|
|
674
|
+
}
|
|
628
675
|
function getOffersWithStats({ offers, customer, vouchers, customerVoucherUsage, customerGiftCardsUsage, redeemed_offers, platform, currency_symbol, currentItemsPrice, totalDiscountApplied, categories, order_discount_details, }) {
|
|
629
676
|
const offersWithStats = [];
|
|
630
677
|
const orderPrice = currentItemsPrice ?? 0;
|
|
@@ -1628,6 +1675,8 @@ function getOffersWithStats({ offers, customer, vouchers, customerVoucherUsage,
|
|
|
1628
1675
|
offersWithStats,
|
|
1629
1676
|
totalClaimableOffers,
|
|
1630
1677
|
unlockedOffersApplicableTimes,
|
|
1678
|
+
offersWithStatsHashKey: getOffersWithStatsHashKey(offersWithStats, totalClaimableOffers),
|
|
1679
|
+
unlockedOffersApplicableTimesHashKey: getUnlockedOffersApplicableTimesHashKey(unlockedOffersApplicableTimes),
|
|
1631
1680
|
};
|
|
1632
1681
|
}
|
|
1633
1682
|
const getAppliedOfferIds = (order_discount_details, categories) => {
|