Let's talk about shopping carts

by Derek Sivers

Related link: http://www.cdbaby.com



I think there is no such thing as a shopping cart.
A shopping cart is what we call the process of putting together an order.

When you put something in your shopping cart, what you're really doing is adding it to your order.
A shopping cart implies something in flux. Items being added, subtracted, changed. But it's still just an order.
Proof?

A shopping cart must follow the *exact* same rules as an order. Meaning:
* all discounts
* postage costs
* bundles
* coupons
* gift certificates

Every business rule you write that applies to the final order has to be exactly the same for a "shopping cart" or else the customer would be furious.
From a programmer's point of view, this means that the same code has to calculate an order-in-flux as it does a final order.
A shopping cart is an order. Not "a kind of" order. Not "like an" order. A shopping cart is an order.
There is no such thing as a shopping cart.

A final order is still not final
Example: a customer orders 3 items that are usually $10 each, but only $7 each if ordered together. The $21 order is shipped. The customer decides to return one of the items in the bundle. The back-end customer-service handling of the not-really-final order has to also use that same code to know that returning one brings the price of the other two back up to $10 each.

The common trait: a collection of things
Think of an Amazon wishlist. It's basically a "cart" from which you can add and subtract items. But it has no quantities and no prices.
What does it have in common with an order (a shopping cart)?
It's a person's collection of things.
It seems this should be a module, a mixin, an interface, an abstract. Something like that. (Sorry - all these object-oriented programming terms swimming in my head, and I get them confused.)

A shopping cart, an order, a wishlist, all have these functions/methods in common:
* add a thing to the collection
* delete a thing from the collection
* change quantity of a thing in the collection
* knows how many things are in the collection
* knows who is its owner (whether user_id, session_id, etc)
* show me all things in the collection

A non-quantitied collection (wishlist) will have this unique aspect:
* when you add a thing to the collection that is already in the collection, the quantity stays at 1
* a count of things just counts how many unique things - ignores quantity (has no concept of quantity)

A quantitied collection (not priced) will have this:
* when you add a thing to the collection that is already in the collection, the quantity increases by 1
* when you decrease the quantity of a thing to zero, the thing is removed from the collection
* a thing's quantity can be changed directly (change 1 of a thing to 15 of that thing)
* a summary count of items needs to take quantity in mind (sum of the quantities tells you how many things)

A priced-and-quantitied collection (shopping cart, order) will add this:
* a summary of price that includes quantities
* business rules for altering the price, based on the things in the collection (sales, quantity-discount, bundled-batches, etc)

We're still just dealing with the generic, here. Next time we'll get into what a CD Baby order (cart) needs to do.

Your thoughts on this?