ShopBot/handlers/user/cart.py
2022-06-04 22:02:51 +03:00

41 lines
1.3 KiB
Python

from aiogram import types
from load import dp, bot, messages
from keyboard.default.main_menu import cart_btn
from keyboard.inline.cart import cart_list
from utils.database.cart import get_user_cart, clean_cart
from utils.database.market import Catalog
@dp.message_handler(lambda x: x.text == messages.cart)
async def cmd_cart(message: types.Message):
items = get_user_cart(message.from_user.id)
if not items:
await bot.send_message(message.chat.id, messages.cart + " пустая!", reply_markup=cart_btn())
return
index, count = items[0]
item = Catalog.get_catalog(index)
await bot.send_message(message.chat.id, messages.cart, reply_markup=cart_btn(False))
await bot.send_photo(
chat_id=message.chat.id,
photo=item["image"],
caption=messages.cart_message.format(
name=item["name"],
description=item["description"],
count=count,
price=item['price']*count
),
parse_mode="Markdown",
reply_markup=cart_list(items=len(items)-1)
)
@dp.message_handler(lambda x: x.text == messages.clean_cart)
async def cmd_clean_cart(message: types.Message):
clean_cart(message.from_user.id)
await bot.send_message(message.chat.id, messages.cart + " очищена", reply_markup=cart_btn())