product management, unification of kb and so on.
This commit is contained in:
@@ -5,7 +5,8 @@ from aiogram.types import CallbackQuery, FSInputFile
|
||||
from aiogram.fsm.context import FSMContext
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from config import PAGE_SIZE
|
||||
from config import PAGE_SIZE, VERIFIED_ACCOUNTS
|
||||
from misc.kb import admins
|
||||
from misc.kb.client import (
|
||||
render_product_interactions,
|
||||
render_products,
|
||||
@@ -46,11 +47,15 @@ async def products_pagination(
|
||||
await cb.message.edit_reply_markup(
|
||||
reply_markup=render_products(
|
||||
products[:PAGE_SIZE],
|
||||
parent_id=category.parent_id,
|
||||
cat_id=category_id,
|
||||
page=page_id,
|
||||
show_prev=page_id > 0,
|
||||
show_next=products_len > PAGE_SIZE,
|
||||
product_cb_factory=lambda p: f"product:{p.id}",
|
||||
back_cb=f"cat:{category.parent_id}",
|
||||
prev_cb=(f"products:{category_id}:{page_id - 1}" if page_id > 0 else None),
|
||||
next_cb=(
|
||||
f"products:{category_id}:{page_id + 1}"
|
||||
if products_len > PAGE_SIZE
|
||||
else None
|
||||
),
|
||||
columns=2,
|
||||
),
|
||||
)
|
||||
|
||||
@@ -68,9 +73,18 @@ async def product_card(
|
||||
product_id = int(cb.data.split(":")[1])
|
||||
product = await products_repo.get_product_by_id(session, product_id)
|
||||
|
||||
order_item = await order_service.get_cart_product_amount(
|
||||
session, customer=cb.from_user.id, product_id=product_id
|
||||
)
|
||||
if cb.from_user.id in VERIFIED_ACCOUNTS:
|
||||
kb = admins.edit_product(product_id=product.id, category_id=product.category_id)
|
||||
else:
|
||||
order_item = await order_service.get_cart_product_amount(
|
||||
session, customer=cb.from_user.id, product_id=product_id
|
||||
)
|
||||
kb = render_product_interactions(
|
||||
product_id=product.id,
|
||||
category_id=product.category_id,
|
||||
show_cart=bool(order_item),
|
||||
cart_amount=order_item,
|
||||
)
|
||||
|
||||
if product.file_id:
|
||||
await cb.message.delete()
|
||||
@@ -78,24 +92,14 @@ async def product_card(
|
||||
msg = await cb.message.answer_photo(
|
||||
product.file_id,
|
||||
caption=get_product_description(product),
|
||||
reply_markup=render_product_interactions(
|
||||
product_id=product.id,
|
||||
category_id=product.category_id,
|
||||
show_cart=bool(order_item),
|
||||
cart_amount=order_item,
|
||||
),
|
||||
reply_markup=kb,
|
||||
)
|
||||
return
|
||||
|
||||
if not os.path.isfile(product.img_path):
|
||||
await cb.message.edit_text(
|
||||
get_product_description(product),
|
||||
reply_markup=render_product_interactions(
|
||||
product_id=product.id,
|
||||
category_id=product.category_id,
|
||||
show_cart=bool(order_item),
|
||||
cart_amount=order_item,
|
||||
),
|
||||
reply_markup=kb,
|
||||
)
|
||||
return
|
||||
|
||||
@@ -103,12 +107,7 @@ async def product_card(
|
||||
msg = await cb.message.answer_photo(
|
||||
FSInputFile(product.img_path),
|
||||
caption=get_product_description(product),
|
||||
reply_markup=render_product_interactions(
|
||||
product_id=product.id,
|
||||
category_id=product.category_id,
|
||||
show_cart=bool(order_item),
|
||||
cart_amount=order_item,
|
||||
),
|
||||
reply_markup=kb,
|
||||
)
|
||||
|
||||
if not msg.photo:
|
||||
@@ -120,7 +119,7 @@ async def product_card(
|
||||
|
||||
|
||||
@router.callback_query(F.data.startswith("cart_action:"))
|
||||
async def add_to_cart(
|
||||
async def cart_action(
|
||||
cb: CallbackQuery,
|
||||
state: FSMContext,
|
||||
session: AsyncSession,
|
||||
|
||||
Reference in New Issue
Block a user