Product rendering, cart functionality
This commit is contained in:
@@ -64,6 +64,7 @@ def render_category(
|
||||
def render_products(
|
||||
products: list[Product],
|
||||
*,
|
||||
parent_id: int,
|
||||
cat_id: int,
|
||||
page: int = 0,
|
||||
show_prev: Optional[bool] = False,
|
||||
@@ -97,10 +98,50 @@ def render_products(
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text="⬅️ Назад",
|
||||
callback_data=f"cat:{cat_id}",
|
||||
callback_data=f"cat:{parent_id}",
|
||||
)
|
||||
]
|
||||
]
|
||||
+ btns
|
||||
+ [nav]
|
||||
).as_markup()
|
||||
|
||||
|
||||
def render_product_interactions(
|
||||
*, product_id: int, category_id: int, show_cart: bool = False, cart_amount: int = 0
|
||||
) -> InlineKeyboardMarkup:
|
||||
btns: list[list[InlineKeyboardButton]] = []
|
||||
|
||||
if show_cart:
|
||||
btns.append(
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text="➖", callback_data=f"cart_action:remove:{product_id}"
|
||||
),
|
||||
InlineKeyboardButton(text=f"🛒 {cart_amount}", callback_data="..."),
|
||||
InlineKeyboardButton(
|
||||
text="➕", callback_data=f"cart_action:add:{product_id}"
|
||||
),
|
||||
]
|
||||
)
|
||||
btns.append(
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text="❌ Удалить из корзины",
|
||||
callback_data=f"cart_action:clear:{product_id}",
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
else:
|
||||
btns.append(
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text="🛒 В корзину", callback_data=f"cart_action:add:{product_id}"
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
btns.append([InlineKeyboardButton(text="⬅️", callback_data=f"cat:{category_id}")])
|
||||
|
||||
return InlineKeyboardBuilder(btns).as_markup()
|
||||
|
||||
9
misc/texts.py
Normal file
9
misc/texts.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from db.models import Product
|
||||
|
||||
|
||||
def get_product_description(product: Product) -> str:
|
||||
output = f"📦 <b>{product.name}</b>\n\n<b><i>🏷️ {product.price}₽</i></b>"
|
||||
if product.description:
|
||||
output += f"\n\n📜 {product.description}"
|
||||
|
||||
return output
|
||||
Reference in New Issue
Block a user