Product rendering, cart functionality

This commit is contained in:
2026-02-08 12:40:04 +07:00
parent d8cad25f33
commit 9e96da8f53
9 changed files with 399 additions and 14 deletions

View File

@@ -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()