feat(menu-app): the QR menu and the order app in the guest's language (contract C-2 names, platform-v2 step 6.4)

The site now sends names / descriptions {el, en} per product, quick option and category
(falling back to the text as typed). The menu app maps them onto its en / gr switch (byLang);
the order app localises its menu by the guest's language (localizeMenu, tested). The menu app
also reads 6.3's allergens object (what a product contains).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 10:46:59 +02:00
co-authored by Claude Opus 5.5
parent e0158b2c72
commit 9f9b882806
4 changed files with 48 additions and 5 deletions
+20
View File
@@ -30,6 +30,26 @@ export function menuFor(categories, service) {
}
export const productName = p => p.digital_name || p.name
/**
* The menu in the guest's language (plan step 6.4): the venue sends each product's, quick option's
* and category's `names` (and `descriptions`) per menu language, already falling back to the text
* as typed; menus from older sites have none and stay as they are.
*/
export function localizeMenu(categories, lang) {
const pick = (texts, base) => (texts && texts[lang]) || base
return (categories ?? []).map(c => ({
...c,
name: pick(c.names, c.name),
products: (c.products ?? []).map(p => (p.names ? {
...p,
name: pick(p.names, p.digital_name || p.name),
digital_name: null,
digital_description: pick(p.descriptions, p.digital_description || '') || null,
quick_options: (p.quick_options ?? []).map(o => ({ ...o, name: pick(o.names, o.name) })),
} : p)),
}))
}
export const productText = p => p.digital_description || ''
/** A cart line's key: the product and its chosen options. */
@@ -9,7 +9,7 @@ import { useNavigate, useParams } from 'react-router-dom'
import { Bike, CalendarDays, Clock, Minus, Plus, ShoppingBag, Store, X } from 'lucide-react'
import { fetchMenu, imageUrl } from '../api'
import { useT } from '../i18n'
import { addToCart, cartCount, cartLines, menuFor, productName, productText, SERVICES } from '../logic'
import { addToCart, cartCount, cartLines, localizeMenu, menuFor, productName, productText, SERVICES } from '../logic'
import BookingPicker from './BookingPicker'
import Checkout from './Checkout'
@@ -48,7 +48,7 @@ export default function OrderPage() {
const book = service === 'book'
// the prices: the service's; a booking's food at the pre-order prices (only when food is on)
const priceService = book ? (booking.food ? 'preorder' : null) : service
const sections = useMemo(() => (menu && priceService ? menuFor(menu.categories, priceService) : []), [menu, priceService])
const sections = useMemo(() => (menu && priceService ? menuFor(localizeMenu(menu.categories, lang), priceService) : []), [menu, priceService, lang])
const products = useMemo(() => sections.flatMap(c => c.products), [sections])
const lines = useMemo(() => (priceService ? cartLines(cart, products, priceService) : []), [cart, products, priceService])
const count = cartCount(lines)
@@ -2,6 +2,7 @@
import assert from 'node:assert/strict'
import { test } from 'node:test'
import {
localizeMenu, productName,
addToCart, cartCount, cartLines, checkoutProblems, menuFor, orderBody, priceFor, refusal, setQty, slotDays, trackSteps,
} from '../src/logic.js'
@@ -81,3 +82,17 @@ test('booking a table, with or without food (S.6)', async () => {
assert.equal(trackSteps('preorder', 'cancelled').at, -1)
assert.equal(priceFor({ sold_at: ['online_preorder'], prices: { online_preorder: 2.6 } }, 'preorder'), 2.6)
})
test('the menu in the guest’s language (6.4): names, descriptions, extras; old menus untouched', () => {
const cats = [{ id: 1, name: 'Ψητά', names: { el: 'Ψητά', en: 'Grill' }, products: [
{ id: 5, name: 'Σουβλάκι', digital_name: 'Σουβλάκι χοιρινό', names: { el: 'Σουβλάκι χοιρινό', en: 'Pork skewer' }, descriptions: { el: 'Με πίτα', en: 'With pitta' },
quick_options: [{ id: 9, name: 'Πίτα', names: { el: 'Πίτα', en: 'Pitta' } }] },
{ id: 6, name: 'Old', digital_name: 'Old one' }] }]
const en = localizeMenu(cats, 'en')
assert.equal(en[0].name, 'Grill')
assert.equal(productName(en[0].products[0]), 'Pork skewer')
assert.equal(en[0].products[0].digital_description, 'With pitta')
assert.equal(en[0].products[0].quick_options[0].name, 'Pitta')
assert.equal(productName(en[0].products[1]), 'Old one')
assert.equal(productName(localizeMenu(cats, 'el')[0].products[0]), 'Σουβλάκι χοιρινό')
})