@managesome/eposmatic-toolkit 0.2.710 → 0.2.713
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/types/catalog.d.ts +1 -0
- package/lib/helpers/utils/catalog-conversion.d.ts +1 -1
- package/lib/helpers/utils/catalog-conversion.js +4 -2
- package/lib/helpers/utils/minified-catalog.js +2 -0
- package/lib/helpers/utils/order-engine.d.ts +13 -0
- package/lib/helpers/utils/order-engine.js +56 -5
- package/lib/helpers/utils/platform-num.d.ts +1 -1
- package/lib/helpers/utils/platform-num.js +40 -22
- package/lib/helpers/utils/receipt-engine.js +15 -8
- package/lib/helpers/utils/specials-helpers.js +5 -0
- package/lib/schemas/models/halfhalf_setup.d.ts +3 -3
- package/lib/schemas/models/items.d.ts +27 -0
- package/lib/schemas/models/items.js +4 -0
- package/lib/schemas/types/items.d.ts +1 -0
- package/lib/tests/nested-halfhalf-segment-price.test.d.ts +1 -0
- package/lib/tests/nested-halfhalf-segment-price.test.js +224 -0
- package/lib/tests/receipt-engine.test.js +1 -1
- package/lib/tests/specials-halfhalf-options.test.js +2 -1
- package/package.json +1 -1
|
@@ -34,6 +34,7 @@ export interface IMinifiedModifierOption {
|
|
|
34
34
|
item_modifier_option_special_hours?: IMinifiedItemSpecialHour[] | null;
|
|
35
35
|
modifiers?: IMinifiedModifier[] | null;
|
|
36
36
|
ref_type?: MODIFIER_OPTION_REF_TYPE_ENUM;
|
|
37
|
+
choose_expensive_segment_price?: boolean;
|
|
37
38
|
_id: string;
|
|
38
39
|
ref: string;
|
|
39
40
|
name: string;
|
|
@@ -4,7 +4,7 @@ export declare function getModifierOptionMultiplier(multiplier: number | null |
|
|
|
4
4
|
export declare function convertModifiersPriceFromCentsAndSort(modifiers: IModifier[] | null | undefined, removeNonActive?: boolean): IModifier[] | null;
|
|
5
5
|
export declare function convertModifierExtrasPriceToCents(modifierExtra: Partial<IModifierExtra>): Partial<IModifierExtra>;
|
|
6
6
|
export declare function convertModifierExtrasPriceFromCents(modifier: IModifierExtra): IModifierExtra;
|
|
7
|
-
export declare function getPartialItemWithCents<T extends Partial<IItem>>(item: T): T;
|
|
7
|
+
export declare function getPartialItemWithCents<T extends Partial<IItem>>(item: T, removeItemBasedOptionFields?: boolean): T;
|
|
8
8
|
export declare function getItemWithCents<T extends IItem>(item: T): T;
|
|
9
9
|
export declare function getSortedPartialItemWithPrice<T extends Partial<IItem>>(item: T): T;
|
|
10
10
|
export declare function getSortedItemWithPrice<T extends IItem>(item: T): T;
|
|
@@ -70,14 +70,16 @@ function convertModifierExtrasPriceFromCents(modifier) {
|
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
72
|
// =========================>>>><<<<============================
|
|
73
|
-
function getPartialItemWithCents(item) {
|
|
73
|
+
function getPartialItemWithCents(item, removeItemBasedOptionFields) {
|
|
74
74
|
return {
|
|
75
75
|
...item,
|
|
76
76
|
...(item.display_price != undefined ? { display_price: (0, price_conversion_1.convertPriceToCents)(item.display_price) } : {}),
|
|
77
77
|
...(item.price !== undefined ? { price: (0, platform_num_1.convertPriceObjToCents)(item.price) } : {}),
|
|
78
78
|
...(item.discount_amount !== undefined ? { discount_amount: (0, platform_num_1.convertPriceObjToCents)(item.discount_amount) } : {}),
|
|
79
79
|
...(item.tax_rate !== undefined ? { tax_rate: (0, platform_num_1.convertPriceObjToCents)(item.tax_rate) } : {}),
|
|
80
|
-
...(item.modifiers !== undefined
|
|
80
|
+
...(item.modifiers !== undefined
|
|
81
|
+
? { modifiers: (0, platform_num_1.convertModifiersPriceToCents)(item.modifiers, removeItemBasedOptionFields) }
|
|
82
|
+
: {}),
|
|
81
83
|
...(item.item_special_hours !== undefined
|
|
82
84
|
? { item_special_hours: (0, platform_num_1.convertSpecialHoursToCents)(item.item_special_hours) }
|
|
83
85
|
: {}),
|
|
@@ -88,6 +88,7 @@ function convertMinifiedModifierOptionsToOriginalModifierOptions(options, tenant
|
|
|
88
88
|
ingredients,
|
|
89
89
|
item_modifier_option_special_hours,
|
|
90
90
|
ref_type: option.ref_type,
|
|
91
|
+
choose_expensive_segment_price: option.choose_expensive_segment_price,
|
|
91
92
|
// required properties
|
|
92
93
|
_id,
|
|
93
94
|
ref,
|
|
@@ -280,6 +281,7 @@ function convertOriginalModifierOptionsToMinifiedModifierOptions(options, tenant
|
|
|
280
281
|
item_modifier_option_special_hours,
|
|
281
282
|
modifiers,
|
|
282
283
|
ref_type: option.ref_type,
|
|
284
|
+
choose_expensive_segment_price: option.choose_expensive_segment_price,
|
|
283
285
|
// required properties
|
|
284
286
|
_id: option._id,
|
|
285
287
|
ref: option.ref,
|
|
@@ -39,6 +39,19 @@ export declare function makeSpaceForFreeOptions(options: IOrderEngineOption[], n
|
|
|
39
39
|
* Returns the item unchanged when no segment option is selected.
|
|
40
40
|
*/
|
|
41
41
|
export declare function applyChooseExpensiveSegmentPrice(orderEngineItem: IOrderEngineItem): IOrderEngineItem;
|
|
42
|
+
/**
|
|
43
|
+
* True when the item has a top-level modifier group option that is a nested
|
|
44
|
+
* half-half (ref_type HALF_HALF) with its setup's choose_expensive flag.
|
|
45
|
+
*/
|
|
46
|
+
export declare function hasFlaggedHalfHalfOption(orderEngineItem: IOrderEngineItem): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* `choose_expensive_segment_price` for a half-half option nested in a special:
|
|
49
|
+
* the option's own top-level modifiers are its segment groups, so they get the
|
|
50
|
+
* same raise-to-most-expensive treatment as a standalone half-half item.
|
|
51
|
+
* ITEM options are terminal (their nested modifiers can never contain
|
|
52
|
+
* ITEM/HALF_HALF); normal options pass untouched. Idempotent (only raises).
|
|
53
|
+
*/
|
|
54
|
+
export declare function applyNestedChooseExpensiveSegmentPrice(orderEngineItem: IOrderEngineItem): IOrderEngineItem;
|
|
42
55
|
export type IOrderEngineItemRewardClaim = {
|
|
43
56
|
type: 'offer';
|
|
44
57
|
offerId: string;
|
|
@@ -8,6 +8,8 @@ exports.syncOrderEngineItem = syncOrderEngineItem;
|
|
|
8
8
|
exports.checkIfModifiersExist = checkIfModifiersExist;
|
|
9
9
|
exports.makeSpaceForFreeOptions = makeSpaceForFreeOptions;
|
|
10
10
|
exports.applyChooseExpensiveSegmentPrice = applyChooseExpensiveSegmentPrice;
|
|
11
|
+
exports.hasFlaggedHalfHalfOption = hasFlaggedHalfHalfOption;
|
|
12
|
+
exports.applyNestedChooseExpensiveSegmentPrice = applyNestedChooseExpensiveSegmentPrice;
|
|
11
13
|
exports.convertOrderEngineItemToOrderItem = convertOrderEngineItemToOrderItem;
|
|
12
14
|
exports.convertItemDiscountToOrderItemDiscount = convertItemDiscountToOrderItemDiscount;
|
|
13
15
|
exports.convertCatalogItemToOrderEngineItem = convertCatalogItemToOrderEngineItem;
|
|
@@ -320,6 +322,23 @@ function applyChooseExpensiveSegmentPrice(orderEngineItem) {
|
|
|
320
322
|
const segmentGroups = (orderEngineItem.modifiers ?? []).filter((modifier) => modifier.depth === 0);
|
|
321
323
|
if (segmentGroups.length < 2)
|
|
322
324
|
return orderEngineItem;
|
|
325
|
+
const raised = applyChooseExpensiveSegmentPriceToModifiers(segmentGroups);
|
|
326
|
+
if (raised == null)
|
|
327
|
+
return orderEngineItem;
|
|
328
|
+
let segmentGroupIndex = 0;
|
|
329
|
+
const modifiers = (orderEngineItem.modifiers ?? []).map((modifier) => modifier.depth !== 0 ? modifier : raised[segmentGroupIndex++]);
|
|
330
|
+
return syncOrderEngineItem({ ...orderEngineItem, modifiers });
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Core `choose_expensive_segment_price` normalization over a list of segment
|
|
334
|
+
* groups (single-select: one option per group). Used for standalone HALF_HALF
|
|
335
|
+
* items (top-level segments) and for a HALF_HALF option nested in a special
|
|
336
|
+
* (the option's own modifiers).
|
|
337
|
+
*
|
|
338
|
+
* Returns null when nothing needs to change (no selected option / no priced
|
|
339
|
+
* segment), otherwise the raised segment groups.
|
|
340
|
+
*/
|
|
341
|
+
function applyChooseExpensiveSegmentPriceToModifiers(segmentGroups) {
|
|
323
342
|
// Prices of ALL options of required (price-defining) modifier groups, at
|
|
324
343
|
// any depth — e.g. "Pizza Size" -> "Large 13"" is part of the item's price
|
|
325
344
|
// whichever size is picked (mirrors `getSegmentItemTotalPrice` used by the
|
|
@@ -359,7 +378,7 @@ function applyChooseExpensiveSegmentPrice(orderEngineItem) {
|
|
|
359
378
|
}
|
|
360
379
|
}
|
|
361
380
|
if (maxSegmentValue <= 0)
|
|
362
|
-
return
|
|
381
|
+
return null;
|
|
363
382
|
// One selected option per segment group (segments are single-select).
|
|
364
383
|
const selections = [];
|
|
365
384
|
for (let g = 0; g < segmentGroups.length; g++) {
|
|
@@ -373,7 +392,7 @@ function applyChooseExpensiveSegmentPrice(orderEngineItem) {
|
|
|
373
392
|
}
|
|
374
393
|
}
|
|
375
394
|
if (selections.length === 0)
|
|
376
|
-
return
|
|
395
|
+
return null;
|
|
377
396
|
// RULE for where the raise lands: on the FIRST PRICED element along the
|
|
378
397
|
// segment's price chain —
|
|
379
398
|
// 1. the segment option's own price (the item base) when it is non-zero
|
|
@@ -413,9 +432,7 @@ function applyChooseExpensiveSegmentPrice(orderEngineItem) {
|
|
|
413
432
|
})),
|
|
414
433
|
};
|
|
415
434
|
};
|
|
416
|
-
|
|
417
|
-
if (modifier.depth !== 0)
|
|
418
|
-
return modifier;
|
|
435
|
+
return segmentGroups.map((modifier, g) => {
|
|
419
436
|
const options = (modifier.options ?? []).map((option, o) => {
|
|
420
437
|
const selection = selections.find((s) => s.groupIndex === g && s.optionIndex === o);
|
|
421
438
|
if (selection == null)
|
|
@@ -432,6 +449,35 @@ function applyChooseExpensiveSegmentPrice(orderEngineItem) {
|
|
|
432
449
|
});
|
|
433
450
|
return { ...modifier, options };
|
|
434
451
|
});
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* True when the item has a top-level modifier group option that is a nested
|
|
455
|
+
* half-half (ref_type HALF_HALF) with its setup's choose_expensive flag.
|
|
456
|
+
*/
|
|
457
|
+
function hasFlaggedHalfHalfOption(orderEngineItem) {
|
|
458
|
+
return (orderEngineItem.modifiers ?? []).some((modifier) => (modifier.options ?? []).some((option) => option.ref_type === constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.HALF_HALF && option.choose_expensive_segment_price === true));
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* `choose_expensive_segment_price` for a half-half option nested in a special:
|
|
462
|
+
* the option's own top-level modifiers are its segment groups, so they get the
|
|
463
|
+
* same raise-to-most-expensive treatment as a standalone half-half item.
|
|
464
|
+
* ITEM options are terminal (their nested modifiers can never contain
|
|
465
|
+
* ITEM/HALF_HALF); normal options pass untouched. Idempotent (only raises).
|
|
466
|
+
*/
|
|
467
|
+
function applyNestedChooseExpensiveSegmentPrice(orderEngineItem) {
|
|
468
|
+
const modifiers = (orderEngineItem.modifiers ?? []).map((modifier) => ({
|
|
469
|
+
...modifier,
|
|
470
|
+
options: (modifier.options ?? []).map((option) => {
|
|
471
|
+
if (option.ref_type !== constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.HALF_HALF ||
|
|
472
|
+
option.choose_expensive_segment_price !== true) {
|
|
473
|
+
return option;
|
|
474
|
+
}
|
|
475
|
+
const raised = applyChooseExpensiveSegmentPriceToModifiers(option.modifiers ?? []);
|
|
476
|
+
if (raised == null)
|
|
477
|
+
return option;
|
|
478
|
+
return { ...option, modifiers: raised };
|
|
479
|
+
}),
|
|
480
|
+
}));
|
|
435
481
|
return syncOrderEngineItem({ ...orderEngineItem, modifiers });
|
|
436
482
|
}
|
|
437
483
|
function convertCatalogItemModifierToOrderEngineItemModifier({ modifiers, orderItemModifiers, platform, tenantId, excludeRefs, zeroPriceRefs, loyaltyRefs, voucherRefs, keepOptionalModifiersAtBottom, soldoutModifiers, depth = 0, }) {
|
|
@@ -991,6 +1037,11 @@ function setCheckFieldInOrderEngineItem(orderEngineItem, identifier, shouldCheck
|
|
|
991
1037
|
if (orderEngineItem.item_type === constants_1.ORDER_ITEM_TYPE_ENUM.HALF_HALF && chooseExpensiveSegmentPrice === true) {
|
|
992
1038
|
return applyChooseExpensiveSegmentPrice(updatedOrderEngineItem);
|
|
993
1039
|
}
|
|
1040
|
+
// Half-half option nested in a special: normalize its own segment groups
|
|
1041
|
+
// (the option's top-level modifiers) whenever it carries the setup flag.
|
|
1042
|
+
if (orderEngineItem.item_type === constants_1.ORDER_ITEM_TYPE_ENUM.SPECIAL && hasFlaggedHalfHalfOption(updatedOrderEngineItem)) {
|
|
1043
|
+
return applyNestedChooseExpensiveSegmentPrice(updatedOrderEngineItem);
|
|
1044
|
+
}
|
|
994
1045
|
return updatedOrderEngineItem;
|
|
995
1046
|
}
|
|
996
1047
|
function setIncrementOrderEngineItemQuantity(orderEngineItem, increment) {
|
|
@@ -14,7 +14,7 @@ export declare function convertMinifiedPriceToCents(price: IMinifiedPrice | unde
|
|
|
14
14
|
export declare function convertMinifiedPriceFromCents(price: IMinifiedPrice | undefined): IMinifiedPrice | undefined;
|
|
15
15
|
export declare function mergePriceObjs(priceObj1: IPrice | null, priceObj2: IPrice | null): IPrice | null;
|
|
16
16
|
export declare function convertPriceObjToSegmentPrice(priceObj: IPrice | null, segments: number): IPrice | null;
|
|
17
|
-
export declare function convertModifiersPriceToCents(modifiers: IModifier[] | null | undefined): IModifier[] | null;
|
|
17
|
+
export declare function convertModifiersPriceToCents(modifiers: IModifier[] | null | undefined, removeItemBasedOptionFields?: boolean): IModifier[] | null;
|
|
18
18
|
export declare function convertSpecialHoursToCents(specialHours: IItemSpecialHour[] | null | undefined): IItemSpecialHour[] | null;
|
|
19
19
|
export declare function convertSpecialHoursFromCents(specialHours: IItemSpecialHour[] | null | undefined): IItemSpecialHour[] | null;
|
|
20
20
|
/**
|
|
@@ -109,30 +109,48 @@ function convertPriceObjToSegmentPrice(priceObj, segments) {
|
|
|
109
109
|
return segmentedPrice;
|
|
110
110
|
}
|
|
111
111
|
// ====================================================================================================
|
|
112
|
-
function convertModifiersPriceToCents(modifiers) {
|
|
112
|
+
function convertModifiersPriceToCents(modifiers, removeItemBasedOptionFields) {
|
|
113
113
|
if (!modifiers || modifiers.length === 0)
|
|
114
114
|
return null;
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
115
|
+
const newModifiers = [];
|
|
116
|
+
for (let i = 0; i < modifiers.length; i++) {
|
|
117
|
+
const modifier = modifiers[i];
|
|
118
|
+
const newOptions = [];
|
|
119
|
+
for (let j = 0; j < modifier.options.length; j++) {
|
|
120
|
+
const option = modifier.options[j];
|
|
121
|
+
const newOption = {
|
|
122
|
+
...option,
|
|
123
|
+
price: convertPriceObjToCents(option.price) ?? undefined,
|
|
124
|
+
multiplier: (0, catalog_conversion_1.getModifierOptionMultiplier)(option.multiplier, true),
|
|
125
|
+
modifiers: convertModifiersPriceToCents(option.modifiers, removeItemBasedOptionFields) ?? undefined,
|
|
126
|
+
default: option.default || undefined,
|
|
127
|
+
ingredients: (0, ingredients_1.getIngredientsWithInt)(option.ingredients) ?? undefined,
|
|
128
|
+
item_modifier_option_special_hours: convertSpecialHoursToCents(option.item_modifier_option_special_hours) ?? undefined,
|
|
129
|
+
};
|
|
130
|
+
if (removeItemBasedOptionFields) {
|
|
131
|
+
delete newOption.ref_type;
|
|
132
|
+
delete newOption.choose_expensive_segment_price;
|
|
133
|
+
}
|
|
134
|
+
newOptions.push(newOption);
|
|
135
|
+
}
|
|
136
|
+
if (newOptions.length === 0)
|
|
137
|
+
continue;
|
|
138
|
+
const newModifier = {
|
|
139
|
+
...modifier,
|
|
140
|
+
options: newOptions,
|
|
141
|
+
min_num_options: modifier.min_num_options ?? undefined,
|
|
142
|
+
max_num_options: modifier.max_num_options ?? undefined,
|
|
143
|
+
min_option_choice_quantity: modifier.min_option_choice_quantity ?? undefined,
|
|
144
|
+
max_option_choice_quantity: modifier.max_option_choice_quantity ?? undefined,
|
|
145
|
+
min_aggregate_options_quantity: modifier.min_aggregate_options_quantity ?? undefined,
|
|
146
|
+
max_aggregate_options_quantity: modifier.max_aggregate_options_quantity ?? undefined,
|
|
147
|
+
num_free_options: modifier.num_free_options ?? undefined,
|
|
148
|
+
exempt_discount: modifier.exempt_discount || undefined,
|
|
149
|
+
minimized: modifier.minimized || undefined,
|
|
150
|
+
};
|
|
151
|
+
newModifiers.push(newModifier);
|
|
152
|
+
}
|
|
153
|
+
return newModifiers;
|
|
136
154
|
}
|
|
137
155
|
function convertSpecialHoursToCents(specialHours) {
|
|
138
156
|
if (!specialHours || specialHours.length === 0)
|
|
@@ -501,18 +501,25 @@ function getTrimmedCompositeModifiers(modifiers, includedItemIds) {
|
|
|
501
501
|
keptOptions.push(option);
|
|
502
502
|
continue;
|
|
503
503
|
}
|
|
504
|
-
// ITEM
|
|
505
|
-
//
|
|
506
|
-
|
|
507
|
-
continue;
|
|
508
|
-
// An ITEM option can never contain nested item-like options, so it is
|
|
509
|
-
// kept as-is (no recursion).
|
|
504
|
+
// An ITEM option is a real menu product: keep it only when the product
|
|
505
|
+
// is part of the partial menu. ITEM options can never contain nested
|
|
506
|
+
// item-like options, so they are kept as-is (no recursion).
|
|
510
507
|
if (option.ref_type === constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.ITEM) {
|
|
508
|
+
if (!includedItemIds.has(option.ref))
|
|
509
|
+
continue;
|
|
510
|
+
keptOptions.push(option);
|
|
511
|
+
continue;
|
|
512
|
+
}
|
|
513
|
+
// A HALF_HALF option's ref is the half-half SETUP id — never a catalog
|
|
514
|
+
// item id, so it is not present in `includedItemIds` (which is built
|
|
515
|
+
// from catalog items only). Its survival is decided by its own segment
|
|
516
|
+
// groups (options with ref_type ITEM): recurse into them; drop the
|
|
517
|
+
// option only when nothing printable is left. Also keep it when the
|
|
518
|
+
// setup id is explicitly included (e.g. the whole setup is selected).
|
|
519
|
+
if (includedItemIds.has(option.ref)) {
|
|
511
520
|
keptOptions.push(option);
|
|
512
521
|
continue;
|
|
513
522
|
}
|
|
514
|
-
// A HALF_HALF option holds its own segment modifier groups, whose
|
|
515
|
-
// options are ITEM refs - recurse into them for filtering.
|
|
516
523
|
const nestedModifiers = option.modifiers != null ? getTrimmedCompositeModifiers(option.modifiers, includedItemIds) : null;
|
|
517
524
|
// A HALF_HALF option that had constituent parts but none survived the
|
|
518
525
|
// filter has nothing printable left -> drop it as well.
|
|
@@ -443,6 +443,7 @@ function convertSpecialToItem(special, itemsMap, halfhalfSetups) {
|
|
|
443
443
|
// regular catalog item: convert it to an IItem (each segment becomes a
|
|
444
444
|
// nested single-select modifier) so it flows like any other option.
|
|
445
445
|
let isHalfHalfOption = false;
|
|
446
|
+
let halfHalfChooseExpensive = false;
|
|
446
447
|
if (catalogItem == null && halfhalfSetups != null) {
|
|
447
448
|
const halfhalfSetup = halfhalfSetups[specialItem.item_id];
|
|
448
449
|
if (halfhalfSetup != null) {
|
|
@@ -450,6 +451,7 @@ function convertSpecialToItem(special, itemsMap, halfhalfSetups) {
|
|
|
450
451
|
if (halfhalfItem != null) {
|
|
451
452
|
catalogItem = halfhalfItem;
|
|
452
453
|
isHalfHalfOption = true;
|
|
454
|
+
halfHalfChooseExpensive = halfhalfSetup.choose_expensive_segment_price === true;
|
|
453
455
|
}
|
|
454
456
|
}
|
|
455
457
|
}
|
|
@@ -483,6 +485,9 @@ function convertSpecialToItem(special, itemsMap, halfhalfSetups) {
|
|
|
483
485
|
// This option IS a menu item (or a half-half) — carry its kind so
|
|
484
486
|
// downstream order items can tell item/half-half options apart.
|
|
485
487
|
ref_type: isHalfHalfOption ? constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.HALF_HALF : constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.ITEM,
|
|
488
|
+
// Only on a nested half-half: the setup flag so the engine normalizes
|
|
489
|
+
// the option's own segment groups at selection time.
|
|
490
|
+
...(isHalfHalfOption && halfHalfChooseExpensive ? { choose_expensive_segment_price: true } : {}),
|
|
486
491
|
// Derived from the source item's included platforms (pure mapping),
|
|
487
492
|
// so platform availability can be applied by the filter layer downstream.
|
|
488
493
|
excluded_platforms: (0, platform_catalog_1.getExcludedPlatformsFromIncludedPlatforms)(catalogItem.included_platforms),
|
|
@@ -220,6 +220,7 @@ export declare const HalfHalfSetupSchema: Schema<any, import("mongoose").Model<a
|
|
|
220
220
|
description: string;
|
|
221
221
|
is_discount_percentage: boolean;
|
|
222
222
|
sold_out: string[];
|
|
223
|
+
choose_expensive_segment_price: boolean;
|
|
223
224
|
included_platforms: import("../..").PLATFORMS_ENUM[];
|
|
224
225
|
item_special_hours: import("mongoose").Types.DocumentArray<{
|
|
225
226
|
days_index: import("../..").DAY_INDEX_ENUM[];
|
|
@@ -565,7 +566,6 @@ export declare const HalfHalfSetupSchema: Schema<any, import("mongoose").Model<a
|
|
|
565
566
|
name: string;
|
|
566
567
|
sort_id: number;
|
|
567
568
|
}>;
|
|
568
|
-
choose_expensive_segment_price: boolean;
|
|
569
569
|
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
|
|
570
570
|
createdAt: NativeDate;
|
|
571
571
|
updatedAt: NativeDate;
|
|
@@ -764,6 +764,7 @@ export declare const HalfHalfSetupSchema: Schema<any, import("mongoose").Model<a
|
|
|
764
764
|
description: string;
|
|
765
765
|
is_discount_percentage: boolean;
|
|
766
766
|
sold_out: string[];
|
|
767
|
+
choose_expensive_segment_price: boolean;
|
|
767
768
|
included_platforms: import("../..").PLATFORMS_ENUM[];
|
|
768
769
|
item_special_hours: import("mongoose").Types.DocumentArray<{
|
|
769
770
|
days_index: import("../..").DAY_INDEX_ENUM[];
|
|
@@ -1109,7 +1110,6 @@ export declare const HalfHalfSetupSchema: Schema<any, import("mongoose").Model<a
|
|
|
1109
1110
|
name: string;
|
|
1110
1111
|
sort_id: number;
|
|
1111
1112
|
}>;
|
|
1112
|
-
choose_expensive_segment_price: boolean;
|
|
1113
1113
|
}>> & import("mongoose").FlatRecord<{
|
|
1114
1114
|
createdAt: NativeDate;
|
|
1115
1115
|
updatedAt: NativeDate;
|
|
@@ -1308,6 +1308,7 @@ export declare const HalfHalfSetupSchema: Schema<any, import("mongoose").Model<a
|
|
|
1308
1308
|
description: string;
|
|
1309
1309
|
is_discount_percentage: boolean;
|
|
1310
1310
|
sold_out: string[];
|
|
1311
|
+
choose_expensive_segment_price: boolean;
|
|
1311
1312
|
included_platforms: import("../..").PLATFORMS_ENUM[];
|
|
1312
1313
|
item_special_hours: import("mongoose").Types.DocumentArray<{
|
|
1313
1314
|
days_index: import("../..").DAY_INDEX_ENUM[];
|
|
@@ -1653,7 +1654,6 @@ export declare const HalfHalfSetupSchema: Schema<any, import("mongoose").Model<a
|
|
|
1653
1654
|
name: string;
|
|
1654
1655
|
sort_id: number;
|
|
1655
1656
|
}>;
|
|
1656
|
-
choose_expensive_segment_price: boolean;
|
|
1657
1657
|
}> & Required<{
|
|
1658
1658
|
_id: import("mongoose").Types.ObjectId;
|
|
1659
1659
|
}> & {
|
|
@@ -1131,6 +1131,7 @@ export declare const ItemSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
1131
1131
|
} | null | undefined;
|
|
1132
1132
|
}> | null | undefined;
|
|
1133
1133
|
ref_type?: import("../../constants").MODIFIER_OPTION_REF_TYPE_ENUM | null | undefined;
|
|
1134
|
+
choose_expensive_segment_price?: boolean | null | undefined;
|
|
1134
1135
|
}, import("mongoose").Types.Subdocument<string, any, {
|
|
1135
1136
|
_id: string;
|
|
1136
1137
|
name: string;
|
|
@@ -1484,6 +1485,7 @@ export declare const ItemSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
1484
1485
|
} | null | undefined;
|
|
1485
1486
|
}> | null | undefined;
|
|
1486
1487
|
ref_type?: import("../../constants").MODIFIER_OPTION_REF_TYPE_ENUM | null | undefined;
|
|
1488
|
+
choose_expensive_segment_price?: boolean | null | undefined;
|
|
1487
1489
|
}> & {
|
|
1488
1490
|
_id: string;
|
|
1489
1491
|
name: string;
|
|
@@ -1837,6 +1839,7 @@ export declare const ItemSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
1837
1839
|
} | null | undefined;
|
|
1838
1840
|
}> | null | undefined;
|
|
1839
1841
|
ref_type?: import("../../constants").MODIFIER_OPTION_REF_TYPE_ENUM | null | undefined;
|
|
1842
|
+
choose_expensive_segment_price?: boolean | null | undefined;
|
|
1840
1843
|
}>;
|
|
1841
1844
|
min_num_options?: number | null | undefined;
|
|
1842
1845
|
max_num_options?: number | null | undefined;
|
|
@@ -2208,6 +2211,7 @@ export declare const ItemSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
2208
2211
|
} | null | undefined;
|
|
2209
2212
|
}> | null | undefined;
|
|
2210
2213
|
ref_type?: import("../../constants").MODIFIER_OPTION_REF_TYPE_ENUM | null | undefined;
|
|
2214
|
+
choose_expensive_segment_price?: boolean | null | undefined;
|
|
2211
2215
|
}, import("mongoose").Types.Subdocument<string, any, {
|
|
2212
2216
|
_id: string;
|
|
2213
2217
|
name: string;
|
|
@@ -2561,6 +2565,7 @@ export declare const ItemSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
2561
2565
|
} | null | undefined;
|
|
2562
2566
|
}> | null | undefined;
|
|
2563
2567
|
ref_type?: import("../../constants").MODIFIER_OPTION_REF_TYPE_ENUM | null | undefined;
|
|
2568
|
+
choose_expensive_segment_price?: boolean | null | undefined;
|
|
2564
2569
|
}> & {
|
|
2565
2570
|
_id: string;
|
|
2566
2571
|
name: string;
|
|
@@ -2914,6 +2919,7 @@ export declare const ItemSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
2914
2919
|
} | null | undefined;
|
|
2915
2920
|
}> | null | undefined;
|
|
2916
2921
|
ref_type?: import("../../constants").MODIFIER_OPTION_REF_TYPE_ENUM | null | undefined;
|
|
2922
|
+
choose_expensive_segment_price?: boolean | null | undefined;
|
|
2917
2923
|
}>;
|
|
2918
2924
|
min_num_options?: number | null | undefined;
|
|
2919
2925
|
max_num_options?: number | null | undefined;
|
|
@@ -3285,6 +3291,7 @@ export declare const ItemSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
3285
3291
|
} | null | undefined;
|
|
3286
3292
|
}> | null | undefined;
|
|
3287
3293
|
ref_type?: import("../../constants").MODIFIER_OPTION_REF_TYPE_ENUM | null | undefined;
|
|
3294
|
+
choose_expensive_segment_price?: boolean | null | undefined;
|
|
3288
3295
|
}, import("mongoose").Types.Subdocument<string, any, {
|
|
3289
3296
|
_id: string;
|
|
3290
3297
|
name: string;
|
|
@@ -3638,6 +3645,7 @@ export declare const ItemSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
3638
3645
|
} | null | undefined;
|
|
3639
3646
|
}> | null | undefined;
|
|
3640
3647
|
ref_type?: import("../../constants").MODIFIER_OPTION_REF_TYPE_ENUM | null | undefined;
|
|
3648
|
+
choose_expensive_segment_price?: boolean | null | undefined;
|
|
3641
3649
|
}> & {
|
|
3642
3650
|
_id: string;
|
|
3643
3651
|
name: string;
|
|
@@ -3991,6 +3999,7 @@ export declare const ItemSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
3991
3999
|
} | null | undefined;
|
|
3992
4000
|
}> | null | undefined;
|
|
3993
4001
|
ref_type?: import("../../constants").MODIFIER_OPTION_REF_TYPE_ENUM | null | undefined;
|
|
4002
|
+
choose_expensive_segment_price?: boolean | null | undefined;
|
|
3994
4003
|
}>;
|
|
3995
4004
|
min_num_options?: number | null | undefined;
|
|
3996
4005
|
max_num_options?: number | null | undefined;
|
|
@@ -4818,6 +4827,7 @@ export declare const ItemSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
4818
4827
|
} | null | undefined;
|
|
4819
4828
|
}> | null | undefined;
|
|
4820
4829
|
ref_type?: import("../../constants").MODIFIER_OPTION_REF_TYPE_ENUM | null | undefined;
|
|
4830
|
+
choose_expensive_segment_price?: boolean | null | undefined;
|
|
4821
4831
|
}, import("mongoose").Types.Subdocument<string, any, {
|
|
4822
4832
|
_id: string;
|
|
4823
4833
|
name: string;
|
|
@@ -5171,6 +5181,7 @@ export declare const ItemSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
5171
5181
|
} | null | undefined;
|
|
5172
5182
|
}> | null | undefined;
|
|
5173
5183
|
ref_type?: import("../../constants").MODIFIER_OPTION_REF_TYPE_ENUM | null | undefined;
|
|
5184
|
+
choose_expensive_segment_price?: boolean | null | undefined;
|
|
5174
5185
|
}> & {
|
|
5175
5186
|
_id: string;
|
|
5176
5187
|
name: string;
|
|
@@ -5524,6 +5535,7 @@ export declare const ItemSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
5524
5535
|
} | null | undefined;
|
|
5525
5536
|
}> | null | undefined;
|
|
5526
5537
|
ref_type?: import("../../constants").MODIFIER_OPTION_REF_TYPE_ENUM | null | undefined;
|
|
5538
|
+
choose_expensive_segment_price?: boolean | null | undefined;
|
|
5527
5539
|
}>;
|
|
5528
5540
|
min_num_options?: number | null | undefined;
|
|
5529
5541
|
max_num_options?: number | null | undefined;
|
|
@@ -5895,6 +5907,7 @@ export declare const ItemSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
5895
5907
|
} | null | undefined;
|
|
5896
5908
|
}> | null | undefined;
|
|
5897
5909
|
ref_type?: import("../../constants").MODIFIER_OPTION_REF_TYPE_ENUM | null | undefined;
|
|
5910
|
+
choose_expensive_segment_price?: boolean | null | undefined;
|
|
5898
5911
|
}, import("mongoose").Types.Subdocument<string, any, {
|
|
5899
5912
|
_id: string;
|
|
5900
5913
|
name: string;
|
|
@@ -6248,6 +6261,7 @@ export declare const ItemSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
6248
6261
|
} | null | undefined;
|
|
6249
6262
|
}> | null | undefined;
|
|
6250
6263
|
ref_type?: import("../../constants").MODIFIER_OPTION_REF_TYPE_ENUM | null | undefined;
|
|
6264
|
+
choose_expensive_segment_price?: boolean | null | undefined;
|
|
6251
6265
|
}> & {
|
|
6252
6266
|
_id: string;
|
|
6253
6267
|
name: string;
|
|
@@ -6601,6 +6615,7 @@ export declare const ItemSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
6601
6615
|
} | null | undefined;
|
|
6602
6616
|
}> | null | undefined;
|
|
6603
6617
|
ref_type?: import("../../constants").MODIFIER_OPTION_REF_TYPE_ENUM | null | undefined;
|
|
6618
|
+
choose_expensive_segment_price?: boolean | null | undefined;
|
|
6604
6619
|
}>;
|
|
6605
6620
|
min_num_options?: number | null | undefined;
|
|
6606
6621
|
max_num_options?: number | null | undefined;
|
|
@@ -6972,6 +6987,7 @@ export declare const ItemSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
6972
6987
|
} | null | undefined;
|
|
6973
6988
|
}> | null | undefined;
|
|
6974
6989
|
ref_type?: import("../../constants").MODIFIER_OPTION_REF_TYPE_ENUM | null | undefined;
|
|
6990
|
+
choose_expensive_segment_price?: boolean | null | undefined;
|
|
6975
6991
|
}, import("mongoose").Types.Subdocument<string, any, {
|
|
6976
6992
|
_id: string;
|
|
6977
6993
|
name: string;
|
|
@@ -7325,6 +7341,7 @@ export declare const ItemSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
7325
7341
|
} | null | undefined;
|
|
7326
7342
|
}> | null | undefined;
|
|
7327
7343
|
ref_type?: import("../../constants").MODIFIER_OPTION_REF_TYPE_ENUM | null | undefined;
|
|
7344
|
+
choose_expensive_segment_price?: boolean | null | undefined;
|
|
7328
7345
|
}> & {
|
|
7329
7346
|
_id: string;
|
|
7330
7347
|
name: string;
|
|
@@ -7678,6 +7695,7 @@ export declare const ItemSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
7678
7695
|
} | null | undefined;
|
|
7679
7696
|
}> | null | undefined;
|
|
7680
7697
|
ref_type?: import("../../constants").MODIFIER_OPTION_REF_TYPE_ENUM | null | undefined;
|
|
7698
|
+
choose_expensive_segment_price?: boolean | null | undefined;
|
|
7681
7699
|
}>;
|
|
7682
7700
|
min_num_options?: number | null | undefined;
|
|
7683
7701
|
max_num_options?: number | null | undefined;
|
|
@@ -8505,6 +8523,7 @@ export declare const ItemSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
8505
8523
|
} | null | undefined;
|
|
8506
8524
|
}> | null | undefined;
|
|
8507
8525
|
ref_type?: import("../../constants").MODIFIER_OPTION_REF_TYPE_ENUM | null | undefined;
|
|
8526
|
+
choose_expensive_segment_price?: boolean | null | undefined;
|
|
8508
8527
|
}, import("mongoose").Types.Subdocument<string, any, {
|
|
8509
8528
|
_id: string;
|
|
8510
8529
|
name: string;
|
|
@@ -8858,6 +8877,7 @@ export declare const ItemSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
8858
8877
|
} | null | undefined;
|
|
8859
8878
|
}> | null | undefined;
|
|
8860
8879
|
ref_type?: import("../../constants").MODIFIER_OPTION_REF_TYPE_ENUM | null | undefined;
|
|
8880
|
+
choose_expensive_segment_price?: boolean | null | undefined;
|
|
8861
8881
|
}> & {
|
|
8862
8882
|
_id: string;
|
|
8863
8883
|
name: string;
|
|
@@ -9211,6 +9231,7 @@ export declare const ItemSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
9211
9231
|
} | null | undefined;
|
|
9212
9232
|
}> | null | undefined;
|
|
9213
9233
|
ref_type?: import("../../constants").MODIFIER_OPTION_REF_TYPE_ENUM | null | undefined;
|
|
9234
|
+
choose_expensive_segment_price?: boolean | null | undefined;
|
|
9214
9235
|
}>;
|
|
9215
9236
|
min_num_options?: number | null | undefined;
|
|
9216
9237
|
max_num_options?: number | null | undefined;
|
|
@@ -9582,6 +9603,7 @@ export declare const ItemSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
9582
9603
|
} | null | undefined;
|
|
9583
9604
|
}> | null | undefined;
|
|
9584
9605
|
ref_type?: import("../../constants").MODIFIER_OPTION_REF_TYPE_ENUM | null | undefined;
|
|
9606
|
+
choose_expensive_segment_price?: boolean | null | undefined;
|
|
9585
9607
|
}, import("mongoose").Types.Subdocument<string, any, {
|
|
9586
9608
|
_id: string;
|
|
9587
9609
|
name: string;
|
|
@@ -9935,6 +9957,7 @@ export declare const ItemSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
9935
9957
|
} | null | undefined;
|
|
9936
9958
|
}> | null | undefined;
|
|
9937
9959
|
ref_type?: import("../../constants").MODIFIER_OPTION_REF_TYPE_ENUM | null | undefined;
|
|
9960
|
+
choose_expensive_segment_price?: boolean | null | undefined;
|
|
9938
9961
|
}> & {
|
|
9939
9962
|
_id: string;
|
|
9940
9963
|
name: string;
|
|
@@ -10288,6 +10311,7 @@ export declare const ItemSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
10288
10311
|
} | null | undefined;
|
|
10289
10312
|
}> | null | undefined;
|
|
10290
10313
|
ref_type?: import("../../constants").MODIFIER_OPTION_REF_TYPE_ENUM | null | undefined;
|
|
10314
|
+
choose_expensive_segment_price?: boolean | null | undefined;
|
|
10291
10315
|
}>;
|
|
10292
10316
|
min_num_options?: number | null | undefined;
|
|
10293
10317
|
max_num_options?: number | null | undefined;
|
|
@@ -10659,6 +10683,7 @@ export declare const ItemSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
10659
10683
|
} | null | undefined;
|
|
10660
10684
|
}> | null | undefined;
|
|
10661
10685
|
ref_type?: import("../../constants").MODIFIER_OPTION_REF_TYPE_ENUM | null | undefined;
|
|
10686
|
+
choose_expensive_segment_price?: boolean | null | undefined;
|
|
10662
10687
|
}, import("mongoose").Types.Subdocument<string, any, {
|
|
10663
10688
|
_id: string;
|
|
10664
10689
|
name: string;
|
|
@@ -11012,6 +11037,7 @@ export declare const ItemSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
11012
11037
|
} | null | undefined;
|
|
11013
11038
|
}> | null | undefined;
|
|
11014
11039
|
ref_type?: import("../../constants").MODIFIER_OPTION_REF_TYPE_ENUM | null | undefined;
|
|
11040
|
+
choose_expensive_segment_price?: boolean | null | undefined;
|
|
11015
11041
|
}> & {
|
|
11016
11042
|
_id: string;
|
|
11017
11043
|
name: string;
|
|
@@ -11365,6 +11391,7 @@ export declare const ItemSchema: Schema<any, import("mongoose").Model<any, any,
|
|
|
11365
11391
|
} | null | undefined;
|
|
11366
11392
|
}> | null | undefined;
|
|
11367
11393
|
ref_type?: import("../../constants").MODIFIER_OPTION_REF_TYPE_ENUM | null | undefined;
|
|
11394
|
+
choose_expensive_segment_price?: boolean | null | undefined;
|
|
11368
11395
|
}>;
|
|
11369
11396
|
min_num_options?: number | null | undefined;
|
|
11370
11397
|
max_num_options?: number | null | undefined;
|
|
@@ -129,6 +129,10 @@ const OptionSchema = new mongoose_1.Schema({
|
|
|
129
129
|
type: String,
|
|
130
130
|
enum: constants_1.ALL_MODIFIER_OPTION_REF_TYPES,
|
|
131
131
|
required: false,
|
|
132
|
+
}, // Only set on a HALF_HALF option nested in a special (its setup flag).
|
|
133
|
+
choose_expensive_segment_price: {
|
|
134
|
+
type: Boolean,
|
|
135
|
+
required: false,
|
|
132
136
|
},
|
|
133
137
|
});
|
|
134
138
|
const ModifiersSchema = new mongoose_1.Schema({
|
|
@@ -34,6 +34,7 @@ export interface IModifierOption {
|
|
|
34
34
|
ingredients?: IIngredient[] | null;
|
|
35
35
|
item_modifier_option_special_hours?: IItemSpecialHour[] | null;
|
|
36
36
|
ref_type?: MODIFIER_OPTION_REF_TYPE_ENUM;
|
|
37
|
+
choose_expensive_segment_price?: boolean;
|
|
37
38
|
}
|
|
38
39
|
export interface IItem {
|
|
39
40
|
_id: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const constants_1 = require("../constants");
|
|
4
|
+
const order_engine_1 = require("../helpers/utils/order-engine");
|
|
5
|
+
function makeEngineOption(overrides = {}) {
|
|
6
|
+
return {
|
|
7
|
+
_id: 'opt-1',
|
|
8
|
+
ref: 'opt-1',
|
|
9
|
+
name: 'Option',
|
|
10
|
+
active: true,
|
|
11
|
+
sold_out: [],
|
|
12
|
+
sort_id: 1,
|
|
13
|
+
excluded_platforms: [],
|
|
14
|
+
default: false,
|
|
15
|
+
price: 0,
|
|
16
|
+
quantity: 1,
|
|
17
|
+
modifiers: [],
|
|
18
|
+
is_free: false,
|
|
19
|
+
loyalty_applied: false,
|
|
20
|
+
voucher_applied: false,
|
|
21
|
+
...overrides,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function makeEngineModifier(overrides = {}) {
|
|
25
|
+
return {
|
|
26
|
+
_id: 'mod-1',
|
|
27
|
+
ref: 'mod-1',
|
|
28
|
+
name: 'Modifier',
|
|
29
|
+
description: '',
|
|
30
|
+
active: true,
|
|
31
|
+
sold_out: [],
|
|
32
|
+
sort_id: 1,
|
|
33
|
+
min_num_options: 1,
|
|
34
|
+
max_num_options: 1,
|
|
35
|
+
depth: 1,
|
|
36
|
+
default: false,
|
|
37
|
+
options: [],
|
|
38
|
+
...overrides,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function makeEngineItem(overrides = {}) {
|
|
42
|
+
return {
|
|
43
|
+
_id: 'item-1',
|
|
44
|
+
category_id: 'cat-1',
|
|
45
|
+
item_id: 'special-1',
|
|
46
|
+
menu_id: 'menu-1',
|
|
47
|
+
item_type: constants_1.ORDER_ITEM_TYPE_ENUM.SPECIAL,
|
|
48
|
+
name: 'Buy 1 Pizza Get 1 Free',
|
|
49
|
+
description: 'Deal',
|
|
50
|
+
loyalty_applied: false,
|
|
51
|
+
voucher_applied: false,
|
|
52
|
+
price: 1500,
|
|
53
|
+
gross_total: 0,
|
|
54
|
+
subtotal: 0,
|
|
55
|
+
tax_rate: 0,
|
|
56
|
+
quantity: 1,
|
|
57
|
+
image_url: '',
|
|
58
|
+
special_instructions: '',
|
|
59
|
+
item_discount_details: null,
|
|
60
|
+
modifiers: [],
|
|
61
|
+
...overrides,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/** Two single-select segment groups (the half-half's segments), max = 600. */
|
|
65
|
+
function makeSegmentGroups() {
|
|
66
|
+
return [
|
|
67
|
+
makeEngineModifier({
|
|
68
|
+
_id: 'seg-1',
|
|
69
|
+
name: 'First Pizza',
|
|
70
|
+
depth: 1,
|
|
71
|
+
options: [
|
|
72
|
+
makeEngineOption({ _id: 'milan', ref: 'milan', price: 500, default: true }),
|
|
73
|
+
makeEngineOption({ _id: 'torent', ref: 'torent', price: 600 }),
|
|
74
|
+
],
|
|
75
|
+
}),
|
|
76
|
+
makeEngineModifier({
|
|
77
|
+
_id: 'seg-2',
|
|
78
|
+
name: 'Second Pizza',
|
|
79
|
+
depth: 1,
|
|
80
|
+
options: [
|
|
81
|
+
makeEngineOption({ _id: 'milan2', ref: 'milan', price: 500 }),
|
|
82
|
+
makeEngineOption({ _id: 'torent2', ref: 'torent', price: 600, default: true }),
|
|
83
|
+
],
|
|
84
|
+
}),
|
|
85
|
+
];
|
|
86
|
+
}
|
|
87
|
+
describe('hasFlaggedHalfHalfOption', () => {
|
|
88
|
+
it('detects a top-level group option with ref_type HALF_HALF + flag', () => {
|
|
89
|
+
const item = makeEngineItem({
|
|
90
|
+
modifiers: [
|
|
91
|
+
makeEngineModifier({
|
|
92
|
+
depth: 0,
|
|
93
|
+
options: [
|
|
94
|
+
makeEngineOption({
|
|
95
|
+
_id: 'halfhalf-1',
|
|
96
|
+
ref: 'halfhalf-1',
|
|
97
|
+
ref_type: constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.HALF_HALF,
|
|
98
|
+
choose_expensive_segment_price: true,
|
|
99
|
+
}),
|
|
100
|
+
],
|
|
101
|
+
}),
|
|
102
|
+
],
|
|
103
|
+
});
|
|
104
|
+
expect((0, order_engine_1.hasFlaggedHalfHalfOption)(item)).toBe(true);
|
|
105
|
+
});
|
|
106
|
+
it('is false for flagged-off half-half, ITEM and normal options', () => {
|
|
107
|
+
const item = makeEngineItem({
|
|
108
|
+
modifiers: [
|
|
109
|
+
makeEngineModifier({
|
|
110
|
+
depth: 0,
|
|
111
|
+
options: [
|
|
112
|
+
makeEngineOption({
|
|
113
|
+
_id: 'halfhalf-1',
|
|
114
|
+
ref: 'halfhalf-1',
|
|
115
|
+
ref_type: constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.HALF_HALF,
|
|
116
|
+
choose_expensive_segment_price: false,
|
|
117
|
+
}),
|
|
118
|
+
makeEngineOption({
|
|
119
|
+
_id: 'milan',
|
|
120
|
+
ref: 'milan',
|
|
121
|
+
ref_type: constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.ITEM,
|
|
122
|
+
choose_expensive_segment_price: true,
|
|
123
|
+
}),
|
|
124
|
+
makeEngineOption({ _id: 'normal', ref: 'normal', default: true }),
|
|
125
|
+
],
|
|
126
|
+
}),
|
|
127
|
+
],
|
|
128
|
+
});
|
|
129
|
+
expect((0, order_engine_1.hasFlaggedHalfHalfOption)(item)).toBe(false);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
describe('applyNestedChooseExpensiveSegmentPrice (half-half inside a special)', () => {
|
|
133
|
+
it('raises the selected cheap segment option to the most expensive one', () => {
|
|
134
|
+
const item = makeEngineItem({
|
|
135
|
+
modifiers: [
|
|
136
|
+
makeEngineModifier({
|
|
137
|
+
_id: 'first-pizza',
|
|
138
|
+
name: 'First Pizza',
|
|
139
|
+
depth: 0,
|
|
140
|
+
options: [
|
|
141
|
+
makeEngineOption({
|
|
142
|
+
_id: 'milan',
|
|
143
|
+
ref: 'milan',
|
|
144
|
+
ref_type: constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.ITEM,
|
|
145
|
+
price: 0,
|
|
146
|
+
default: true,
|
|
147
|
+
}),
|
|
148
|
+
makeEngineOption({
|
|
149
|
+
_id: 'halfhalf-1',
|
|
150
|
+
ref: 'halfhalf-1',
|
|
151
|
+
ref_type: constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.HALF_HALF,
|
|
152
|
+
choose_expensive_segment_price: true,
|
|
153
|
+
default: true,
|
|
154
|
+
price: 0,
|
|
155
|
+
modifiers: makeSegmentGroups(),
|
|
156
|
+
}),
|
|
157
|
+
],
|
|
158
|
+
}),
|
|
159
|
+
makeEngineModifier({
|
|
160
|
+
_id: 'drink',
|
|
161
|
+
name: 'Drink',
|
|
162
|
+
depth: 0,
|
|
163
|
+
options: [
|
|
164
|
+
makeEngineOption({
|
|
165
|
+
_id: 'cola',
|
|
166
|
+
ref: 'cola',
|
|
167
|
+
ref_type: constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.ITEM,
|
|
168
|
+
default: true,
|
|
169
|
+
price: 0,
|
|
170
|
+
}),
|
|
171
|
+
],
|
|
172
|
+
}),
|
|
173
|
+
],
|
|
174
|
+
});
|
|
175
|
+
const result = (0, order_engine_1.applyNestedChooseExpensiveSegmentPrice)(item);
|
|
176
|
+
const firstPizza = result.modifiers.find((m) => m._id === 'first-pizza');
|
|
177
|
+
const halfHalfOption = firstPizza.options.find((o) => o._id === 'halfhalf-1');
|
|
178
|
+
const segA = halfHalfOption.modifiers.find((m) => m._id === 'seg-1');
|
|
179
|
+
const segB = halfHalfOption.modifiers.find((m) => m._id === 'seg-2');
|
|
180
|
+
// Selected MILAN (500) in segment 1 raised to 600; selected TORENT (600)
|
|
181
|
+
// in segment 2 unchanged. Unselected options keep their prices.
|
|
182
|
+
expect(segA.options.find((o) => o._id === 'milan').price).toBe(600);
|
|
183
|
+
expect(segA.options.find((o) => o._id === 'torent').price).toBe(600);
|
|
184
|
+
expect(segB.options.find((o) => o._id === 'torent2').price).toBe(600);
|
|
185
|
+
// Other groups untouched.
|
|
186
|
+
const drink = result.modifiers.find((m) => m._id === 'drink');
|
|
187
|
+
expect(drink.options.find((o) => o._id === 'cola').price).toBe(0);
|
|
188
|
+
});
|
|
189
|
+
it('does nothing when the half-half flag is off', () => {
|
|
190
|
+
const item = makeEngineItem({
|
|
191
|
+
modifiers: [
|
|
192
|
+
makeEngineModifier({
|
|
193
|
+
depth: 0,
|
|
194
|
+
options: [
|
|
195
|
+
makeEngineOption({
|
|
196
|
+
_id: 'halfhalf-1',
|
|
197
|
+
ref: 'halfhalf-1',
|
|
198
|
+
ref_type: constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.HALF_HALF,
|
|
199
|
+
choose_expensive_segment_price: false,
|
|
200
|
+
default: true,
|
|
201
|
+
modifiers: makeSegmentGroups(),
|
|
202
|
+
}),
|
|
203
|
+
],
|
|
204
|
+
}),
|
|
205
|
+
],
|
|
206
|
+
});
|
|
207
|
+
const result = (0, order_engine_1.applyNestedChooseExpensiveSegmentPrice)(item);
|
|
208
|
+
const halfHalfOption = result.modifiers[0].options[0];
|
|
209
|
+
expect(halfHalfOption.modifiers[0].options[0].price).toBe(500);
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
describe('applyChooseExpensiveSegmentPrice (standalone regression)', () => {
|
|
213
|
+
it('still raises to the max at top-level segment groups', () => {
|
|
214
|
+
const item = makeEngineItem({
|
|
215
|
+
item_type: constants_1.ORDER_ITEM_TYPE_ENUM.HALF_HALF,
|
|
216
|
+
modifiers: makeSegmentGroups().map((modifier, i) => ({ ...modifier, depth: 0, _id: `seg-${i}` })),
|
|
217
|
+
});
|
|
218
|
+
const result = (0, order_engine_1.applyChooseExpensiveSegmentPrice)(item);
|
|
219
|
+
const segA = result.modifiers.find((m) => m._id === 'seg-0');
|
|
220
|
+
const segB = result.modifiers.find((m) => m._id === 'seg-1');
|
|
221
|
+
expect(segA.options.find((o) => o._id === 'milan').price).toBe(600);
|
|
222
|
+
expect(segB.options.find((o) => o._id === 'torent2').price).toBe(600);
|
|
223
|
+
});
|
|
224
|
+
});
|
|
@@ -138,7 +138,7 @@ describe('getPartialItems - composite items on partial KOTs (ref_type)', () => {
|
|
|
138
138
|
'cat-deals': { sortId: 0, includedItemsMap: { 'deal-2': { sortId: 0 } } },
|
|
139
139
|
'cat-pizza': {
|
|
140
140
|
sortId: 1,
|
|
141
|
-
includedItemsMap: { 'pizza-milano': { sortId: 0 }
|
|
141
|
+
includedItemsMap: { 'pizza-milano': { sortId: 0 } },
|
|
142
142
|
},
|
|
143
143
|
});
|
|
144
144
|
const trimmedDeal = result.find((c) => c.category_id === 'cat-deals').items[0];
|
|
@@ -52,7 +52,7 @@ function makeHalfHalfSetup(overrides = {}) {
|
|
|
52
52
|
upsell_price: null,
|
|
53
53
|
discount_amount: null,
|
|
54
54
|
is_discount_percentage: false,
|
|
55
|
-
choose_expensive_segment_price:
|
|
55
|
+
choose_expensive_segment_price: true,
|
|
56
56
|
segments: [
|
|
57
57
|
{ _id: 'seg-1', name: 'First Pizza', sort_id: 1 },
|
|
58
58
|
{ _id: 'seg-2', name: 'Second Pizza', sort_id: 2 },
|
|
@@ -144,6 +144,7 @@ describe('convertSpecialToItem with half-half options', () => {
|
|
|
144
144
|
expect(halfHalfOption).toBeDefined();
|
|
145
145
|
expect(halfHalfOption.name).toBe('Half/Half Pizza Large');
|
|
146
146
|
expect(halfHalfOption.ref_type).toBe(constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.HALF_HALF);
|
|
147
|
+
expect(halfHalfOption.choose_expensive_segment_price).toBe(true);
|
|
147
148
|
// Segment modifiers (one single-select per segment); their options are
|
|
148
149
|
// real items -> ITEM.
|
|
149
150
|
const segmentModifiers = halfHalfOption.modifiers ?? [];
|