@managesome/eposmatic-toolkit 0.2.488 → 0.2.490
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.
- package/lib/helpers/store/cart-actions.js +174 -39
- package/lib/helpers/store/catalog-actions.d.ts +9 -3
- package/lib/helpers/store/catalog-actions.js +54 -0
- package/lib/helpers/types/index.d.ts +1 -0
- package/lib/helpers/types/index.js +1 -0
- package/lib/helpers/types/inventory-catalog.d.ts +18 -0
- package/lib/helpers/types/inventory-catalog.js +2 -0
- package/lib/helpers/utils/offers-helpers.js +26 -14
- package/package.json +1 -1
|
@@ -972,23 +972,33 @@ function getOfferSynchronizedCartDataForCalculation({ data, syncContext, }) {
|
|
|
972
972
|
clearOrderLevelDiscount('loyalty');
|
|
973
973
|
}
|
|
974
974
|
else {
|
|
975
|
-
const hasRelevantCap = is_discount_percentage &&
|
|
976
|
-
max_discount_amount != null &&
|
|
977
|
-
Number.isFinite(max_discount_amount) &&
|
|
978
|
-
max_discount_amount >= 0;
|
|
979
975
|
const hasRelevantPercentageCap = !is_discount_percentage &&
|
|
980
976
|
max_discount_percentage != null &&
|
|
981
977
|
Number.isFinite(max_discount_percentage) &&
|
|
982
978
|
max_discount_percentage >= 0;
|
|
983
|
-
const
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
979
|
+
const hasMaxAmountCap = is_discount_percentage &&
|
|
980
|
+
max_discount_amount != null &&
|
|
981
|
+
Number.isFinite(max_discount_amount) &&
|
|
982
|
+
max_discount_amount >= 0;
|
|
983
|
+
const hasFlatMaxPercentage = !is_discount_percentage && hasRelevantPercentageCap;
|
|
984
|
+
if (hasExcludedRefs && !is_discount_percentage && !hasFlatMaxPercentage) {
|
|
985
|
+
clearOrderLevelDiscount('loyalty');
|
|
986
|
+
}
|
|
987
|
+
else if (hasExcludedRefs) {
|
|
988
|
+
// Excluded items present: must apply percentage against eligible subtotal only.
|
|
989
|
+
const eligibleBase = hasFlatMaxPercentage
|
|
990
|
+
? (0, utils_1.parseNum)((0, utils_1.getNetItemsValueAfterItemDiscount)({
|
|
991
|
+
itemsPrice: eligibleSubtotal,
|
|
992
|
+
totalDiscountApplied: 0,
|
|
993
|
+
orderLevelDiscount: 0,
|
|
994
|
+
}))
|
|
995
|
+
: eligibleSubtotal;
|
|
996
|
+
if (eligibleBase <= 0) {
|
|
987
997
|
clearOrderLevelDiscount('loyalty');
|
|
988
998
|
}
|
|
989
999
|
else {
|
|
990
1000
|
const calculatedDiscount = (0, utils_1.getCappedOfferDiscountAmount)({
|
|
991
|
-
baseAmount:
|
|
1001
|
+
baseAmount: eligibleBase,
|
|
992
1002
|
discountValue: discount_value,
|
|
993
1003
|
isDiscountPercentage: is_discount_percentage,
|
|
994
1004
|
maxDiscountAmount: max_discount_amount,
|
|
@@ -1002,6 +1012,67 @@ function getOfferSynchronizedCartDataForCalculation({ data, syncContext, }) {
|
|
|
1002
1012
|
hasChanges = true;
|
|
1003
1013
|
}
|
|
1004
1014
|
}
|
|
1015
|
+
else if (hasMaxAmountCap) {
|
|
1016
|
+
// Percentage offer with max_amount cap (no excluded items).
|
|
1017
|
+
const projectedPercentage = (0, utils_1.getPercentageAmount)(orderLevelDiscountBaseAmount, discount_value);
|
|
1018
|
+
if (projectedPercentage > max_discount_amount) {
|
|
1019
|
+
// Cap would be breached -- normalize to flat at cap.
|
|
1020
|
+
order_discount_details = {
|
|
1021
|
+
...order_discount_details,
|
|
1022
|
+
loyalty_discount: (0, utils_1.parseNum)(max_discount_amount),
|
|
1023
|
+
is_loyalty_discount_percentage: false,
|
|
1024
|
+
};
|
|
1025
|
+
}
|
|
1026
|
+
else {
|
|
1027
|
+
// Cap not breached -- un-cap back to percentage (or stay percentage).
|
|
1028
|
+
order_discount_details = {
|
|
1029
|
+
...order_discount_details,
|
|
1030
|
+
loyalty_discount: (0, utils_1.parseNum)(discount_value),
|
|
1031
|
+
is_loyalty_discount_percentage: true,
|
|
1032
|
+
};
|
|
1033
|
+
}
|
|
1034
|
+
hasChanges = true;
|
|
1035
|
+
}
|
|
1036
|
+
else if (hasFlatMaxPercentage) {
|
|
1037
|
+
// Flat discount with max_percentage cap -- resolve against full cart.
|
|
1038
|
+
if (orderLevelDiscountBaseAmount <= 0) {
|
|
1039
|
+
clearOrderLevelDiscount('loyalty');
|
|
1040
|
+
}
|
|
1041
|
+
else {
|
|
1042
|
+
const calculatedDiscount = (0, utils_1.getCappedOfferDiscountAmount)({
|
|
1043
|
+
baseAmount: orderLevelDiscountBaseAmount,
|
|
1044
|
+
discountValue: discount_value,
|
|
1045
|
+
isDiscountPercentage: false,
|
|
1046
|
+
maxDiscountAmount: undefined,
|
|
1047
|
+
maxDiscountPercentage: max_discount_percentage,
|
|
1048
|
+
});
|
|
1049
|
+
order_discount_details = {
|
|
1050
|
+
...order_discount_details,
|
|
1051
|
+
loyalty_discount: (0, utils_1.parseNum)(calculatedDiscount),
|
|
1052
|
+
is_loyalty_discount_percentage: false,
|
|
1053
|
+
};
|
|
1054
|
+
hasChanges = true;
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
else if (is_discount_percentage) {
|
|
1058
|
+
// Plain percentage offer, no excluded items, no caps.
|
|
1059
|
+
const shouldRevert = order_discount_details.is_loyalty_discount_percentage === false &&
|
|
1060
|
+
order_discount_details.loyalty_discount != null;
|
|
1061
|
+
if (shouldRevert) {
|
|
1062
|
+
order_discount_details = {
|
|
1063
|
+
...order_discount_details,
|
|
1064
|
+
loyalty_discount: (0, utils_1.parseNum)(discount_value),
|
|
1065
|
+
is_loyalty_discount_percentage: true,
|
|
1066
|
+
};
|
|
1067
|
+
hasChanges = true;
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
else {
|
|
1071
|
+
// Plain flat offer, no caps -- keep as-is.
|
|
1072
|
+
if (orderLevelDiscountBaseAmount <= 0) {
|
|
1073
|
+
clearOrderLevelDiscount('loyalty');
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1005
1076
|
}
|
|
1006
1077
|
}
|
|
1007
1078
|
unlockedOffersMap[loyaltyDiscountId] -= 1;
|
|
@@ -1032,39 +1103,103 @@ function getOfferSynchronizedCartDataForCalculation({ data, syncContext, }) {
|
|
|
1032
1103
|
subtotal: orderLevelDiscountBaseAmount,
|
|
1033
1104
|
hasExcludedRefs: false,
|
|
1034
1105
|
};
|
|
1035
|
-
|
|
1106
|
+
const hasRelevantPercentageCap = !is_discount_percentage &&
|
|
1107
|
+
max_discount_percentage != null &&
|
|
1108
|
+
Number.isFinite(max_discount_percentage) &&
|
|
1109
|
+
max_discount_percentage >= 0;
|
|
1110
|
+
const hasMaxAmountCap = is_discount_percentage &&
|
|
1111
|
+
max_discount_amount != null &&
|
|
1112
|
+
Number.isFinite(max_discount_amount) &&
|
|
1113
|
+
max_discount_amount >= 0;
|
|
1114
|
+
const hasFlatMaxPercentage = !is_discount_percentage && hasRelevantPercentageCap;
|
|
1115
|
+
if (hasExcludedRefs && !is_discount_percentage && !hasFlatMaxPercentage) {
|
|
1036
1116
|
clearOrderLevelDiscount('voucher');
|
|
1037
1117
|
}
|
|
1118
|
+
else if (hasExcludedRefs) {
|
|
1119
|
+
// Excluded items present: must apply percentage against eligible subtotal only.
|
|
1120
|
+
const eligibleBase = hasFlatMaxPercentage
|
|
1121
|
+
? (0, utils_1.parseNum)((0, utils_1.getNetItemsValueAfterItemDiscount)({
|
|
1122
|
+
itemsPrice: eligibleSubtotal,
|
|
1123
|
+
totalDiscountApplied: 0,
|
|
1124
|
+
orderLevelDiscount: 0,
|
|
1125
|
+
}))
|
|
1126
|
+
: eligibleSubtotal;
|
|
1127
|
+
if (eligibleBase <= 0) {
|
|
1128
|
+
clearOrderLevelDiscount('voucher');
|
|
1129
|
+
}
|
|
1130
|
+
else {
|
|
1131
|
+
const calculatedDiscount = (0, utils_1.getCappedOfferDiscountAmount)({
|
|
1132
|
+
baseAmount: eligibleBase,
|
|
1133
|
+
discountValue: discount_value,
|
|
1134
|
+
isDiscountPercentage: is_discount_percentage,
|
|
1135
|
+
maxDiscountAmount: max_discount_amount,
|
|
1136
|
+
maxDiscountPercentage: max_discount_percentage,
|
|
1137
|
+
});
|
|
1138
|
+
order_discount_details = {
|
|
1139
|
+
...order_discount_details,
|
|
1140
|
+
voucher_discount: (0, utils_1.parseNum)(calculatedDiscount),
|
|
1141
|
+
is_voucher_discount_percentage: false,
|
|
1142
|
+
};
|
|
1143
|
+
hasChanges = true;
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
else if (hasMaxAmountCap) {
|
|
1147
|
+
// Percentage offer with max_amount cap (no excluded items).
|
|
1148
|
+
const projectedPercentage = (0, utils_1.getPercentageAmount)(orderLevelDiscountBaseAmount, discount_value);
|
|
1149
|
+
if (projectedPercentage > max_discount_amount) {
|
|
1150
|
+
// Cap would be breached -- normalize to flat at cap.
|
|
1151
|
+
order_discount_details = {
|
|
1152
|
+
...order_discount_details,
|
|
1153
|
+
voucher_discount: (0, utils_1.parseNum)(max_discount_amount),
|
|
1154
|
+
is_voucher_discount_percentage: false,
|
|
1155
|
+
};
|
|
1156
|
+
}
|
|
1157
|
+
else {
|
|
1158
|
+
// Cap not breached -- un-cap back to percentage (or stay percentage).
|
|
1159
|
+
order_discount_details = {
|
|
1160
|
+
...order_discount_details,
|
|
1161
|
+
voucher_discount: (0, utils_1.parseNum)(discount_value),
|
|
1162
|
+
is_voucher_discount_percentage: true,
|
|
1163
|
+
};
|
|
1164
|
+
}
|
|
1165
|
+
hasChanges = true;
|
|
1166
|
+
}
|
|
1167
|
+
else if (hasFlatMaxPercentage) {
|
|
1168
|
+
if (orderLevelDiscountBaseAmount <= 0) {
|
|
1169
|
+
clearOrderLevelDiscount('voucher');
|
|
1170
|
+
}
|
|
1171
|
+
else {
|
|
1172
|
+
const calculatedDiscount = (0, utils_1.getCappedOfferDiscountAmount)({
|
|
1173
|
+
baseAmount: orderLevelDiscountBaseAmount,
|
|
1174
|
+
discountValue: discount_value,
|
|
1175
|
+
isDiscountPercentage: false,
|
|
1176
|
+
maxDiscountAmount: undefined,
|
|
1177
|
+
maxDiscountPercentage: max_discount_percentage,
|
|
1178
|
+
});
|
|
1179
|
+
order_discount_details = {
|
|
1180
|
+
...order_discount_details,
|
|
1181
|
+
voucher_discount: (0, utils_1.parseNum)(calculatedDiscount),
|
|
1182
|
+
is_voucher_discount_percentage: false,
|
|
1183
|
+
};
|
|
1184
|
+
hasChanges = true;
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
else if (is_discount_percentage) {
|
|
1188
|
+
// Plain percentage offer, no excluded items, no caps.
|
|
1189
|
+
const shouldRevert = order_discount_details.is_voucher_discount_percentage === false &&
|
|
1190
|
+
order_discount_details.voucher_discount != null;
|
|
1191
|
+
if (shouldRevert) {
|
|
1192
|
+
order_discount_details = {
|
|
1193
|
+
...order_discount_details,
|
|
1194
|
+
voucher_discount: (0, utils_1.parseNum)(discount_value),
|
|
1195
|
+
is_voucher_discount_percentage: true,
|
|
1196
|
+
};
|
|
1197
|
+
hasChanges = true;
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1038
1200
|
else {
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
Number.isFinite(max_discount_amount) &&
|
|
1042
|
-
max_discount_amount >= 0;
|
|
1043
|
-
const hasRelevantPercentageCap = !is_discount_percentage &&
|
|
1044
|
-
max_discount_percentage != null &&
|
|
1045
|
-
Number.isFinite(max_discount_percentage) &&
|
|
1046
|
-
max_discount_percentage >= 0;
|
|
1047
|
-
const shouldNormalizeToStatic = hasExcludedRefs || hasRelevantCap || hasRelevantPercentageCap;
|
|
1048
|
-
const discountBaseAmount = hasExcludedRefs ? eligibleSubtotal : orderLevelDiscountBaseAmount;
|
|
1049
|
-
if (shouldNormalizeToStatic) {
|
|
1050
|
-
if (discountBaseAmount <= 0) {
|
|
1051
|
-
clearOrderLevelDiscount('voucher');
|
|
1052
|
-
}
|
|
1053
|
-
else {
|
|
1054
|
-
const calculatedDiscount = (0, utils_1.getCappedOfferDiscountAmount)({
|
|
1055
|
-
baseAmount: discountBaseAmount,
|
|
1056
|
-
discountValue: discount_value,
|
|
1057
|
-
isDiscountPercentage: is_discount_percentage,
|
|
1058
|
-
maxDiscountAmount: max_discount_amount,
|
|
1059
|
-
maxDiscountPercentage: max_discount_percentage,
|
|
1060
|
-
});
|
|
1061
|
-
order_discount_details = {
|
|
1062
|
-
...order_discount_details,
|
|
1063
|
-
voucher_discount: (0, utils_1.parseNum)(calculatedDiscount),
|
|
1064
|
-
is_voucher_discount_percentage: false,
|
|
1065
|
-
};
|
|
1066
|
-
hasChanges = true;
|
|
1067
|
-
}
|
|
1201
|
+
if (orderLevelDiscountBaseAmount <= 0) {
|
|
1202
|
+
clearOrderLevelDiscount('voucher');
|
|
1068
1203
|
}
|
|
1069
1204
|
}
|
|
1070
1205
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ICategory, IIncludedCategory, IItem, IKitchenInventory } from '../../schemas';
|
|
2
|
-
import { ICatalog, IMinifiedCategory, IMinifiedItem, ISimplifiedCatalog, ISimplifiedCatalogItem, ISimplifiedCategory, ISimplifiedItem, IWarehouseCatalog } from '../types';
|
|
1
|
+
import { ICategory, IIncludedCategory, IInventoryCategory, IItem, IKitchenInventory } from '../../schemas';
|
|
2
|
+
import { ICatalog, IInventoryCategoryWithItems, IInventoryIncludedCategory, IMinifiedCategory, IMinifiedItem, ISimplifiedCatalog, ISimplifiedCatalogItem, ISimplifiedCategory, ISimplifiedItem, IWarehouseCatalog } from '../types';
|
|
3
3
|
export declare function getPartialSimplifiedItem(item: Partial<ISimplifiedItem>): Partial<ISimplifiedCatalogItem>;
|
|
4
4
|
export declare function getSimplifiedItemWithPrice(item: ISimplifiedItem): ISimplifiedCatalogItem;
|
|
5
5
|
export declare function getSimpleCatalogFetchedData(categories: ISimplifiedCategory[], items: ISimplifiedItem[]): ISimplifiedCatalog[];
|
|
@@ -36,4 +36,10 @@ export declare function getInventoryMappedItems(inventory: IKitchenInventory[]):
|
|
|
36
36
|
*
|
|
37
37
|
* When includedCategories is empty, returns ALL items (no filter).
|
|
38
38
|
*/
|
|
39
|
-
export declare function getSelectedVendorInventoryItems(mappedInventory: Record<string, IKitchenInventory[]>, includedCategories:
|
|
39
|
+
export declare function getSelectedVendorInventoryItems(mappedInventory: Record<string, IKitchenInventory[]>, includedCategories: IInventoryIncludedCategory[]): IKitchenInventory[];
|
|
40
|
+
/**
|
|
41
|
+
* Group inventory categories with their items, including a synthetic
|
|
42
|
+
* "Uncategorized" entry for items without a category_id.
|
|
43
|
+
* Mirrors getWarehouseCatalogFetchedData for the admin panel.
|
|
44
|
+
*/
|
|
45
|
+
export declare function getGroupedInventoryCategories(categories: IInventoryCategory[], items: IKitchenInventory[]): IInventoryCategoryWithItems[];
|
|
@@ -17,6 +17,7 @@ exports.getSelectedCatalogs = getSelectedCatalogs;
|
|
|
17
17
|
exports.getSelectedVendorCatalogs = getSelectedVendorCatalogs;
|
|
18
18
|
exports.getInventoryMappedItems = getInventoryMappedItems;
|
|
19
19
|
exports.getSelectedVendorInventoryItems = getSelectedVendorInventoryItems;
|
|
20
|
+
exports.getGroupedInventoryCategories = getGroupedInventoryCategories;
|
|
20
21
|
const utils_1 = require("../utils");
|
|
21
22
|
const catalog_conversion_1 = require("../utils/catalog-conversion");
|
|
22
23
|
const minified_catalog_1 = require("../utils/minified-catalog");
|
|
@@ -282,3 +283,56 @@ function getSelectedVendorInventoryItems(mappedInventory, includedCategories) {
|
|
|
282
283
|
}
|
|
283
284
|
return result;
|
|
284
285
|
}
|
|
286
|
+
// ============================================================================
|
|
287
|
+
// Admin Panel: Group inventory categories with their items (incl. uncategorized)
|
|
288
|
+
// Mirrors getWarehouseCatalogFetchedData but for IInventoryCategory/IKitchenInventory.
|
|
289
|
+
// ============================================================================
|
|
290
|
+
/**
|
|
291
|
+
* Group inventory categories with their items, including a synthetic
|
|
292
|
+
* "Uncategorized" entry for items without a category_id.
|
|
293
|
+
* Mirrors getWarehouseCatalogFetchedData for the admin panel.
|
|
294
|
+
*/
|
|
295
|
+
function getGroupedInventoryCategories(categories, items) {
|
|
296
|
+
const result = [];
|
|
297
|
+
// Group items by category_id
|
|
298
|
+
const itemsByCategory = {};
|
|
299
|
+
const uncategorizedItems = [];
|
|
300
|
+
for (let i = 0; i < items.length; i++) {
|
|
301
|
+
const item = items[i];
|
|
302
|
+
if (item.category_id) {
|
|
303
|
+
if (!itemsByCategory[item.category_id])
|
|
304
|
+
itemsByCategory[item.category_id] = [];
|
|
305
|
+
itemsByCategory[item.category_id].push(item);
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
uncategorizedItems.push(item);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
// Add each category with its items, sorted by category sort_id
|
|
312
|
+
const sortedCategories = [...categories].sort((a, b) => a.sort_id - b.sort_id);
|
|
313
|
+
for (const cat of sortedCategories) {
|
|
314
|
+
result.push({
|
|
315
|
+
category: cat,
|
|
316
|
+
items: itemsByCategory[cat.ref_id] || [],
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
// Append uncategorized items as a synthetic category (ref_id: null so the API receives null, not a fake string)
|
|
320
|
+
if (uncategorizedItems.length > 0) {
|
|
321
|
+
const maxSortId = categories.length > 0 ? Math.max(...categories.map((c) => c.sort_id)) : 0;
|
|
322
|
+
result.push({
|
|
323
|
+
category: {
|
|
324
|
+
_id: null,
|
|
325
|
+
ref_id: null,
|
|
326
|
+
tenant_id: '',
|
|
327
|
+
name: 'Uncategorized',
|
|
328
|
+
subtitle: '',
|
|
329
|
+
active: true,
|
|
330
|
+
sort_id: maxSortId + 1,
|
|
331
|
+
createdAt: new Date(0),
|
|
332
|
+
updatedAt: new Date(0),
|
|
333
|
+
},
|
|
334
|
+
items: uncategorizedItems,
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
return result;
|
|
338
|
+
}
|
|
@@ -12,6 +12,7 @@ export * from './hubrise_deliveries';
|
|
|
12
12
|
export * from './hubrise_location';
|
|
13
13
|
export * from './hubrise_orders';
|
|
14
14
|
export * from './internal-leads';
|
|
15
|
+
export * from './inventory-catalog';
|
|
15
16
|
export * from './kpra-generate-invoice';
|
|
16
17
|
export * from './marketing';
|
|
17
18
|
export * from './order-engine';
|
|
@@ -28,6 +28,7 @@ __exportStar(require("./hubrise_deliveries"), exports);
|
|
|
28
28
|
__exportStar(require("./hubrise_location"), exports);
|
|
29
29
|
__exportStar(require("./hubrise_orders"), exports);
|
|
30
30
|
__exportStar(require("./internal-leads"), exports);
|
|
31
|
+
__exportStar(require("./inventory-catalog"), exports);
|
|
31
32
|
__exportStar(require("./kpra-generate-invoice"), exports);
|
|
32
33
|
__exportStar(require("./marketing"), exports);
|
|
33
34
|
__exportStar(require("./order-engine"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { IInventoryCategory, IKitchenInventory } from '../../schemas';
|
|
2
|
+
/**
|
|
3
|
+
* Included category entry for the admin panel's vendor inventory context.
|
|
4
|
+
* Allows null category_id for uncategorized items, unlike IIncludedCategory
|
|
5
|
+
* (which uses category_id: string for courses/menus).
|
|
6
|
+
*/
|
|
7
|
+
export interface IInventoryIncludedCategory {
|
|
8
|
+
category_id: string | null;
|
|
9
|
+
excluded_items: string[];
|
|
10
|
+
}
|
|
11
|
+
export type IInventoryCategoryDisplay = Omit<IInventoryCategory, '_id' | 'ref_id'> & {
|
|
12
|
+
_id: string | null;
|
|
13
|
+
ref_id: string | null;
|
|
14
|
+
};
|
|
15
|
+
export interface IInventoryCategoryWithItems {
|
|
16
|
+
category: IInventoryCategoryDisplay;
|
|
17
|
+
items: IKitchenInventory[];
|
|
18
|
+
}
|
|
@@ -1050,24 +1050,29 @@ function getOrderSubtotalFromCategoriesForOfferStats(categories) {
|
|
|
1050
1050
|
if (categories == null)
|
|
1051
1051
|
return null;
|
|
1052
1052
|
let subtotal = 0;
|
|
1053
|
+
let itemsCount = 0;
|
|
1053
1054
|
for (let i = 0; i < categories.length; i++) {
|
|
1054
1055
|
const items = categories[i].items;
|
|
1055
1056
|
for (let j = 0; j < items.length; j++) {
|
|
1056
1057
|
subtotal += getPositiveAmount(items[j].subtotal);
|
|
1058
|
+
itemsCount += Math.max(0, Math.floor(items[j].quantity ?? 0));
|
|
1057
1059
|
}
|
|
1058
1060
|
}
|
|
1059
|
-
return (0, common_1.parseNum)(subtotal);
|
|
1061
|
+
return { subtotal: (0, common_1.parseNum)(subtotal), itemsCount };
|
|
1060
1062
|
}
|
|
1061
1063
|
function getOrderLevelDiscountBaseAmountForOfferStats({ categories, itemsPrice, totalDiscountApplied, orderDiscountDetails, }) {
|
|
1062
|
-
const
|
|
1063
|
-
if (
|
|
1064
|
-
return
|
|
1064
|
+
const categoriesResult = getOrderSubtotalFromCategoriesForOfferStats(categories);
|
|
1065
|
+
if (categoriesResult != null) {
|
|
1066
|
+
return { baseAmount: categoriesResult.subtotal, itemsCount: categoriesResult.itemsCount };
|
|
1065
1067
|
}
|
|
1066
|
-
return
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1068
|
+
return {
|
|
1069
|
+
baseAmount: getNetItemsValueAfterItemDiscount({
|
|
1070
|
+
itemsPrice,
|
|
1071
|
+
totalDiscountApplied,
|
|
1072
|
+
orderLevelDiscount: orderDiscountDetails?.total_discount,
|
|
1073
|
+
}),
|
|
1074
|
+
itemsCount: 0,
|
|
1075
|
+
};
|
|
1071
1076
|
}
|
|
1072
1077
|
function getOrderLevelDiscountAmountForOfferStats({ orderDiscountDetails, orderLevelDiscountBaseAmount, }) {
|
|
1073
1078
|
return (0, common_1.parseNum)(Math.min(getPositiveAmount(orderDiscountDetails?.total_discount), getPositiveAmount(orderLevelDiscountBaseAmount)));
|
|
@@ -1494,13 +1499,14 @@ function getRewardPreviewHashKey(rewardPreview) {
|
|
|
1494
1499
|
// Failing to do so will cause the frontend (OffersProvider) to miss state changes —
|
|
1495
1500
|
// it compares hash key strings to decide whether to update React state / dispatch Redux actions.
|
|
1496
1501
|
// The same rule applies to getUnlockedOffersApplicableTimesHashKey and getRewardPreviewHashKey.
|
|
1497
|
-
function getOffersWithStatsHashKey(offersWithStats, totalClaimableOffers, isEdit) {
|
|
1502
|
+
function getOffersWithStatsHashKey({ offersWithStats, totalClaimableOffers, isEdit, itemsCount, itemsPrice, }) {
|
|
1498
1503
|
const editSegment = isEdit ? 'edit:' : '';
|
|
1504
|
+
const cartSegment = `c:${itemsCount ?? 0}:${itemsPrice ?? 0}`;
|
|
1499
1505
|
if (offersWithStats.length === 0) {
|
|
1500
|
-
return `offers:v1:${editSegment}empty:${totalClaimableOffers.length}`;
|
|
1506
|
+
return `offers:v1:${editSegment}${cartSegment}:empty:${totalClaimableOffers.length}`;
|
|
1501
1507
|
}
|
|
1502
1508
|
const sortedOffers = [...offersWithStats].sort((a, b) => a.offer._id.localeCompare(b.offer._id));
|
|
1503
|
-
let result = `offers:v1:${editSegment}${totalClaimableOffers.length}|`;
|
|
1509
|
+
let result = `offers:v1:${editSegment}${cartSegment}:${totalClaimableOffers.length}|`;
|
|
1504
1510
|
for (let i = 0; i < sortedOffers.length; i++) {
|
|
1505
1511
|
const { offer, stats } = sortedOffers[i];
|
|
1506
1512
|
const eligibleItemIds = [...stats.eligible_item_ids].sort().join(',');
|
|
@@ -1512,7 +1518,7 @@ function getOffersWithStatsHashKey(offersWithStats, totalClaimableOffers, isEdit
|
|
|
1512
1518
|
}
|
|
1513
1519
|
function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOfferRedemptionCounts, redeemed_offers, platform, currency_symbol, currentItemsPrice, totalDiscountApplied, categories, order_discount_details, isEdit, }) {
|
|
1514
1520
|
const offersWithStats = [];
|
|
1515
|
-
const orderLevelDiscountBaseAmount = getOrderLevelDiscountBaseAmountForOfferStats({
|
|
1521
|
+
const { baseAmount: orderLevelDiscountBaseAmount, itemsCount } = getOrderLevelDiscountBaseAmountForOfferStats({
|
|
1516
1522
|
categories,
|
|
1517
1523
|
itemsPrice: currentItemsPrice,
|
|
1518
1524
|
totalDiscountApplied,
|
|
@@ -3029,7 +3035,13 @@ function getOffersWithStats({ offers, customer, vouchers, giftCards, customerOff
|
|
|
3029
3035
|
offersWithStats,
|
|
3030
3036
|
totalClaimableOffers,
|
|
3031
3037
|
unlockedOffersApplicableTimes,
|
|
3032
|
-
offersWithStatsHashKey: getOffersWithStatsHashKey(
|
|
3038
|
+
offersWithStatsHashKey: getOffersWithStatsHashKey({
|
|
3039
|
+
offersWithStats,
|
|
3040
|
+
totalClaimableOffers,
|
|
3041
|
+
isEdit,
|
|
3042
|
+
itemsCount,
|
|
3043
|
+
itemsPrice: currentItemsPrice,
|
|
3044
|
+
}),
|
|
3033
3045
|
unlockedOffersApplicableTimesHashKey: getUnlockedOffersApplicableTimesHashKey(unlockedOffersApplicableTimes, isEdit),
|
|
3034
3046
|
};
|
|
3035
3047
|
}
|