@managesome/eposmatic-toolkit 0.2.720 → 0.2.732
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/order-engine.d.ts +40 -12
- package/lib/helpers/utils/cart-helpers.d.ts +2 -0
- package/lib/helpers/utils/halfhalf-setup-helpers.js +75 -52
- package/lib/helpers/utils/order-engine.d.ts +80 -79
- package/lib/helpers/utils/order-engine.js +351 -249
- package/lib/tests/choose-expensive-edge-cases.test.d.ts +1 -0
- package/lib/tests/choose-expensive-edge-cases.test.js +966 -0
- package/lib/tests/choose-expensive-flow-verification.test.d.ts +1 -0
- package/lib/tests/choose-expensive-flow-verification.test.js +702 -0
- package/lib/tests/halfhalf-selection-rules.test.d.ts +1 -0
- package/lib/tests/halfhalf-selection-rules.test.js +200 -0
- package/lib/tests/nested-halfhalf-segment-price.test.js +0 -227
- package/lib/tests/segment-price-floor.test.d.ts +1 -0
- package/lib/tests/segment-price-floor.test.js +143 -0
- package/lib/tests/specials-halfhalf-pricing.test.js +143 -585
- package/package.json +1 -1
|
@@ -5,18 +5,6 @@ export interface IOrderEngineOption extends Omit<IModifierOption, 'modifiers' |
|
|
|
5
5
|
loyalty_applied: boolean;
|
|
6
6
|
voucher_applied: boolean;
|
|
7
7
|
price: number;
|
|
8
|
-
/**
|
|
9
|
-
* The price the engine assigned to this option when the item was built
|
|
10
|
-
* (the catalog/definition value — NOT a persisted order value). It is the
|
|
11
|
-
* engine's own memory for reversible price normalization such as
|
|
12
|
-
* `choose_expensive_segment_price`: normalizing re-bases each option from
|
|
13
|
-
* here first, so the rule can raise AND lower across selection changes
|
|
14
|
-
* without any caller having to keep a pristine copy of the item.
|
|
15
|
-
*
|
|
16
|
-
* Optionally absent (e.g. hand-built engine items): callers that normalize
|
|
17
|
-
* prices should then pass an explicit `basePrices` map instead.
|
|
18
|
-
*/
|
|
19
|
-
base_price?: number;
|
|
20
8
|
quantity: number;
|
|
21
9
|
modifiers: IOrderEngineModifier[];
|
|
22
10
|
}
|
|
@@ -25,6 +13,46 @@ export interface IOrderEngineModifier extends Omit<IModifier, 'options'> {
|
|
|
25
13
|
default: boolean;
|
|
26
14
|
options: IOrderEngineOption[];
|
|
27
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Original (definition) price of every engine option, keyed by its OPTION
|
|
18
|
+
* PATH: the `_`-joined chain of modifier/option ids from the root — the same
|
|
19
|
+
* identifier format used by `setCheckFieldInOrderEngineItem` and the
|
|
20
|
+
* flattened modifiers (all ids are BSON ObjectIds, so `_` cannot appear
|
|
21
|
+
* inside one). Examples:
|
|
22
|
+
* - standalone half-half segment option: `seg-1_milan`
|
|
23
|
+
* - option of a half-half nested in a special: `mod-pizza_halfhalf-1_seg-1_milan`
|
|
24
|
+
* - option inside a required modifier group: `mod-roma_size-mod_large-13`
|
|
25
|
+
*
|
|
26
|
+
* Engine price normalization (`choose_expensive_segment_price`) only ever
|
|
27
|
+
* mutates `price`, so this map is a COMPLETE reference of the original state:
|
|
28
|
+
* re-basing from it before every re-apply keeps the rule reversible (raise
|
|
29
|
+
* AND lower) while selections stay untouched.
|
|
30
|
+
*
|
|
31
|
+
* A key is ABSENT when the option has no definition entry (e.g. it was
|
|
32
|
+
* created outside the catalog definition) — readers must treat absence as
|
|
33
|
+
* "no reference, keep the current price", never as `0`.
|
|
34
|
+
*/
|
|
35
|
+
export type TOrderEnginePriceReferences = {
|
|
36
|
+
[optionPath: string]: number | undefined;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Return of `convertCatalogItemToOrderEngineItem`: the immutable original
|
|
40
|
+
* price references plus the item the UI edits (working data). The references
|
|
41
|
+
* are never mutated; every normalization reads them to restore prices first.
|
|
42
|
+
*/
|
|
43
|
+
export interface IOrderEngineItemState {
|
|
44
|
+
readonly originalPriceReferences: TOrderEnginePriceReferences;
|
|
45
|
+
workingData: IOrderEngineItem;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Options of `applyChooseExpensiveSegmentPrice` /
|
|
49
|
+
* `applyNestedChooseExpensiveSegmentPrice`: the immutable definition prices the
|
|
50
|
+
* rule re-bases from before every normalization (see
|
|
51
|
+
* `TOrderEnginePriceReferences`). Omitted → the legacy raise-only behaviour.
|
|
52
|
+
*/
|
|
53
|
+
export interface IChooseExpensiveSegmentPriceOptions {
|
|
54
|
+
originalPriceReferences?: TOrderEnginePriceReferences;
|
|
55
|
+
}
|
|
28
56
|
export interface IOrderEngineItem {
|
|
29
57
|
_id: string;
|
|
30
58
|
category_id: string;
|
|
@@ -37,6 +37,8 @@ export interface ICatalogItemOptionsDrawerProps<I extends ISimplifiedCatalogItem
|
|
|
37
37
|
rewardClaim?: IRewardClaim;
|
|
38
38
|
isRewardItem?: boolean;
|
|
39
39
|
chooseExpensiveSegmentPrice?: boolean;
|
|
40
|
+
segmentPriceFloor?: number;
|
|
41
|
+
isHalfHalfSegmentItem?: boolean;
|
|
40
42
|
onSelect?: (item: IOrderItem) => void;
|
|
41
43
|
}
|
|
42
44
|
interface IGetEditItemProps<I extends ISimplifiedCatalogItem | IItem> {
|
|
@@ -140,10 +140,6 @@ const zeroModifierPrices = (modifiers) => {
|
|
|
140
140
|
function zeroItemPrices(item) {
|
|
141
141
|
return { ...item, price: null, modifiers: zeroModifierPrices(item.modifiers) };
|
|
142
142
|
}
|
|
143
|
-
function isRequiredModifierGroup(modifier) {
|
|
144
|
-
return ((modifier.min_num_options != null && modifier.min_num_options > 0) ||
|
|
145
|
-
(modifier.min_aggregate_options_quantity != null && modifier.min_aggregate_options_quantity > 0));
|
|
146
|
-
}
|
|
147
143
|
function convertHalfHalfSetupToWorkableHalfHalfSetup(halfhalfSetups, itemsMap, platform, tenant_id) {
|
|
148
144
|
if (!platform || !tenant_id)
|
|
149
145
|
return [];
|
|
@@ -179,11 +175,11 @@ function convertHalfHalfSetupToWorkableHalfHalfSetup(halfhalfSetups, itemsMap, p
|
|
|
179
175
|
// from the selectable list (same semantics as specials' excluded_refs).
|
|
180
176
|
.filter((setupItem) => !halfhalfSetup.excluded_refs.includes(setupItem.item_id))
|
|
181
177
|
.sort((a, b) => a.sort_id - b.sort_id);
|
|
182
|
-
// Workable segment entries: divided base price + own upsell
|
|
183
|
-
//
|
|
184
|
-
//
|
|
185
|
-
//
|
|
186
|
-
//
|
|
178
|
+
// Workable segment entries: divided base price + own upsell. The
|
|
179
|
+
// expensive-segment rule is NOT baked in here: it depends on the current
|
|
180
|
+
// selection, so it runs on the engine working data (classic drawer and
|
|
181
|
+
// `convertHalfHalfToOrderEngineItem`) against the definition prices as
|
|
182
|
+
// the original references.
|
|
187
183
|
const entries = [];
|
|
188
184
|
for (let j = 0; j < halfhalfItems.length; j++) {
|
|
189
185
|
const item = halfhalfItems[j];
|
|
@@ -277,7 +273,8 @@ function convertHalfHalfSetupToWorkableHalfHalfSetup(halfhalfSetups, itemsMap, p
|
|
|
277
273
|
* Returns null only when no option can be resolved from the items map.
|
|
278
274
|
*/
|
|
279
275
|
function convertHalfHalfToItem(halfhalfSetup, itemsMap, options) {
|
|
280
|
-
const
|
|
276
|
+
const specialItems = options?.specialItems;
|
|
277
|
+
const isSpecialContext = specialItems != null;
|
|
281
278
|
// Fields are carried through as-is (no schedule resolution here).
|
|
282
279
|
const upsell_price = halfhalfSetup.upsell_price;
|
|
283
280
|
const discount_amount = halfhalfSetup.discount_amount;
|
|
@@ -286,8 +283,8 @@ function convertHalfHalfToItem(halfhalfSetup, itemsMap, options) {
|
|
|
286
283
|
// In a special the segment options ARE the special's own items; the
|
|
287
284
|
// half-half's original item list is never used. Standalone uses the
|
|
288
285
|
// half-half's own list (respecting its excluded_refs).
|
|
289
|
-
const halfHalfItems =
|
|
290
|
-
? [...
|
|
286
|
+
const halfHalfItems = specialItems
|
|
287
|
+
? [...specialItems].sort((a, b) => (a.sort_id ?? 0) - (b.sort_id ?? 0))
|
|
291
288
|
: [...halfhalfSetup.items]
|
|
292
289
|
// Respect excluded_refs: items whose item_id (ref) is listed are
|
|
293
290
|
// removed from the selectable list (same semantics as specials').
|
|
@@ -539,40 +536,52 @@ function convertHalfHalfToOrderItem({ halfHalfItem, selectedHalfHalfItems, quant
|
|
|
539
536
|
*/
|
|
540
537
|
function convertHalfHalfToOrderEngineItem({ halfHalfItem, selectedHalfHalfItems, quantity, platform, existingOrderItem, orderItemId, chooseExpensiveSegmentPrice, }) {
|
|
541
538
|
let menu_id;
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
const
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
539
|
+
// Original (definition) prices for the assembled engine tree, keyed by the
|
|
540
|
+
// same option path the engine uses (`seg-1_milan`,
|
|
541
|
+
// `seg-1_milan_size-mod_large-13`). The selected per-segment items can carry
|
|
542
|
+
// prices raised by an earlier normalization (an edit de-structures them from
|
|
543
|
+
// the persisted line), so the baseline MUST come from the workable
|
|
544
|
+
// definition instead of the selected item price.
|
|
545
|
+
const originalPriceReferences = {};
|
|
546
|
+
const addDefinitionReferences = (modifiers, parentPath) => {
|
|
547
|
+
(modifiers ?? []).forEach((modifier) => {
|
|
548
|
+
const modifierPath = parentPath ? `${parentPath}_${modifier._id}` : modifier._id;
|
|
549
|
+
(modifier.options ?? []).forEach((option) => {
|
|
550
|
+
const optionPath = `${modifierPath}_${option._id}`;
|
|
551
|
+
originalPriceReferences[optionPath] = (0, platform_catalog_1.getPriceEnum)(option.price, platform);
|
|
552
|
+
addDefinitionReferences(option.modifiers, optionPath);
|
|
553
|
+
});
|
|
554
|
+
});
|
|
556
555
|
};
|
|
557
|
-
|
|
556
|
+
// `exclusive_refs` items are FREE inside the half-half through PRICE ONLY
|
|
557
|
+
// (the workable conversion nulls their price). `is_free` is never set
|
|
558
|
+
// here: the "Free" tag belongs exclusively to `num_free_options` options.
|
|
559
|
+
const toEngineModifiers = (modifiers, depth, definitionModifiers) => (modifiers ?? []).map((modifier) => {
|
|
560
|
+
// Required/max flags come from the CATALOG definition: stored order-item
|
|
561
|
+
// modifiers don't carry them, and treating every group as required would
|
|
562
|
+
// let selected add-ons (e.g. toppings) inflate the choose_expensive
|
|
563
|
+
// comparison — they add on top of the segment instead.
|
|
564
|
+
const definitionModifier = (definitionModifiers ?? []).find((def) => def._id === modifier._id);
|
|
558
565
|
const options = modifier.options ?? [];
|
|
559
|
-
const engineOptions = options.map((option) =>
|
|
560
|
-
_id
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
566
|
+
const engineOptions = options.map((option) => {
|
|
567
|
+
const definitionOption = (definitionModifier?.options ?? []).find((def) => def._id === option._id);
|
|
568
|
+
return {
|
|
569
|
+
_id: option._id,
|
|
570
|
+
ref: option.ref,
|
|
571
|
+
name: option.name,
|
|
572
|
+
price: option.price,
|
|
573
|
+
quantity: option.quantity || 1,
|
|
574
|
+
is_free: option.is_free ?? false,
|
|
575
|
+
default: true,
|
|
576
|
+
loyalty_applied: false,
|
|
577
|
+
voucher_applied: false,
|
|
578
|
+
active: true,
|
|
579
|
+
sold_out: [],
|
|
580
|
+
sort_id: 0,
|
|
581
|
+
excluded_platforms: [],
|
|
582
|
+
modifiers: toEngineModifiers(option.modifiers, depth + 1, definitionOption?.modifiers),
|
|
583
|
+
};
|
|
584
|
+
});
|
|
576
585
|
return {
|
|
577
586
|
_id: modifier._id,
|
|
578
587
|
ref: modifier.ref,
|
|
@@ -583,8 +592,20 @@ function convertHalfHalfToOrderEngineItem({ halfHalfItem, selectedHalfHalfItems,
|
|
|
583
592
|
active: true,
|
|
584
593
|
sold_out: [],
|
|
585
594
|
sort_id: 0,
|
|
586
|
-
|
|
587
|
-
|
|
595
|
+
// Mirror the catalog flags EXACTLY when the definition is known
|
|
596
|
+
// (undefined/null min = optional). Unknown groups keep the previous
|
|
597
|
+
// conservative default (required, max = selection count).
|
|
598
|
+
...(definitionModifier != null
|
|
599
|
+
? {
|
|
600
|
+
min_num_options: definitionModifier.min_num_options,
|
|
601
|
+
max_num_options: definitionModifier.max_num_options,
|
|
602
|
+
min_aggregate_options_quantity: definitionModifier.min_aggregate_options_quantity,
|
|
603
|
+
max_aggregate_options_quantity: definitionModifier.max_aggregate_options_quantity,
|
|
604
|
+
}
|
|
605
|
+
: {
|
|
606
|
+
min_num_options: 1,
|
|
607
|
+
max_num_options: options.length || 1,
|
|
608
|
+
}),
|
|
588
609
|
options: engineOptions,
|
|
589
610
|
};
|
|
590
611
|
});
|
|
@@ -597,16 +618,18 @@ function convertHalfHalfToOrderEngineItem({ halfHalfItem, selectedHalfHalfItems,
|
|
|
597
618
|
menu_id = selectedItem.menu_id;
|
|
598
619
|
}
|
|
599
620
|
const segment = halfHalfItem.segments[s];
|
|
600
|
-
const
|
|
621
|
+
const definitionItem = halfHalfItem.items.find((item) => item._id === selectedItem.item_id);
|
|
622
|
+
const segmentPath = `${segment?._id ?? halfHalfItem._id}_${selectedItem.item_id}`;
|
|
623
|
+
if (definitionItem != null) {
|
|
624
|
+
originalPriceReferences[segmentPath] = (0, platform_catalog_1.getPriceEnum)(definitionItem.price, platform);
|
|
625
|
+
addDefinitionReferences(definitionItem.modifiers, segmentPath);
|
|
626
|
+
}
|
|
601
627
|
const segmentOptions = [
|
|
602
628
|
{
|
|
603
629
|
_id: selectedItem.item_id,
|
|
604
630
|
ref: selectedItem.item_id,
|
|
605
631
|
name: selectedItem.name,
|
|
606
632
|
price: selectedItem.price,
|
|
607
|
-
// Definition price, not the (possibly previously raised) selected
|
|
608
|
-
// order item price — see `getSegmentItemBasePrices`.
|
|
609
|
-
base_price: getWorkableItemPrice(selectedItem.item_id) ?? selectedItem.price,
|
|
610
633
|
quantity: selectedItem.quantity || 1,
|
|
611
634
|
is_free: false,
|
|
612
635
|
default: true,
|
|
@@ -616,7 +639,7 @@ function convertHalfHalfToOrderEngineItem({ halfHalfItem, selectedHalfHalfItems,
|
|
|
616
639
|
sold_out: [],
|
|
617
640
|
sort_id: 0,
|
|
618
641
|
excluded_platforms: [],
|
|
619
|
-
modifiers: toEngineModifiers(selectedItem.modifiers, 1,
|
|
642
|
+
modifiers: toEngineModifiers(selectedItem.modifiers, 1, definitionItem?.modifiers),
|
|
620
643
|
},
|
|
621
644
|
];
|
|
622
645
|
const segmentModifier = {
|
|
@@ -667,7 +690,7 @@ function convertHalfHalfToOrderEngineItem({ halfHalfItem, selectedHalfHalfItems,
|
|
|
667
690
|
};
|
|
668
691
|
const syncedOrderEngineItem = (0, order_engine_1.syncOrderEngineItem)(orderEngineItem);
|
|
669
692
|
if (chooseExpensiveSegmentPrice === true) {
|
|
670
|
-
return (0, order_engine_1.applyChooseExpensiveSegmentPrice)(syncedOrderEngineItem);
|
|
693
|
+
return (0, order_engine_1.applyChooseExpensiveSegmentPrice)(syncedOrderEngineItem, { originalPriceReferences });
|
|
671
694
|
}
|
|
672
695
|
return syncedOrderEngineItem;
|
|
673
696
|
}
|
|
@@ -1,114 +1,115 @@
|
|
|
1
1
|
import { ORDER_ITEM_TYPE_ENUM, PLATFORMS_ENUM } from '../../constants';
|
|
2
2
|
import { IDiscountDetails, IGiftCard, IItem, IModifier, IOffer, IOrderItem, IPrice } from '../../schemas';
|
|
3
3
|
import { ISimplifiedCatalogItem } from '../types';
|
|
4
|
-
import { IOrderEngineItem, IOrderEngineModifier, IOrderEngineOption } from '../types/order-engine';
|
|
4
|
+
import { IChooseExpensiveSegmentPriceOptions, IOrderEngineItem, IOrderEngineItemState, IOrderEngineModifier, IOrderEngineOption } from '../types/order-engine';
|
|
5
5
|
export declare function hasMissedRequiredItemModifier(currentModifiers: IModifier[] | null, platform: PLATFORMS_ENUM | undefined): boolean;
|
|
6
6
|
export declare function syncOrderEngineItem(orderEngineItem: IOrderEngineItem): IOrderEngineItem;
|
|
7
7
|
export declare function checkIfModifiersExist(modifiers: IModifier[] | null, platform: PLATFORMS_ENUM | undefined): boolean;
|
|
8
8
|
export declare function makeSpaceForFreeOptions(options: IOrderEngineOption[], num_free_options: number | null | undefined): IOrderEngineOption[];
|
|
9
|
-
/**
|
|
10
|
-
* OPTIONAL override of the pristine-price baseline for
|
|
11
|
-
* `choose_expensive_segment_price`.
|
|
12
|
-
*
|
|
13
|
-
* The engine normally re-bases itself from the `base_price` stamped on every
|
|
14
|
-
* option when the item was built (its own memory — see `IOrderEngineOption`),
|
|
15
|
-
* so re-applying the rule after a selection change can LOWER prices again and
|
|
16
|
-
* callers never have to keep a pristine copy of the item. Pass `basePrices`
|
|
17
|
-
* only when the baseline must come from somewhere else (e.g. a pre-computed
|
|
18
|
-
* `_id -> price` map); it takes precedence over the stamps.
|
|
19
|
-
*/
|
|
20
|
-
export interface IChooseExpensiveSegmentPriceOptions {
|
|
21
|
-
basePrices?: Record<string, number>;
|
|
22
|
-
}
|
|
23
9
|
/**
|
|
24
10
|
* Applies `choose_expensive_segment_price` to an order engine item converted
|
|
25
11
|
* from a half-half setup (top-level modifier groups = segments, single-select
|
|
26
12
|
* each, only 2 or 4 segments).
|
|
27
13
|
*
|
|
28
|
-
* The rule
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* conversion) so the result NEVER accumulates raises, even when the item is
|
|
35
|
-
* mutated in place across selection changes. `basePrices` can override that
|
|
36
|
-
* baseline (see `IChooseExpensiveSegmentPriceOptions`).
|
|
14
|
+
* The expensive rule depends on which halves the user actually picked, so it
|
|
15
|
+
* cannot run during `IHalfHalfSetup -> IItem` conversion — it must run after
|
|
16
|
+
* selection, on the WORKING data. When `originalPriceReferences` is provided,
|
|
17
|
+
* every option price is first re-based from that immutable reference, which
|
|
18
|
+
* makes the rule fully reversible: picking a cheaper pair afterwards restores
|
|
19
|
+
* the previous (raised) prices instead of accumulating them.
|
|
37
20
|
*
|
|
38
21
|
* Rule: `price = base + upsell` — the item (option) level upsell is already
|
|
39
22
|
* baked into the option price at conversion. choose_expensive compares every
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
23
|
+
* segment option (option price + required/price-defining modifier prices —
|
|
24
|
+
* e.g. a "Pizza Size" group whose Small/Large/X-Large options are part of the
|
|
25
|
+
* item's price) and levels the cheaper PICK to the most expensive SELECTED
|
|
26
|
+
* half — `A($5)+B($5)` charges 5+5, `B($5)+C($6)` charges 6+6, and switching
|
|
27
|
+
* `C+D -> A+B` lowers them again. Every option is levelled to `max(own value,
|
|
28
|
+
* the max of the OTHER segments' selected values)` — the level its OWN pick
|
|
29
|
+
* would produce: choosing an unselected sibling REPLACES its segment's
|
|
30
|
+
* current pick, so that pick never inflates its own siblings' prices (a
|
|
31
|
+
* segment holding the expensive half keeps its other options at their own
|
|
32
|
+
* prices — you can only pick the next half from the NEXT segment), while a
|
|
33
|
+
* segment with no pick yet previews the full level. Unselected options never
|
|
34
|
+
* contribute to totals. The raise is applied to the FIRST
|
|
35
|
+
* PRICED element along the segment's price chain: the segment option's own
|
|
36
|
+
* price when non-zero, else the first priced required leaf ("First Half ->
|
|
37
|
+
* ROMA -> Pizza Size -> Large 13"") — see `findRaiseTarget`. Optional/upsell
|
|
38
|
+
* modifier groups are excluded: they add on top and must not influence the
|
|
39
|
+
* comparison. The IHalfHalfSetup level upsell is NOT part of this rule: it is
|
|
40
|
+
* the converted item's own price and is added once on top of the combined
|
|
41
|
+
* subtotal. Free (`is_free`) options never drive the comparison and are never
|
|
42
|
+
* raised.
|
|
51
43
|
*
|
|
52
44
|
* All prices here are plain numbers (engine-priced).
|
|
53
45
|
*
|
|
54
|
-
* Returns the item unchanged when
|
|
46
|
+
* Returns the item unchanged when no segment option is selected (only
|
|
47
|
+
* re-based when references were provided).
|
|
55
48
|
*/
|
|
56
49
|
export declare function applyChooseExpensiveSegmentPrice(orderEngineItem: IOrderEngineItem, options?: IChooseExpensiveSegmentPriceOptions): IOrderEngineItem;
|
|
50
|
+
/**
|
|
51
|
+
* Value `choose_expensive_segment_price` compares and levels: the option price
|
|
52
|
+
* (base + item/option level upsell, merged at conversion) + the prices of its
|
|
53
|
+
* SELECTED required (price-defining) options. Exposed so callers that show a
|
|
54
|
+
* price for a single segment (e.g. the segment customization drawer) use the
|
|
55
|
+
* SAME math.
|
|
56
|
+
*/
|
|
57
|
+
export declare function getOrderEngineOptionSegmentValue(option: IOrderEngineOption): number;
|
|
57
58
|
/**
|
|
58
59
|
* True when the item has a top-level modifier group option that is a nested
|
|
59
60
|
* half-half (ref_type HALF_HALF) with its setup's choose_expensive flag.
|
|
60
61
|
*/
|
|
61
62
|
export declare function hasFlaggedHalfHalfOption(orderEngineItem: IOrderEngineItem): boolean;
|
|
62
63
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
64
|
+
* Half-half selection rule: an item may fill at most `segments - 1` halves —
|
|
65
|
+
* it may never make ALL sides of the half-half (otherwise it is not a half-half
|
|
66
|
+
* anymore). Returns the option PATHS that would complete "all sides" when
|
|
67
|
+
* selected, formatted exactly like `setCheckFieldInOrderEngineItem`
|
|
68
|
+
* identifiers (`seg-2_roma`, `mod-pizza_halfhalf-1_seg-2_milan`), so callers
|
|
69
|
+
* can block, guard and label them.
|
|
70
|
+
*
|
|
71
|
+
* Handles both shapes:
|
|
72
|
+
* - a HALF_HALF item (its top-level groups are the segments — pass
|
|
73
|
+
* `isHalfHalfSegmentItem: false`),
|
|
74
|
+
* - a flagged half-half option nested in a SPECIAL (its own modifier groups
|
|
75
|
+
* are the segments).
|
|
76
|
+
* A drawer opened for a single half-half SEGMENT passes
|
|
77
|
+
* `isHalfHalfSegmentItem: true` so the item's own option groups are never
|
|
78
|
+
* treated as segments.
|
|
69
79
|
*/
|
|
70
|
-
export declare function
|
|
80
|
+
export declare function getBlockedHalfHalfOptionPaths(orderEngineItem: IOrderEngineItem, isHalfHalfSegmentItem?: boolean): Set<string>;
|
|
81
|
+
/**
|
|
82
|
+
* Same half-half selection rule for the MODERN selection list (no engine tree
|
|
83
|
+
* yet): the item ids that cannot be picked for `segmentIndex` because doing so
|
|
84
|
+
* would make them occupy every segment. `segmentIndex` is the segment being
|
|
85
|
+
* picked/edited (its own current item does not count against itself).
|
|
86
|
+
*/
|
|
87
|
+
export declare function getHalfHalfBlockedItemIds(orderItems: (IOrderItem | null)[], segmentIndex: number | null): string[];
|
|
71
88
|
/**
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* the
|
|
75
|
-
*
|
|
89
|
+
* `choose_expensive_segment_price` for a half-half option nested in a special:
|
|
90
|
+
* the option's own top-level modifiers are its segment groups, so they get the
|
|
91
|
+
* same level-to-the-most-expensive-SELECTED-half treatment as a standalone
|
|
92
|
+
* half-half item. ITEM options are terminal (their nested modifiers can never
|
|
93
|
+
* contain ITEM/HALF_HALF); normal options pass untouched.
|
|
76
94
|
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* options are built FROM the special's items, so they reuse the SAME `_id`s
|
|
81
|
-
* as the special's top-level options while their prices differ (top-level =
|
|
82
|
-
* full upsell, segment = per-segment share). `nestedHalfHalfSegmentsOnly`
|
|
83
|
-
* keeps the map to the subtrees of HALF_HALF options (the segment trees plus
|
|
84
|
-
* their nested modifiers), excluding top-level option prices — the special
|
|
85
|
-
* drawer feeds this map to `resetOrderEngineItemPrices` / the nested
|
|
86
|
-
* normalization, so the walk order of the item can never leak a top-level
|
|
87
|
-
* price into a segment (or the other way around). Standalone half-half items
|
|
88
|
-
* are a single scope: every segment shares its option `_id`s with the SAME
|
|
89
|
-
* price, so the unscoped map is safe there.
|
|
95
|
+
* When `originalPriceReferences` is provided, prices are re-based first — but
|
|
96
|
+
* ONLY inside the flagged half-half subtrees, so the special's own option
|
|
97
|
+
* prices keep whatever the conversion produced.
|
|
90
98
|
*/
|
|
91
|
-
export declare function
|
|
92
|
-
nestedHalfHalfSegmentsOnly?: boolean;
|
|
93
|
-
}): Record<string, number>;
|
|
99
|
+
export declare function applyNestedChooseExpensiveSegmentPrice(orderEngineItem: IOrderEngineItem, options?: IChooseExpensiveSegmentPriceOptions): IOrderEngineItem;
|
|
94
100
|
/**
|
|
95
|
-
*
|
|
96
|
-
* `
|
|
97
|
-
* `
|
|
98
|
-
*
|
|
101
|
+
* Levels the item's segment VALUE (item price + required option prices — the
|
|
102
|
+
* value `getOrderEngineOptionSegmentValue` / `applyChooseExpensiveSegmentPrice`
|
|
103
|
+
* compare) UP to `floorPrice`, using the same raise mechanics as the rule: the
|
|
104
|
+
* raise lands on the FIRST PRICED element — the item price when non-zero,
|
|
105
|
+
* otherwise the first priced required leaf, otherwise the item price.
|
|
99
106
|
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
* at different prices, so a blanket reset with the scoped map would push the
|
|
105
|
-
* segment share onto the top-level option). With the engine's own stamps the
|
|
106
|
-
* scope is inherent — pass the SAME scope to the map builder and to this
|
|
107
|
-
* reset when you do pass a map.
|
|
107
|
+
* Used by the drawer that edits a SINGLE half-half segment: the half-half
|
|
108
|
+
* screen passes the max value of the OTHER selected halves as the floor, so
|
|
109
|
+
* the drawer shows the amount this segment is actually charged once the
|
|
110
|
+
* choose_expensive rule levels it. It never lowers.
|
|
108
111
|
*/
|
|
109
|
-
export declare function
|
|
110
|
-
nestedHalfHalfOnly?: boolean;
|
|
111
|
-
}): IOrderEngineItem;
|
|
112
|
+
export declare function applySegmentPriceFloor(orderEngineItem: IOrderEngineItem, floorPrice: number): IOrderEngineItem;
|
|
112
113
|
export type IOrderEngineItemRewardClaim = {
|
|
113
114
|
type: 'offer';
|
|
114
115
|
offerId: string;
|
|
@@ -155,7 +156,7 @@ interface IConvertCatalogItemToOrderEngineItemParams {
|
|
|
155
156
|
defaultMenuId: string | null;
|
|
156
157
|
soldoutModifiers: string[];
|
|
157
158
|
}
|
|
158
|
-
export declare function convertCatalogItemToOrderEngineItem({ item, orderItem, platform, tenantId, excludeRefs, excludedDiscountRefs, zeroPriceRefs, orderItemType, applyLoyalty, applyVoucher, keepOptionalModifiersAtBottom, defaultMenuId, soldoutModifiers, }: IConvertCatalogItemToOrderEngineItemParams):
|
|
159
|
+
export declare function convertCatalogItemToOrderEngineItem({ item, orderItem, platform, tenantId, excludeRefs, excludedDiscountRefs, zeroPriceRefs, orderItemType, applyLoyalty, applyVoucher, keepOptionalModifiersAtBottom, defaultMenuId, soldoutModifiers, }: IConvertCatalogItemToOrderEngineItemParams): IOrderEngineItemState;
|
|
159
160
|
export declare function hasRequiredModifier<T extends IModifier | IOrderEngineModifier>(currentModifiers: T[] | null): boolean;
|
|
160
161
|
export declare function convertItemToOrderItem(item: IItem | ISimplifiedCatalogItem, menu_id: string | null, platform: PLATFORMS_ENUM | undefined, tenantId: string, orderItemType?: ORDER_ITEM_TYPE_ENUM): IOrderItem;
|
|
161
162
|
export declare function setCheckFieldInOrderEngineItem(orderEngineItem: IOrderEngineItem, identifier: string, shouldCheck: boolean, chooseExpensiveSegmentPrice?: boolean): IOrderEngineItem;
|