Ordr.in 101: Dealing With The Menu
The menu structure (you get this from the Restaurant Details endpoint) is fairly complicated, at least compared to what you would expect. Putting together an order than is both valid and complete enough for a restaurant to deliver food requires a lot more detail than you’d think if you’re normal experience with food ordering is calling the restaurant and asking for a pizza with mushrooms.
So here are the basics - a menu is a hierarchy with up to 4 tiers, it looks like this:
Groups -> Items -> Option Groups -> Option Items
So one example could look like this:
Entree (a group)
-> Large Pizza (an item)
-> What topping would you like? (an option group)
-> Anchovies (an option item)
Each thing is modeled in the data as a JSON object, and if it’s not a leaf, it will have a “children” key which will lead you to the next level. That’s children in the sense of computer science not biology. :)
Items (the second level) are orderable with IDs that you can add to a tray - some of them require a specific number of option items. Inside of these menu items exist "option groups" which are not things you can add to a tray. Option groups (like "toppings", "dressing" or "sides”) contain sets of option items. Option items (the 4th and lowest level of the tree) are the actual options that you can select to add to a tray.
Some menu items require a specific number of options in order for them to be valid in a tray. A good example would be a menu item called "teriyaki platter" which has options for a type of meat. Lets pretend these options are "chicken", "beef" and "salmon." You wouldn't be able to order a teriyaki platter without specifying which meat you want with it, so this would require at least one option to be valid tray element. This logic is represented by two fields in the menu item called "max_child_select" and "min_child_select", which refer to the maximum and minimum number of options that need to be selected in order for this to be valid. NOTE - if max_child_select is 0, it’s equivalent to infinity (that is, you can select as many as you like) it does not literally mean, you can select at most 0 items.
Lets recap the structure of typical menu data using this teriyaki platter as an example!
"Dinner Entrees": [
"name": "Teriyaki Platter",
"name": "Meat choices",
"Other stuff": ...
In this case it goes:
Dinner entrees -> Teriyaki Platter -> Meat Choices -> Chicken
Build a tray: This is the food that the user wants to order. Maybe you will have an interface for them to select what to order or maybe you will programmatically select something for them. However you decide to do it, you know how the menu items are structured. Now you need to build a tray with the IDs of the selected items and option items to order.
The tray is composed of groups of menu items and associated, optional sub-items. A single menu item's format is:
[menu item id]/[qty],[option id],[option id]...
Multiple menu items are joined by a +:
[menu item id]/[qty]+[menu item id2]/[qty2]
Means 2 of menu item 3270 (with no sub options) and 1 of item num 3263 with sub option 3279.
And now you know how to validate a tray! That's the hardest part of using the APIs!
Please check out the other API 101 posts: