@managesome/eposmatic-toolkit 0.2.701 → 0.2.702
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.
|
@@ -94,6 +94,7 @@ interface IConvertHalfHalfToOrderEngineItem {
|
|
|
94
94
|
platform: PLATFORMS_ENUM;
|
|
95
95
|
existingOrderItem?: IOrderItem;
|
|
96
96
|
orderItemId?: string;
|
|
97
|
+
chooseExpensiveSegmentPrice?: boolean;
|
|
97
98
|
}
|
|
98
99
|
/**
|
|
99
100
|
* Converts the legacy half-half selection (per-segment IOrderItems) into a
|
|
@@ -110,7 +111,7 @@ interface IConvertHalfHalfToOrderEngineItem {
|
|
|
110
111
|
* own modifier tree is carried as nested selected engine modifiers; all
|
|
111
112
|
* options are kept selected (they were chosen), so sync/error checks pass.
|
|
112
113
|
*/
|
|
113
|
-
export declare function convertHalfHalfToOrderEngineItem({ halfHalfItem, selectedHalfHalfItems, quantity, platform, existingOrderItem, orderItemId, }: IConvertHalfHalfToOrderEngineItem): IOrderEngineItem;
|
|
114
|
+
export declare function convertHalfHalfToOrderEngineItem({ halfHalfItem, selectedHalfHalfItems, quantity, platform, existingOrderItem, orderItemId, chooseExpensiveSegmentPrice, }: IConvertHalfHalfToOrderEngineItem): IOrderEngineItem;
|
|
114
115
|
/**
|
|
115
116
|
* De-structures a HALF_HALF IOrderItem back into the legacy per-segment
|
|
116
117
|
* selection format used by the HalfHalfScreen selection flow.
|
|
@@ -213,18 +213,63 @@ function convertHalfHalfSetupToWorkableHalfHalfSetup(halfhalfSetups, itemsMap, p
|
|
|
213
213
|
expensiveMaxTotal = entries.reduce((max, entry) => Math.max(max, entry.segmentTotal), 0);
|
|
214
214
|
}
|
|
215
215
|
const items = [];
|
|
216
|
+
const raisePriceBy = (price, delta) => {
|
|
217
|
+
// Raise BOTH the active platform's key AND the base by `delta` so the
|
|
218
|
+
// effective price (`getPriceEnum` reads `price[platform] ?? BASE_PRICE`)
|
|
219
|
+
// is normalized even for items priced per-platform (e.g. POS_DINE_IN /
|
|
220
|
+
// WEB_DELIVERY keys on the same IPrice object).
|
|
221
|
+
const deltaObj = { BASE_PRICE: delta };
|
|
222
|
+
deltaObj[platform] = delta;
|
|
223
|
+
return (0, platform_num_1.mergePriceObjs)(price, deltaObj);
|
|
224
|
+
};
|
|
225
|
+
// RULE (same as the engine's `findRaiseTarget`): the raise is applied to
|
|
226
|
+
// the FIRST PRICED element along the segment's price chain —
|
|
227
|
+
// 1. the item's own price when non-zero, else
|
|
228
|
+
// 2. the priced required leaf: the single option of a single-option
|
|
229
|
+
// required group (its price is fixed), or the selected/default
|
|
230
|
+
// option of a multi-option group (never an unselected sibling), else
|
|
231
|
+
// 3. fall back to the item price.
|
|
232
|
+
const findRaiseTargetOption = (modifiers) => {
|
|
233
|
+
for (const modifier of modifiers ?? []) {
|
|
234
|
+
const isRequired = (modifier.min_num_options != null && modifier.min_num_options > 0) ||
|
|
235
|
+
(modifier.min_aggregate_options_quantity != null && modifier.min_aggregate_options_quantity > 0);
|
|
236
|
+
if (!isRequired)
|
|
237
|
+
continue;
|
|
238
|
+
const options = modifier.options ?? [];
|
|
239
|
+
if (options.length === 1)
|
|
240
|
+
return options[0];
|
|
241
|
+
const selectedOption = options.find((option) => option.default);
|
|
242
|
+
if (selectedOption != null)
|
|
243
|
+
return selectedOption;
|
|
244
|
+
}
|
|
245
|
+
return null;
|
|
246
|
+
};
|
|
216
247
|
for (const entry of entries) {
|
|
217
248
|
const { workableItem, itemUpsell, segmentTotal } = entry;
|
|
218
249
|
if (halfhalfSetup.choose_expensive_segment_price && segmentTotal < expensiveMaxTotal) {
|
|
219
250
|
const delta = expensiveMaxTotal - segmentTotal;
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
251
|
+
if ((0, platform_catalog_1.getPriceEnum)(workableItem.price, platform) > 0) {
|
|
252
|
+
// Rule 1: the item itself carries the price.
|
|
253
|
+
workableItem.price = raisePriceBy(workableItem.price, delta);
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
// Rule 2: the price lives on a required leaf — raise it there
|
|
257
|
+
// (e.g. "ROMA -> Pizza Size -> Large 13\"").
|
|
258
|
+
const targetOption = findRaiseTargetOption(workableItem.modifiers);
|
|
259
|
+
const currentModifiers = workableItem.modifiers ?? [];
|
|
260
|
+
if (targetOption != null && currentModifiers.length > 0) {
|
|
261
|
+
workableItem.modifiers = currentModifiers.map((modifier) => ({
|
|
262
|
+
...modifier,
|
|
263
|
+
options: modifier.options.map((option) => option._id === targetOption._id
|
|
264
|
+
? { ...option, price: raisePriceBy(option.price ?? null, delta) }
|
|
265
|
+
: option),
|
|
266
|
+
}));
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
// Rule 3: fall back to the item price.
|
|
270
|
+
workableItem.price = raisePriceBy(workableItem.price, delta);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
228
273
|
}
|
|
229
274
|
// Each half keeps its own item-level upsell, added ON TOP of the divided
|
|
230
275
|
// price. The half-half upsell is a ONE-TIME addition on the order item,
|
|
@@ -521,7 +566,7 @@ function convertHalfHalfToOrderItem({ halfHalfItem, selectedHalfHalfItems, quant
|
|
|
521
566
|
* own modifier tree is carried as nested selected engine modifiers; all
|
|
522
567
|
* options are kept selected (they were chosen), so sync/error checks pass.
|
|
523
568
|
*/
|
|
524
|
-
function convertHalfHalfToOrderEngineItem({ halfHalfItem, selectedHalfHalfItems, quantity, platform, existingOrderItem, orderItemId, }) {
|
|
569
|
+
function convertHalfHalfToOrderEngineItem({ halfHalfItem, selectedHalfHalfItems, quantity, platform, existingOrderItem, orderItemId, chooseExpensiveSegmentPrice, }) {
|
|
525
570
|
let menu_id;
|
|
526
571
|
const toEngineModifiers = (modifiers, depth) => (modifiers ?? []).map((modifier) => {
|
|
527
572
|
const options = modifier.options ?? [];
|
|
@@ -629,7 +674,11 @@ function convertHalfHalfToOrderEngineItem({ halfHalfItem, selectedHalfHalfItems,
|
|
|
629
674
|
item_discount_details: (0, order_engine_1.convertItemDiscountToOrderItemDiscount)(halfHalfItem.discount_amount, halfHalfItem.is_discount_percentage, platform, halfHalfItem._id),
|
|
630
675
|
modifiers,
|
|
631
676
|
};
|
|
632
|
-
|
|
677
|
+
const syncedOrderEngineItem = (0, order_engine_1.syncOrderEngineItem)(orderEngineItem);
|
|
678
|
+
if (chooseExpensiveSegmentPrice === true) {
|
|
679
|
+
return (0, order_engine_1.applyChooseExpensiveSegmentPrice)(syncedOrderEngineItem);
|
|
680
|
+
}
|
|
681
|
+
return syncedOrderEngineItem;
|
|
633
682
|
}
|
|
634
683
|
// ====================================================================================================
|
|
635
684
|
/**
|