How to sort Categories & Items
A menu is sent to your Menu Update webhook as a set of linked collections. This guide explains how these collections fit together and how to interpret the payload to reconstruct the menu structure and display it correctly.
Menu structure
A menu payload has four collections. categories is an array; the other three are objects keyed by _id.
The menu's hierarchy and display order are determined by each item's subProducts array. This array contains the _id values of the items one level below, listed in the order they should be displayed to the customer.
When reconstructing the menu tree, use the subProducts array to establish parent-child relationships and determine display order. The _id values act as references between collections, allowing you to identify the corresponding items and build the complete menu hierarchy.
| Collection | productType | What it is | subProducts contains |
|---|---|---|---|
categories[] | – | A section of the menu, such as Starters or Drinks. | Product IDs |
products{} | 1 | An item that can be ordered on its own. It can also be offered as an option in a modifier group. | Modifier group IDs |
modifierGroups{} | 3 | A set of options shown as one choice, with rules on how many can be selected. | Modifier IDs, or product IDs for products offered as options |
modifiers{} | 2 | An option that changes a product, such as a topping or a cooking preference. | Nested modifier group IDs |
_id and plu
_id and pluEvery item has an _id and a plu:
_iddescribes the menu structure. Use it to followsubProductsfrom one level to the next.pluidentifies the item itself. Use it to specify which items to include when creating an order.
Sort order
Display order comes from the same subProducts arrays that define the menu structure:
- Categories are shown in the order they appear in the
categoriesarray. - Everything else is shown in the order its ID appears in its parent's
subProductsarray.
A product can appear in more than one category, so read its position from each category's subProducts, not from the products object. Order can change each time the menu is published, so always use the latest payload.
Building the menu tree
To turn the payload into a menu:
- Start with each category's
subProducts. - Look up each ID, then do the same for that item's
subProducts. - Stop when an item's
subProductsis empty.
Every level follows the same pattern, so one recursive function handles all of them, including nested modifiers. Each ID exists in only one collection, so you can merge products, modifierGroups and modifiers into a single lookup first.
Example
Hover over or select an ID in the payload, or an item in the menu, to see where it's defined and referenced:
{ "categories": [ { "_id": "63cf…c0a0", "name": "Steaks", "subProducts": ["63cf…c05d"] }, { "_id": "63cf…c0a1", "name": "Drinks", "subProducts": ["63cf…c06a"] } ], "products": { "63cf…c05d": { "_id": "63cf…c05d", "name": "Delicious Steak Frites", "plu": "STK-01", "productType": 1, "price": 1850, "subProducts": ["63cf…c061", "63cf…c064"] }, "63cf…c065": { "_id": "63cf…c065", "name": "Side Salad", "plu": "SID-02", "productType": 1, "price": 0, "subProducts": [] }, "63cf…c06a": { "_id": "63cf…c06a", "name": "Ginger Beer", "plu": "DRK-04", "productType": 1, "price": 350, "subProducts": [] } }, "modifierGroups": { "63cf…c061": { "_id": "63cf…c061", "name": "Cooking instructions", "plu": "CK-01", "productType": 3, "min": 1, "max": 1, "subProducts": ["63cf…c062", "63cf…c063"] }, "63cf…c064": { "_id": "63cf…c064", "name": "Choose a side", "plu": "SD-01", "productType": 3, "min": 1, "max": 1, "subProducts": ["63cf…c065"] } }, "modifiers": { "63cf…c062": { "_id": "63cf…c062", "name": "Rare", "plu": "CK-R", "productType": 2, "price": 0, "subProducts": [] }, "63cf…c063": { "_id": "63cf…c063", "name": "Well Done", "plu": "CK-WD", "productType": 2, "price": 0, "subProducts": [] } }}
Resolve the menu tree in JavaScript
// menu = the JSON body received on https://yourwebhook.com/menu_update
const items = { ...menu.products, ...menu.modifierGroups, ...menu.modifiers };
const resolve = (id) => {
const item = items[id];
return { ...item, subProducts: (item.subProducts || []).map(resolve) };
};
const tree = menu.categories.map((category) => ({
name: category.name,
items: category.subProducts.map(resolve),
}));Run against the example payload, this produces:
Steaks
Delicious Steak Frites productType 1
Cooking instructions productType 3
Rare productType 2
Well Done productType 2
Choose a side productType 3
Side Salad productType 1
Drinks
Ginger Beer productType 1Updated 1 day ago
