Modify cart items
This commit is contained in:
@@ -78,8 +78,43 @@ async def add_to_cart(request: Request, session: SessionDep, user: UserDep):
|
||||
)
|
||||
|
||||
|
||||
@shop_router.get("/shop/cart/remove/{item_id}")
|
||||
async def remove_from_cart(
|
||||
request: Request, session: SessionDep, user: UserDep, item_id: int
|
||||
):
|
||||
|
||||
cart = user.shopping_cart
|
||||
for item in cart.items:
|
||||
if item.id == item_id:
|
||||
item.order = None
|
||||
session.delete(item)
|
||||
break
|
||||
else:
|
||||
raise HTTPException(status_code=404, detail="Item not found in cart.")
|
||||
|
||||
return RedirectResponse(url=f"/shop/cart", status_code=status.HTTP_302_FOUND)
|
||||
|
||||
|
||||
@shop_router.post("/shop/cart/update/{item_id}")
|
||||
async def update_cart_item(
|
||||
request: Request, session: SessionDep, user: UserDep, item_id: int
|
||||
):
|
||||
|
||||
form_data = await request.form()
|
||||
|
||||
cart = user.shopping_cart
|
||||
for item in cart.items:
|
||||
if item.id == item_id:
|
||||
item.update_quantity(Decimal(form_data["quantity"]))
|
||||
break
|
||||
else:
|
||||
raise HTTPException(status_code=404, detail="Item not found in cart.")
|
||||
|
||||
return RedirectResponse(url=f"/shop/cart", status_code=status.HTTP_302_FOUND)
|
||||
|
||||
|
||||
@shop_router.get("/shop/order/{order_id}")
|
||||
async def add_to_cart(
|
||||
async def get_order_details(
|
||||
request: Request, session: SessionDep, user: UserDep, order_id: int
|
||||
):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user