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:
@@ -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],
|
||||
|
||||
@@ -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]), 'Σουβλάκι χοιρινό')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user