@managesome/eposmatic-toolkit 0.2.709 → 0.2.712

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.
Files changed (35) hide show
  1. package/lib/constants/ENUMS.d.ts +1 -0
  2. package/lib/constants/ENUMS.js +1 -0
  3. package/lib/helpers/types/catalog.d.ts +3 -1
  4. package/lib/helpers/utils/catalog-conversion.d.ts +1 -1
  5. package/lib/helpers/utils/catalog-conversion.js +4 -2
  6. package/lib/helpers/utils/halfhalf-setup-helpers.js +2 -0
  7. package/lib/helpers/utils/minified-catalog.js +4 -0
  8. package/lib/helpers/utils/order-engine.d.ts +13 -0
  9. package/lib/helpers/utils/order-engine.js +59 -5
  10. package/lib/helpers/utils/platform-num.d.ts +1 -1
  11. package/lib/helpers/utils/platform-num.js +40 -22
  12. package/lib/helpers/utils/receipt-engine.js +69 -11
  13. package/lib/helpers/utils/selection-model.d.ts +3 -0
  14. package/lib/helpers/utils/selection-model.js +1 -0
  15. package/lib/helpers/utils/specials-helpers.d.ts +3 -3
  16. package/lib/helpers/utils/specials-helpers.js +44 -7
  17. package/lib/schemas/models/halfhalf_setup.d.ts +3 -3
  18. package/lib/schemas/models/items.d.ts +54 -0
  19. package/lib/schemas/models/items.js +11 -0
  20. package/lib/schemas/models/modifier_extras.d.ts +9 -9
  21. package/lib/schemas/models/orders.d.ts +981 -0
  22. package/lib/schemas/models/orders.js +5 -0
  23. package/lib/schemas/models/rewards_usage.d.ts +3 -3
  24. package/lib/schemas/models/tenant_cash_in_out.d.ts +3 -3
  25. package/lib/schemas/models/warehouse_internal_movements.d.ts +3 -3
  26. package/lib/schemas/models/warehouse_inventory_lot_serial_numbers.d.ts +3 -3
  27. package/lib/schemas/types/items.d.ts +3 -1
  28. package/lib/schemas/types/orders.d.ts +2 -1
  29. package/lib/tests/nested-halfhalf-segment-price.test.d.ts +1 -0
  30. package/lib/tests/nested-halfhalf-segment-price.test.js +224 -0
  31. package/lib/tests/receipt-engine.test.d.ts +1 -0
  32. package/lib/tests/receipt-engine.test.js +204 -0
  33. package/lib/tests/specials-halfhalf-options.test.d.ts +1 -0
  34. package/lib/tests/specials-halfhalf-options.test.js +328 -0
  35. package/package.json +1 -1
