Remove dead adopt_session_cart_for_user.py (replaced by glue/services/cart_adoption.py)
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 37s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 37s
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,6 @@ from .get_cart import get_cart
|
|||||||
from .identity import current_cart_identity
|
from .identity import current_cart_identity
|
||||||
from .total import total
|
from .total import total
|
||||||
from .clear_cart_for_order import clear_cart_for_order
|
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 .calendar_cart import get_calendar_cart_entries, calendar_total
|
||||||
from .check_sumup_status import check_sumup_status
|
from .check_sumup_status import check_sumup_status
|
||||||
from .page_cart import (
|
from .page_cart import (
|
||||||
|
|||||||
@@ -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
|
|
||||||
Reference in New Issue
Block a user