diff --git a/connect_frontend/menu-app/src/pages/MenuPage.jsx b/connect_frontend/menu-app/src/pages/MenuPage.jsx index ac27fa3..d9a3853 100644 --- a/connect_frontend/menu-app/src/pages/MenuPage.jsx +++ b/connect_frontend/menu-app/src/pages/MenuPage.jsx @@ -74,18 +74,25 @@ function resolveImageUrl(url) { // pushed before S.2 had digital_price. const QR_POINT = 'qr_table' +// The menu in the guest's language (plan step 6.4): the venue sends `names` / `descriptions` per +// menu language (el, en), already falling back to the text as typed; this app's codes are en / gr. +const byLang = (texts, base) => (texts ? { en: texts.en || base, gr: texts.el || base } : base) + +// Allergens (6.3) come as {key: "contains" | "may_contain"}; this page lists what it contains. +const allergenKeys = a => (Array.isArray(a) ? a : Object.keys(a || {}).filter(k => a[k] === 'contains')) + function normaliseProduct(p, catId) { return { ...p, digital_price: undefined, digital_discount: undefined, id: String(p.id), cat: catId, - name: p.digital_name || p.name || '', - desc: p.digital_description || p.description || '', + name: byLang(p.names, p.digital_name || p.name || ''), + desc: byLang(p.descriptions, p.digital_description || p.description || ''), price: p.prices ? (p.prices[QR_POINT] ?? 0) : (p.digital_price ?? p.base_price ?? 0), badge: p.digital_badge || p.badge || null, tags: p.digital_tags || p.tags || [], - allergens: p.allergens || [], + allergens: allergenKeys(p.allergens), ingredients: p.ingredients || null, discountPct: 0, image_url: resolveImageUrl(p.digital_image_url || p.image_url || null), @@ -98,6 +105,7 @@ function normaliseCategories(rawCats) { const id = cat.id ? String(cat.id) : `cat-${idx}` return { ...cat, + name: byLang(cat.names, cat.name), id, hue: cat.hue ?? CATEGORY_HUES[idx % CATEGORY_HUES.length], GlyphIcon: GLYPH_BY_ID[id] ?? GLYPH_FALLBACK[idx % GLYPH_FALLBACK.length], diff --git a/connect_frontend/order-app/src/logic.js b/connect_frontend/order-app/src/logic.js index 518d72c..8b9f165 100644 --- a/connect_frontend/order-app/src/logic.js +++ b/connect_frontend/order-app/src/logic.js @@ -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. */ diff --git a/connect_frontend/order-app/src/pages/OrderPage.jsx b/connect_frontend/order-app/src/pages/OrderPage.jsx index 469c41b..c735ec4 100644 --- a/connect_frontend/order-app/src/pages/OrderPage.jsx +++ b/connect_frontend/order-app/src/pages/OrderPage.jsx @@ -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) diff --git a/connect_frontend/order-app/tests/logic.test.mjs b/connect_frontend/order-app/tests/logic.test.mjs index db49d87..ef56f75 100644 --- a/connect_frontend/order-app/tests/logic.test.mjs +++ b/connect_frontend/order-app/tests/logic.test.mjs @@ -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]), 'Σουβλάκι χοιρινό') +})