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) async def checkout(message: types.Message): 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() @dp.message_handler(lambda x: x.text == messages.all_right_message, state="save_or_continue") async def continue_user_form(): pass @dp.message_handler(lambda x: x.text == messages.save_and_continue, state="save_or_continue") 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) await continue_user_form()