@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.
@@ -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 applied below.
183
- // `choose_expensive_segment_price` is NOT applied here: it depends on which
184
- // halves the user picks and must be able to lower prices again, so it runs
185
- // at selection/display/submit time on the engine item with pristine
186
- // `basePrices` (see `applyChooseExpensiveSegmentPrice`).
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 isSpecialContext = options?.specialItems != null;
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 = isSpecialContext
290
- ? [...options.specialItems].sort((a, b) => (a.sort_id ?? 0) - (b.sort_id ?? 0))
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
- * Definition prices of the SEGMENT ITEM (its own price + nested modifier
544
- * option prices). The selected per-segment order items can carry prices
545
- * raised by a previous `choose_expensive_segment_price` normalization (edit
546
- * flow, de-structured line), so the engine stamps THIS baseline as its own
547
- * memory `base_price` — re-apply can then raise AND lower.
548
- */
549
- const getSegmentItemBasePrices = (itemId) => {
550
- const workableItem = halfHalfItem.items.find((item) => item._id === itemId);
551
- return workableItem == null ? {} : (0, order_engine_1.getOptionPriceMapFromItem)(workableItem, platform);
552
- };
553
- const getWorkableItemPrice = (itemId) => {
554
- const workableItem = halfHalfItem.items.find((item) => item._id === itemId);
555
- return workableItem == null ? undefined : (0, platform_catalog_1.getPriceEnum)(workableItem.price, platform);
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
- const toEngineModifiers = (modifiers, depth, basePrices) => (modifiers ?? []).map((modifier) => {
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: option._id,
561
- ref: option.ref,
562
- name: option.name,
563
- price: option.price,
564
- base_price: basePrices[option._id] ?? option.price,
565
- quantity: option.quantity || 1,
566
- is_free: option.is_free ?? false,
567
- default: true,
568
- loyalty_applied: false,
569
- voucher_applied: false,
570
- active: true,
571
- sold_out: [],
572
- sort_id: 0,
573
- excluded_platforms: [],
574
- modifiers: toEngineModifiers(option.modifiers, depth + 1, basePrices),
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
- min_num_options: 1,
587
- max_num_options: options.length || 1,
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 segmentBasePrices = getSegmentItemBasePrices(selectedItem.item_id);
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, segmentBasePrices),
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 is a pure function of the CURRENT selection: the most expensive
29
- * half the user actually picked sets the charged price for every picked half
30
- * (cheaper halves are raised to it; picking a cheaper combination later
31
- * lowers them again). It cannot run during `IHalfHalfSetup -> IItem`
32
- * conversion — it runs at display/submit time on the engine item, re-basing
33
- * every price from the engine's own memory (the `base_price` stamped at
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
- * SELECTED segment option (option price + required/price-defining modifier
41
- * prices — e.g. a "Pizza Size" group whose Small/Large/X-Large options are
42
- * part of the item's price) and raises the cheaper ones so their final
43
- * segment price matches the most expensive selected half. The raise is
44
- * applied to the FIRST PRICED element along the segment's price chain: the
45
- * segment option's own price when non-zero, else the first priced required
46
- * leaf ("First Half -> ROMA -> Pizza Size -> Large 13\"") — see
47
- * `findRaiseTarget`. Optional/upsell modifier groups are excluded: they add
48
- * on top and must not influence the comparison. The IHalfHalfSetup level
49
- * upsell is NOT part of this rule: it is the converted item's own price and
50
- * is added once on top of the combined subtotal.
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 nothing changes.
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
- * `choose_expensive_segment_price` for a half-half option nested in a special:
64
- * the option's own top-level modifiers are its segment groups, so they get the
65
- * same raise-to-most-expensive treatment as a standalone half-half item.
66
- * ITEM options are terminal (their nested modifiers can never contain
67
- * ITEM/HALF_HALF); normal options pass untouched. Runs on a copy with pristine
68
- * `basePrices` when provided (see `IChooseExpensiveSegmentPriceOptions`).
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 applyNestedChooseExpensiveSegmentPrice(orderEngineItem: IOrderEngineItem, options?: IChooseExpensiveSegmentPriceOptions): IOrderEngineItem;
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
- * Builds a pristine `_id -> price` map of every option in a converted catalog
73
- * item (`modifiers -> options -> nested modifiers -> options ...`). Used as
74
- * the baseline for `choose_expensive_segment_price` so applying the rule never
75
- * depends on previously raised prices.
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
- * The flat `_id -> price` shape can only represent ONE value per option
78
- * `_id`, so callers MUST keep the map to a single price scope. A half-half
79
- * nested in a special is exactly the case where that fails: its segment
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 getOptionPriceMapFromItem(item: IItem | ISimplifiedCatalogItem, platform: PLATFORMS_ENUM | null | undefined, options?: {
92
- nestedHalfHalfSegmentsOnly?: boolean;
93
- }): Record<string, number>;
99
+ export declare function applyNestedChooseExpensiveSegmentPrice(orderEngineItem: IOrderEngineItem, options?: IChooseExpensiveSegmentPriceOptions): IOrderEngineItem;
94
100
  /**
95
- * Re-bases every engine option price from the engine's own memory (the
96
- * `base_price` stamped at conversion), optionally overridden by an explicit
97
- * `basePrices` map. Called when a drawer builds the engine item so state
98
- * (sidebar prices, edit baselines) never carries a previous normalization.
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
- * `options.nestedHalfHalfOnly` restricts the reset to the subtrees of
101
- * HALF_HALF options — the exact scope `getOptionPriceMapFromItem` builds when
102
- * called with `nestedHalfHalfSegmentsOnly`. Only needed when an external
103
- * `basePrices` map is passed (a special's top-level options reuse their `_id`s
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 resetOrderEngineItemPrices(orderEngineItem: IOrderEngineItem, basePrices?: Record<string, number>, options?: {
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): IOrderEngineItem;
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;