Yes, agreed, who the cart belongs to should not be discarded by doing '@cart.user_id = nil'. And fetching the latest cart of possibly many solves some problems.
So when a signed-in user purchases or clicks 'Empty cart', a new, empty cart would be created belonging to them. If they purchase nothing more, an empty cart remains in the database. There are not many users, so that's not a problem. The cart of a purchaser not signed in would be tied to the order record, as with all orders. The session would be cleared of the cart id. A new cart would be created when they next click on 'Add Item To Cart' or 'View Cart'. That works. For someone not signed in who clicks 'Empty cart', the cart would not be cleared of items (violating the rule), rather, a new cart would be created and its id put into the session. This will leave behind some empty, abandoned carts. C'est la vie. Thanks much, that's very helpful. Scott At 03:55 PM 12/6/2009, you wrote: >Scott Olmsted wrote: > > > > There's no 'Save For Later', and there's no 'Empty Cart' or 'Discard Cart'. > > > > While carts are never removed from the database, they are discarded > > after the gateway reports acceptance of the payment: > > > > @cart.user_id = nil > > @cart.save > >That breaks the rule "thou shalt not delete, overwrite, or destroy data". > >Ideally, a database - especially e-commerce related - should only add new >records. "Destroy" a cart by adding another one, and then the user only ever >sees the cart with the highest timestamp. Rails's model observers and named >scopes should make these features trivial to add. Should. > >Also, it might be time for the "got unit tests" question. RoR makes them sooo >tragically easy... > >-- > Phlip > http://c2.com/cgi/wiki?MoreliaViridis > >-- >SD Ruby mailing list >[email protected] >http://groups.google.com/group/sdruby -- SD Ruby mailing list [email protected] http://groups.google.com/group/sdruby
