-
Notifications
You must be signed in to change notification settings - Fork 6
/
order.py
75 lines (61 loc) · 3.38 KB
/
order.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
################################################
# order.py #
# Defines the business logic #
# #
################################################
import responder
from menu import *
from config import *
from persistence import *
def getOrderSelected(userId):
order = getOrderSelection(userId)
aslist = list(order)
response = {"selection": [
{"name": json.loads(getMenuStarters())["options"][int(aslist[0])]["name"],
"price": json.loads(getMenuStarters())["options"][int(aslist[0])]["price"]},
{"name": json.loads(getMenuMainCourses())["options"][int(aslist[1])]["name"],
"price": json.loads(getMenuMainCourses())["options"][int(aslist[1])]["price"]},
{"name": json.loads(getMenuDesserts())["options"][int(aslist[2])]["name"],
"price": json.loads(getMenuDesserts())["options"][int(aslist[2])]["price"]},
{"name": json.loads(getMenuDrinks())["options"][int(aslist[3])]["name"],
"price": json.loads(getMenuDrinks())["options"][int(aslist[3])]["price"]},
]}
return json.dumps(response)
def getOrderTotal(userId):
print("getting total amount")
total = 0
jsonItems = json.loads(getOrderSelected(userId))["selection"]
for item in jsonItems:
print(item)
total += int(item["price"])
return total
def processOrderSelection(userId, selectionId):
interactionstatus = getInteractionStatus(userId)
if (interactionstatus == INTERACTION_WAITING_FOR_STARTER_SELECTION):
storeOrderSelection(userId, 0, selectionId[-1])
responder.sendTextMessage(userId, "Nice selection! Let's continue with the order.")
responder.sendPlateSelection(userId, "What would you like for your main course?",
"Made with love and the best ingredients.",
getMenuMainCourses())
storeInteractionStatus(userId, INTERACTION_WAITING_FOR_MAINCOURSE_SELECTION)
return
if (interactionstatus == INTERACTION_WAITING_FOR_MAINCOURSE_SELECTION):
storeOrderSelection(userId, 1, selectionId[-1])
responder.sendTextMessage(userId, "That's a good choice. Any room left for dessert?")
responder.sendPlateSelection(userId, "Choose your dessert:", "Your sweet dreams came true.", getMenuDesserts())
storeInteractionStatus(userId, INTERACTION_WAITING_FOR_DESSERT_SELECTION)
return
if (interactionstatus == INTERACTION_WAITING_FOR_DESSERT_SELECTION):
storeOrderSelection(userId, 2, selectionId[-1])
responder.sendTextMessage(userId, "Awesome! What do you want to drink?")
responder.sendPlateSelection(userId, "Choose your beverage:", "Liquids are cool. Especially with ice.",
getMenuDrinks())
storeInteractionStatus(userId, INTERACTION_WAITING_FOR_DRINK_SELECTION)
return
if (interactionstatus == INTERACTION_WAITING_FOR_DRINK_SELECTION):
storeOrderSelection(userId, 3, selectionId[-1])
responder.sendTextMessage(userId, "Your order is complete.")
responder.showOrder(userId)
responder.sendYesNo(userId, "Are you ready to proceed to checkout?")
storeInteractionStatus(userId, INTERACTION_READY_FOR_CHECKOUT)
return