diff --git a/bp/cart/services/__init__.py b/bp/cart/services/__init__.py index a297bbc..16e4278 100644 --- a/bp/cart/services/__init__.py +++ b/bp/cart/services/__init__.py @@ -2,7 +2,6 @@ from .get_cart import get_cart from .identity import current_cart_identity from .total import total from .clear_cart_for_order import clear_cart_for_order -from .adopt_session_cart_for_user import adopt_session_cart_for_user from .calendar_cart import get_calendar_cart_entries, calendar_total from .check_sumup_status import check_sumup_status from .page_cart import ( diff --git a/bp/cart/services/adopt_session_cart_for_user.py b/bp/cart/services/adopt_session_cart_for_user.py deleted file mode 100644 index 7c143a2..0000000 --- a/bp/cart/services/adopt_session_cart_for_user.py +++ /dev/null @@ -1,46 +0,0 @@ -from sqlalchemy import select, update, func - -from market.models.market import CartItem - - -async def adopt_session_cart_for_user(session, user_id: int, session_id: str | None) -> None: - """ - When a user logs in or registers: - - If there are cart items for this anonymous session, take them over. - - Replace any existing cart items for this user with the anonymous cart. - """ - - if not session_id: - return - - # 1) Find anonymous cart items for this session - result = await session.execute( - select(CartItem) - .where( - CartItem.deleted_at.is_(None), - CartItem.user_id.is_(None), - CartItem.session_id == session_id, - ) - ) - anon_items = result.scalars().all() - if not anon_items: - # nothing to adopt - return - - # 2) Soft-delete any existing cart for this user - await session.execute( - update(CartItem) - .where( - CartItem.deleted_at.is_(None), - CartItem.user_id == user_id, - ) - .values(deleted_at=func.now()) - ) - - # 3) Reassign anonymous cart items to the user - for ci in anon_items: - ci.user_id = user_id - # optional: you can keep the session_id as well, but user_id will take precedence - # ci.session_id = session_id - - # No explicit commit here; caller's transaction will handle it