separated clients handlers, cart->checkout ppline
This commit is contained in:
@@ -6,6 +6,10 @@ from aiogram.utils.keyboard import InlineKeyboardBuilder
|
||||
from db.models import Category, Product
|
||||
from dto.cart import CartItemDTO
|
||||
|
||||
return_menu = InlineKeyboardBuilder(
|
||||
[[InlineKeyboardButton(text="⬅️ В меню", callback_data="menu:main")]]
|
||||
).as_markup()
|
||||
|
||||
|
||||
def pagination_row(
|
||||
*,
|
||||
@@ -15,6 +19,9 @@ def pagination_row(
|
||||
) -> list[InlineKeyboardButton]:
|
||||
row = []
|
||||
|
||||
if not (prev_cb or next_cb):
|
||||
return row
|
||||
|
||||
if prev_cb:
|
||||
row.append(InlineKeyboardButton(text="⬅️", callback_data=prev_cb))
|
||||
|
||||
@@ -161,7 +168,7 @@ def render_cart(
|
||||
) -> InlineKeyboardMarkup:
|
||||
btns = [
|
||||
InlineKeyboardButton(
|
||||
text=f"{cart_item.quantity} | {cart_item.name} | {cart_item.total}₽",
|
||||
text=f"🛒 {cart_item.quantity} | {cart_item.name} | {cart_item.total}₽",
|
||||
callback_data=f"product:{cart_item.product_id}",
|
||||
)
|
||||
for cart_item in cart_items
|
||||
@@ -184,4 +191,33 @@ def render_cart(
|
||||
]
|
||||
+ [btns[i : i + 2] for i in range(0, len(cart_items), 2)]
|
||||
+ [nav]
|
||||
+ [[InlineKeyboardButton(text="🔷 Оформить заказ", callback_data="checkout")]]
|
||||
).as_markup()
|
||||
|
||||
|
||||
def order_confirmation(order_id: int) -> InlineKeyboardMarkup:
|
||||
return InlineKeyboardBuilder(
|
||||
[
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text="🟢 Подтвердить заказ",
|
||||
callback_data=f"confirm_order:{order_id}",
|
||||
)
|
||||
],
|
||||
[InlineKeyboardButton(text="❌ Отменить", callback_data="menu:main")],
|
||||
]
|
||||
).as_markup()
|
||||
|
||||
|
||||
def order_specs_confirmation(order_id: int) -> InlineKeyboardMarkup:
|
||||
return InlineKeyboardBuilder(
|
||||
[
|
||||
[
|
||||
InlineKeyboardButton(
|
||||
text="🟢 Перейти к оплате",
|
||||
callback_data=f"payment:{order_id}",
|
||||
)
|
||||
],
|
||||
[InlineKeyboardButton(text="❌", callback_data="menu:main")],
|
||||
]
|
||||
).as_markup()
|
||||
|
||||
7
misc/states.py
Normal file
7
misc/states.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from aiogram.fsm.state import StatesGroup, State
|
||||
|
||||
|
||||
class CheckoutStorage(StatesGroup):
|
||||
name = State()
|
||||
phone = State()
|
||||
address = State()
|
||||
@@ -1,4 +1,5 @@
|
||||
from db.models import Product
|
||||
from dto.cart import CartDTO
|
||||
|
||||
|
||||
def get_product_description(product: Product) -> str:
|
||||
@@ -7,3 +8,18 @@ def get_product_description(product: Product) -> str:
|
||||
output += f"\n\n📜 {product.description}"
|
||||
|
||||
return output
|
||||
|
||||
|
||||
def get_order_item_list(cart: CartDTO):
|
||||
text = "🛍 Состав заказа:\n"
|
||||
for i, product in enumerate(cart.items):
|
||||
text += f"\n{i+1}. <b>{product.name}</b>\n•\t<i>{product.quantity} × {product.price} = {product.total}₽</i>\n"
|
||||
|
||||
text += f"\n━━━━━━━━━━━━━━\n💰 Итого: {cart.total}₽"
|
||||
|
||||
return text
|
||||
|
||||
|
||||
# def get_order_notification(cart: CartDTO):
|
||||
# text
|
||||
# FIXME
|
||||
|
||||
10
misc/utils.py
Normal file
10
misc/utils.py
Normal file
@@ -0,0 +1,10 @@
|
||||
import phonenumbers
|
||||
from phonenumbers import NumberParseException
|
||||
|
||||
|
||||
def is_valid_phone(phone: str, region="RU") -> bool:
|
||||
try:
|
||||
parsed = phonenumbers.parse(phone, region)
|
||||
return phonenumbers.is_valid_number(parsed)
|
||||
except NumberParseException:
|
||||
return False
|
||||
Reference in New Issue
Block a user