relationship of shopping cart and order

Most implementations of shopping carts I have seen is that a user stores line items in a cart, where the line items represent products or subscriptions. So a cart has many products through line items and a product can have many carts through line items. Then a customer makes an order and so you introduce a new model order. The order has information such as customer's name, the payment type, and if you are working with a payment gateway, such as paypal, it will contain paypal tokens and recurring tokens. So the order and the cart are two different models, two different purposes. Cart is a thing that enables a customer to store things in, and a order is the thing that handles payments. So I was watching this railscasts and he updates a purchased_at attribute on the cart itself:

But is a cart really purchased, or is it the order that is purchased? If the order contains all payment information, shouldn't the order contain the purchased_at attribute and not the cart?

It important to keep in mind that the episode is focused on PayPal notifications, not describing a fully fleshed out e-commerce domain model. Spree[1] provides a better example of a fully implemented domain model. In Spree, the concept of a ‘cart’ is implemented using a current order. When an item is added to the ‘cart’, it’s actually added to the current order in progress. I guess it’s not that different from the RailsCast example, where cart == order. In the past, when developing custom commerce platforms I have tried it both ways: creating a cart and then migrating it to an order when purchased; and just working with an order throughout. Using one domain model, order with lifecycle states, is a lot simpler.

[1] http://www.spreecommerce.com