From 61686fd70cb17ac52000bfc013ff298c18fbf2b4 Mon Sep 17 00:00:00 2001 From: giles Date: Sat, 14 Feb 2026 19:38:18 +0000 Subject: [PATCH] Remove dead login_helper.py (replaced by glue/services/cart_adoption.py) Co-Authored-By: Claude Opus 4.6 --- bp/cart/login_helper.py | 57 ----------------------------------------- 1 file changed, 57 deletions(-) delete mode 100644 bp/cart/login_helper.py diff --git a/bp/cart/login_helper.py b/bp/cart/login_helper.py deleted file mode 100644 index 8d2134c..0000000 --- a/bp/cart/login_helper.py +++ /dev/null @@ -1,57 +0,0 @@ -# app/cart_merge.py - -from __future__ import annotations - -from quart import g, session as qsession -from sqlalchemy import select -from typing import Optional - -from market.models.market import CartItem - - -async def merge_anonymous_cart_into_user(user_id: int) -> None: - """ - When a user logs in, move any anonymous cart (session_id) items onto their user_id. - """ - sid: Optional[str] = qsession.get("cart_sid") - if not sid: - return - - # get all anon cart items for this session - anon_items = ( - await g.s.execute( - select(CartItem).where( - CartItem.deleted_at.is_(None), - CartItem.session_id == sid, - ) - ) - ).scalars().all() - if not anon_items: - return - - # Existing user items keyed by product_id for quick merge - user_items_by_product = { - ci.product_id: ci - for ci in ( - await g.s.execute( - select(CartItem).where( - CartItem.deleted_at.is_(None), - CartItem.user_id == user_id, - ) - ) - ).scalars().all() - } - - for anon in anon_items: - existing = user_items_by_product.get(anon.product_id) - if existing: - # merge quantities then soft-delete the anon row - existing.quantity += anon.quantity - anon.deleted_at = func.now() - else: - # reassign anonymous cart row to this user - anon.user_id = user_id - anon.session_id = None - - # clear the anonymous session id now that it's "claimed" - qsession.pop("cart_sid", None)