ShopBot/handlers/user/checkout.py

36 lines
1.3 KiB
Python
Raw Normal View History

2022-06-04 22:02:51 +03:00
from aiogram import types
from load import dp, bot, messages
from utils.database.cart import get_user_cart
from utils.database.market import Catalog
from utils.database.ordering import save_info
from keyboard.default.checkout import checkout_btn
from state.state import UserState
@dp.message_handler(lambda x: x.text == messages.checkout)
2022-06-05 15:02:41 +03:00
async def checkout(message: types.Message):
2022-06-04 22:02:51 +03:00
items = get_user_cart(message.from_user.id)
output: str = ""
cost = 0
for index, count in items:
i = Catalog.get_catalog(index)
output += f'Имя: {i["name"]} цена: {i["price"]} - {count}шт.\n'
cost += i["price"] * count
output += f"Общая сумма: {cost}\nВсё верно? Следующий этап: заполнение заявки"
await bot.send_message(message.chat.id, output, reply_markup=checkout_btn())
await UserState.confirm.set()
2022-06-05 15:02:41 +03:00
@dp.message_handler(lambda x: x.text == messages.all_right_message, state="save_or_continue")
async def continue_user_form():
2022-06-04 22:02:51 +03:00
pass
2022-06-05 15:02:41 +03:00
@dp.message_handler(lambda x: x.text == messages.save_and_continue, state="save_or_continue")
2022-06-04 22:02:51 +03:00
async def save_user_info(message: types.Message):
state = dp.current_state(chat=message.chat.id, user=message.from_user.id)
info = await state.get_data()
save_info(user_id=message.from_user.id, **info)
2022-06-05 15:02:41 +03:00
await continue_user_form()