@@ -1011,6 +1011,7 @@ export declare enum ONLINE_ORDERING_DESIGN_TYPE_ENUM {
1011
1011
  export declare const ALL_ONLINE_ORDERING_DESIGN_TYPES: ONLINE_ORDERING_DESIGN_TYPE_ENUM[];
1012
1012
  export declare enum MODIFIER_OPTION_REF_TYPE_ENUM {
1013
1013
  ITEM = "ITEM",
1014
+ HALF_HALF = "HALF_HALF",
1014
1015
  OPTION = "OPTION"
1015
1016
  }
1016
1017
  export declare const ALL_MODIFIER_OPTION_REF_TYPES: MODIFIER_OPTION_REF_TYPE_ENUM[];
@@ -1662,6 +1662,7 @@ exports.ALL_ONLINE_ORDERING_DESIGN_TYPES = Object.values(ONLINE_ORDERING_DESIGN_
1662
1662
  var MODIFIER_OPTION_REF_TYPE_ENUM;
1663
1663
  (function (MODIFIER_OPTION_REF_TYPE_ENUM) {
1664
1664
  MODIFIER_OPTION_REF_TYPE_ENUM["ITEM"] = "ITEM";
1665
+ MODIFIER_OPTION_REF_TYPE_ENUM["HALF_HALF"] = "HALF_HALF";
1665
1666
  MODIFIER_OPTION_REF_TYPE_ENUM["OPTION"] = "OPTION";
1666
1667
  })(MODIFIER_OPTION_REF_TYPE_ENUM || (exports.MODIFIER_OPTION_REF_TYPE_ENUM = MODIFIER_OPTION_REF_TYPE_ENUM = {}));
1667
1668
  exports.ALL_MODIFIER_OPTION_REF_TYPES = Object.values(MODIFIER_OPTION_REF_TYPE_ENUM);
@@ -1,4 +1,4 @@
1
- import { CATEGORY_DISPLAY_TYPE_ENUM, DAY_INDEX_ENUM, ITEM_CAVEATS_ENUM, ITEM_DIETARY_PREFERENCE_ENUM, PLATFORMS_ENUM } from '../../constants';
1
+ import { CATEGORY_DISPLAY_TYPE_ENUM, DAY_INDEX_ENUM, ITEM_CAVEATS_ENUM, ITEM_DIETARY_PREFERENCE_ENUM, MODIFIER_OPTION_REF_TYPE_ENUM, PLATFORMS_ENUM } from '../../constants';
2
2
  import { ICategory, IItem, IItemSpecialHour } from '../../schemas';
3
3
  import { IPrice } from '../../schemas/types/common';
4
4
  export interface ICatalog extends ICategory {
@@ -33,6 +33,8 @@ export interface IMinifiedModifierOption {
33
33
  price?: IMinifiedPrice;
34
34
  item_modifier_option_special_hours?: IMinifiedItemSpecialHour[] | null;
35
35
  modifiers?: IMinifiedModifier[] | null;
36
+ ref_type?: MODIFIER_OPTION_REF_TYPE_ENUM;
37
+ choose_expensive_segment_price?: boolean;
36
38
  _id: string;
37
39
  ref: string;
38
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 ? { modifiers: (0, platform_num_1.convertModifiersPriceToCents)(item.modifiers) } : {}),
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
  : {}),
@@ -393,6 +393,8 @@ function convertHalfHalfToItem(halfhalfSetup, itemsMap) {
393
393
  active: catalogItem.active,
394
394
  sold_out: catalogItem.sold_out,
395
395
  sort_id: sortId,
396
+ // Each segment choice IS a menu item.
397
+ ref_type: constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.ITEM,
396
398
  // Derived from the source item's included platforms (pure mapping),
397
399
  // so platform availability can be applied by the filter layer downstream.
398
400
  excluded_platforms: (0, platform_catalog_1.getExcludedPlatformsFromIncludedPlatforms)(catalogItem.included_platforms),
@@ -87,6 +87,8 @@ function convertMinifiedModifierOptionsToOriginalModifierOptions(options, tenant
87
87
  modifiers,
88
88
  ingredients,
89
89
  item_modifier_option_special_hours,
90
+ ref_type: option.ref_type,
91
+ choose_expensive_segment_price: option.choose_expensive_segment_price,
90
92
  // required properties
91
93
  _id,
92
94
  ref,
@@ -278,6 +280,8 @@ function convertOriginalModifierOptionsToMinifiedModifierOptions(options, tenant
278
280
  price,
279
281
  item_modifier_option_special_hours,
280
282
  modifiers,
283
+ ref_type: option.ref_type,
284
+ choose_expensive_segment_price: option.choose_expensive_segment_price,
281
285
  // required properties
282
286
  _id: option._id,
283
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 orderEngineItem;
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 orderEngineItem;
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
- const modifiers = (orderEngineItem.modifiers ?? []).map((modifier, g) => {
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, }) {
@@ -584,6 +630,9 @@ function convertOrderEngineOptionsToOrderItemOptions(options, tenantId) {
584
630
  price: option.price,
585
631
  quantity: option.quantity,
586
632
  is_free: option.is_free,
633
+ // Item / half-half options carry their ref_type; normal modifier
634
+ // options omit it.
635
+ ...(option.ref_type != null ? { ref_type: option.ref_type } : {}),
587
636
  modifiers: convertOrderEngineModifiersToOrderItemModifiers(option.modifiers, tenantId),
588
637
  });
589
638
  }
@@ -988,6 +1037,11 @@ function setCheckFieldInOrderEngineItem(orderEngineItem, identifier, shouldCheck
988
1037
  if (orderEngineItem.item_type === constants_1.ORDER_ITEM_TYPE_ENUM.HALF_HALF && chooseExpensiveSegmentPrice === true) {
989
1038
  return applyChooseExpensiveSegmentPrice(updatedOrderEngineItem);
990
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
+ }
991
1045
  return updatedOrderEngineItem;
992
1046
  }
993
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
- return modifiers.map((modifier) => ({
116
- ...modifier,
117
- min_num_options: modifier.min_num_options ?? undefined,
118
- max_num_options: modifier.max_num_options ?? undefined,
119
- min_option_choice_quantity: modifier.min_option_choice_quantity ?? undefined,
120
- max_option_choice_quantity: modifier.max_option_choice_quantity ?? undefined,
121
- min_aggregate_options_quantity: modifier.min_aggregate_options_quantity ?? undefined,
122
- max_aggregate_options_quantity: modifier.max_aggregate_options_quantity ?? undefined,
123
- num_free_options: modifier.num_free_options ?? undefined,
124
- exempt_discount: modifier.exempt_discount || undefined,
125
- minimized: modifier.minimized || undefined,
126
- options: modifier.options.map((option) => ({
127
- ...option,
128
- price: convertPriceObjToCents(option.price) ?? undefined,
129
- multiplier: (0, catalog_conversion_1.getModifierOptionMultiplier)(option.multiplier, true),
130
- modifiers: convertModifiersPriceToCents(option.modifiers) ?? undefined,
131
- default: option.default || undefined,
132
- ingredients: (0, ingredients_1.getIngredientsWithInt)(option.ingredients) ?? undefined,
133
- item_modifier_option_special_hours: convertSpecialHoursToCents(option.item_modifier_option_special_hours) ?? undefined,
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)
@@ -461,25 +461,79 @@ function getReceiptBody({ orderItems, currency_symbol, show_modifiers, display_m
461
461
  // =========================><=========================
462
462
  /**
463
463
  * For a SPECIAL / HALF_HALF order item (a deal or half-half pizza), the
464
- * top-level modifiers hold the real constituent items as options: each
465
- * `option.ref` is an item `_id` that may live in any category.
464
+ * top-level modifiers hold the real constituent items as options. Each option
465
+ * carries a `ref_type` (MODIFIER_OPTION_REF_TYPE_ENUM):
466
+ * - ITEM -> the option `ref` is a real menu product id. It can NEVER contain
467
+ * nested ITEM / HALF_HALF options - it is filtered by partial-menu membership
468
+ * only, never recursed;
469
+ * - HALF_HALF -> the option `ref` is a real menu product id, and its OWN
470
+ * top-level modifiers (segment groups) hold options with ref_type ITEM - so
471
+ * filtering IS applied recursively there;
472
+ * - OPTION (or unset) -> a regular modifier option (size, topping, ...). It is
473
+ * a terminal leaf: it never contains nested ITEM / HALF_HALF options, so it
474
+ * passes through fully (never partialed).
466
475
  *
467
- * In partial printing these composite products must not be printed blindly:
468
- * - an option whose item is not selected in ANY included category is dropped;
476
+ * Only options whose ref_type is ITEM or HALF_HALF qualify for partial
477
+ * printing - including at the top level. In partial printing these composite
478
+ * products must not be printed blindly:
479
+ * - ITEM / HALF_HALF options whose product is not selected in ANY included
480
+ * category are dropped (they belong to another partial menu / KOT);
481
+ * - a HALF_HALF option whose nested constituent parts are all dropped is
482
+ * dropped as well (nothing printable remains);
469
483
  * - a modifier left with no options is dropped;
470
484
  * - if every modifier is dropped the whole item is dropped as well.
471
485
  *
472
486
  * Returns a shallow-cloned item with the trimmed modifiers, or null when
473
487
  * nothing survives the filter.
474
488
  */
475
- function getPartiallyIncludedCompositeItem(item, includedItemIds) {
489
+ function getTrimmedCompositeModifiers(modifiers, includedItemIds) {
476
490
  const trimmedModifiers = [];
477
- const itemModifiers = item.modifiers ?? [];
478
- for (let i = 0; i < itemModifiers.length; i++) {
479
- const modifier = itemModifiers[i];
480
- // option.ref acts as a real item _id; keep the option only when that item
481
- // is part of the partial menu in any of its categories.
482
- const keptOptions = modifier.options.filter((option) => includedItemIds.has(option.ref));
491
+ for (let i = 0; i < modifiers.length; i++) {
492
+ const modifier = modifiers[i];
493
+ const keptOptions = [];
494
+ for (let j = 0; j < modifier.options.length; j++) {
495
+ const option = modifier.options[j];
496
+ const isItemLike = option.ref_type === constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.ITEM ||
497
+ option.ref_type === constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.HALF_HALF;
498
+ // A normal modifier option (OPTION / unset) is a terminal leaf: it
499
+ // passes through fully, never filtered and never recursed.
500
+ if (!isItemLike) {
501
+ keptOptions.push(option);
502
+ continue;
503
+ }
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).
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)) {
520
+ keptOptions.push(option);
521
+ continue;
522
+ }
523
+ const nestedModifiers = option.modifiers != null ? getTrimmedCompositeModifiers(option.modifiers, includedItemIds) : null;
524
+ // A HALF_HALF option that had constituent parts but none survived the
525
+ // filter has nothing printable left -> drop it as well.
526
+ if (option.modifiers != null &&
527
+ option.modifiers.length > 0 &&
528
+ nestedModifiers != null &&
529
+ nestedModifiers.length === 0) {
530
+ continue;
531
+ }
532
+ keptOptions.push({
533
+ ...option,
534
+ modifiers: nestedModifiers,
535
+ });
536
+ }
483
537
  if (keptOptions.length === 0)
484
538
  continue;
485
539
  trimmedModifiers.push({
@@ -487,6 +541,10 @@ function getPartiallyIncludedCompositeItem(item, includedItemIds) {
487
541
  options: keptOptions,
488
542
  });
489
543
  }
544
+ return trimmedModifiers;
545
+ }
546
+ function getPartiallyIncludedCompositeItem(item, includedItemIds) {
547
+ const trimmedModifiers = getTrimmedCompositeModifiers(item.modifiers ?? [], includedItemIds);
490
548
  if (trimmedModifiers.length === 0)
491
549
  return null;
492
550
  return {
@@ -1,3 +1,4 @@
1
+ import { MODIFIER_OPTION_REF_TYPE_ENUM } from '../../constants';
1
2
  import { IOrderModifier } from '../../schemas';
2
3
  export interface ISelectionOption {
3
4
  /** Deterministic semantic identity — the catalog item `_id`. */
@@ -8,6 +9,8 @@ export interface ISelectionOption {
8
9
  price: number;
9
10
  quantity: number;
10
11
  is_free: boolean;
12
+ /** Only set when the option IS an item / half-half. */
13
+ ref_type?: MODIFIER_OPTION_REF_TYPE_ENUM;
11
14
  modifiers: IOrderModifier[] | null;
12
15
  }
13
16
  export interface ISelectionGroup {
@@ -23,6 +23,7 @@ function buildStoredFromSelection(groups) {
23
23
  price: option.price,
24
24
  quantity: option.quantity,
25
25
  is_free: option.is_free,
26
+ ...(option.ref_type != null ? { ref_type: option.ref_type } : {}),
26
27
  modifiers: option.modifiers ?? null,
27
28
  }));
28
29
  modifiers.push({
@@ -1,5 +1,5 @@
1
1
  import { PLATFORMS_ENUM } from '../../constants';
2
- import { IItem, IModifier, IOrderItem, ISpecial } from '../../schemas';
2
+ import { IHalfHalfSetup, IItem, IModifier, IOrderItem, ISpecial } from '../../schemas';
3
3
  import { ISimplifiedCatalogItem } from '../types';
4
4
  export declare function getSpecialsPostedData(data: ISpecial[], payload: ISpecial): ISpecial[];
5
5
  export declare function renderBulkSpecialsUpdate(data: ISpecial[], payload: Partial<ISpecial>[]): ISpecial[];
@@ -39,7 +39,7 @@ export type IWorkableSpecialMenu<T extends IItem | ISimplifiedCatalogItem> = {
39
39
  * Returns null when nothing is left after exclusion.
40
40
  */
41
41
  export declare function applyModifierSpecialRefRules(modifiers: IModifier[] | null | undefined, exclusiveRefs: string[], excludedRefs: string[]): IModifier[] | null;
42
- export declare function convertSpecialsToWorkableSpecials<T extends IItem | ISimplifiedCatalogItem>(specials: ISpecial[], itemsMap: Record<string, T>, platform: PLATFORMS_ENUM | undefined, tenant_id: string | undefined): IWorkableSpecialMenu<T>[];
42
+ export declare function convertSpecialsToWorkableSpecials<T extends IItem | ISimplifiedCatalogItem>(specials: ISpecial[], itemsMap: Record<string, T>, platform: PLATFORMS_ENUM | undefined, tenant_id: string | undefined, halfhalfSetups?: Record<string, IHalfHalfSetup>): IWorkableSpecialMenu<T>[];
43
43
  export interface IModifierSpecials {
44
44
  _id: string;
45
45
  selectedItems: (IOrderItem | null)[];
@@ -94,5 +94,5 @@ export declare function deStructureSpecialOrderItem(orderItem: IOrderItem, speci
94
94
  *
95
95
  * Returns null only when no option can be resolved from the items map.
96
96
  */
97
- export declare function convertSpecialToItem(special: ISpecial, itemsMap: Record<string, IItem>): IItem | null;
97
+ export declare function convertSpecialToItem(special: ISpecial, itemsMap: Record<string, IItem>, halfhalfSetups?: Record<string, IHalfHalfSetup>): IItem | null;
98
98
  export {};
@@ -16,6 +16,7 @@ exports.convertSpecialToItem = convertSpecialToItem;
16
16
  const bson_objectid_1 = __importDefault(require("bson-objectid"));
17
17
  const constants_1 = require("../../constants");
18
18
  const store_1 = require("../store");
19
+ const halfhalf_setup_helpers_1 = require("./halfhalf-setup-helpers");
19
20
  const order_engine_1 = require("./order-engine");
20
21
  const platform_catalog_1 = require("./platform-catalog");
21
22
  const platform_num_1 = require("./platform-num");
@@ -116,7 +117,7 @@ function applyModifierSpecialRefRules(modifiers, exclusiveRefs, excludedRefs) {
116
117
  const withOptions = result.filter((modifier) => modifier.options.length > 0);
117
118
  return withOptions.length > 0 ? withOptions : null;
118
119
  }
119
- function convertSpecialsToWorkableSpecials(specials, itemsMap, platform, tenant_id) {
120
+ function convertSpecialsToWorkableSpecials(specials, itemsMap, platform, tenant_id, halfhalfSetups) {
120
121
  if (!platform || !tenant_id)
121
122
  return [];
122
123
  const isSimple = typeof itemsMap[Object.keys(itemsMap)[0]]?.sold_out === 'boolean';
@@ -155,11 +156,19 @@ function convertSpecialsToWorkableSpecials(specials, itemsMap, platform, tenant_
155
156
  const modifierSpecialItems = [...modifierSpecial.items];
156
157
  modifierSpecialItems.sort((a, b) => a.sort_id - b.sort_id);
157
158
  const items = [];
159
+ // A modifier group can list half-half setups instead of catalog items;
160
+ // they are rendered/selected through the classic preview separately, but
161
+ // they keep the group non-empty so the special stays selectable.
162
+ let hasHalfHalfRef = false;
158
163
  for (let k = 0; k < modifierSpecialItems.length; k++) {
159
164
  const item = modifierSpecial.items[k];
160
165
  const catalogItem = itemsMap[item.item_id];
161
- if (!catalogItem)
166
+ if (!catalogItem) {
167
+ if (halfhalfSetups != null && halfhalfSetups[item.item_id] != null) {
168
+ hasHalfHalfRef = true;
169
+ }
162
170
  continue;
171
+ }
163
172
  const workableItem = (0, platform_catalog_1.convertItemToWorkableItem)(catalogItem, platform, tenant_id, omitItemLevelSchedule, true);
164
173
  if (!workableItem)
165
174
  continue;
@@ -175,9 +184,10 @@ function convertSpecialsToWorkableSpecials(specials, itemsMap, platform, tenant_
175
184
  workableItem.modifiers = applyModifierSpecialRefRules(workableItem.modifiers, modifierSpecial.exclusive_refs, modifierSpecial.excluded_refs);
176
185
  items.push(workableItem);
177
186
  }
178
- // A modifier group with zero items makes the special invalid (cannot be
179
- // completed) — the whole special is not selectable.
180
- if (items.length === 0) {
187
+ // A modifier group with zero resolvable items makes the special invalid
188
+ // (cannot be completed) — unless it only references half-half setups
189
+ // (selectable via the classic preview, kept as a selectable group).
190
+ if (items.length === 0 && !hasHalfHalfRef) {
181
191
  hasEmptyGroup = true;
182
192
  continue;
183
193
  }
@@ -241,6 +251,10 @@ function convertSpecialItemToOrderItem({ specialItem, modifierSpecials, quantity
241
251
  quantity: selectedItem.quantity,
242
252
  modifiers: selectedItem.modifiers,
243
253
  is_free: false,
254
+ // The option IS an item or a half-half — carry its kind.
255
+ ref_type: selectedItem.item_type === constants_1.ORDER_ITEM_TYPE_ENUM.HALF_HALF
256
+ ? constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.HALF_HALF
257
+ : constants_1.MODIFIER_OPTION_REF_TYPE_ENUM.ITEM,
244
258
  });
245
259
  }
246
260
  // Mark the cheapest N selected items as free (num_free_items), same as the
@@ -273,6 +287,7 @@ function convertSpecialItemToOrderItem({ specialItem, modifierSpecials, quantity
273
287
  price: option.price,
274
288
  quantity: option.quantity,
275
289
  is_free: option.is_free,
290
+ ...(option.ref_type != null ? { ref_type: option.ref_type } : {}),
276
291
  modifiers: option.modifiers ?? null,
277
292
  })),
278
293
  });
@@ -406,7 +421,7 @@ function deStructureSpecialOrderItem(orderItem, specialItem) {
406
421
  *
407
422
  * Returns null only when no option can be resolved from the items map.
408
423
  */
409
- function convertSpecialToItem(special, itemsMap) {
424
+ function convertSpecialToItem(special, itemsMap, halfhalfSetups) {
410
425
  // Fields are carried through as-is (no schedule resolution here).
411
426
  const price = special.price;
412
427
  const discount_amount = special.discount_amount;
@@ -423,7 +438,23 @@ function convertSpecialToItem(special, itemsMap) {
423
438
  const options = [];
424
439
  for (let k = 0; k < modifierSpecialItems.length; k++) {
425
440
  const specialItem = modifierSpecialItems[k];
426
- const catalogItem = itemsMap[specialItem.item_id];
441
+ let catalogItem = itemsMap[specialItem.item_id];
442
+ // A modifier_special item can reference a half-half setup instead of a
443
+ // regular catalog item: convert it to an IItem (each segment becomes a
444
+ // nested single-select modifier) so it flows like any other option.
445
+ let isHalfHalfOption = false;
446
+ let halfHalfChooseExpensive = false;
447
+ if (catalogItem == null && halfhalfSetups != null) {
448
+ const halfhalfSetup = halfhalfSetups[specialItem.item_id];
449
+ if (halfhalfSetup != null) {
450
+ const halfhalfItem = (0, halfhalf_setup_helpers_1.convertHalfHalfToItem)(halfhalfSetup, itemsMap);
451
+ if (halfhalfItem != null) {
452
+ catalogItem = halfhalfItem;
453
+ isHalfHalfOption = true;
454
+ halfHalfChooseExpensive = halfhalfSetup.choose_expensive_segment_price === true;
455
+ }
456
+ }
457
+ }
427
458
  if (!catalogItem)
428
459
  continue;
429
460
  allKeywords.push(...(catalogItem.keywords ?? []));
@@ -451,6 +482,12 @@ function convertSpecialToItem(special, itemsMap) {
451
482
  active: catalogItem.active,
452
483
  sold_out: catalogItem.sold_out,
453
484
  sort_id: specialItem.sort_id,
485
+ // This option IS a menu item (or a half-half) — carry its kind so
486
+ // downstream order items can tell item/half-half options apart.
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 } : {}),
454
491
  // Derived from the source item's included platforms (pure mapping),
455
492
  // so platform availability can be applied by the filter layer downstream.
456
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
  }> & {