Either way, you know the shopper is finished when they go to check out and
pay. Maybe you mean, when do you delete the records from the DB? I would
just leave them there. It is good to have a record of abandoned shopping
carts.
One way is a simple list append: session.cart_items.append({'id':789
,'qty':1})
But you may need to do more programming such as to handle adding an item to
the cart that is already in the cart, deleting items, etc. But this should
all just be basic Python list handling. You're just storing a list in the
shopper's session cookie.