E-commerce Classes/Controllers/Flow
I’m looking for some solid best practices for e-commerce flow (classes, controllers), as I seem to approach it differently on almost every project. And even after looking through lots of open source packages, I still don’t see any clear conventions.
Say I have a ShoppingCart object that is stored in the session. I have a CartController that exposes methods for adding/removing items, changing quantities, etc., and a ‘cart’ page for displaying the contents of the cart, with links to “continue shopping“ or “checkout”. Very straightforward and simple e-store 101.
But here is where the whole “checkout” process always gets a bit nebulous to me...
- Should the cart have knowledge of ship-to/bill-to addresses, coupon codes, shipping methods, etc.? On one hand, it seems that it should only know about the basket of goods; but on the other hand, it’s nice to be able to display that meta info back to the customer.
- Which controllers and classes would be responsible for managing the intermediate data like customer addresses, coupons, shipping methods, etc.? (Assume we allow for guest checkout.)
- At what point should the cart get converted into an
Order? Only after successful payment, or as soon as the payment attempt is submitted (i.e. as 'incomplete' or 'unpaid')? Or at some other point altogether?
I realize that many of the answers will depend on the project requirements (which is why I always feel like I’m reinventing a wheel), but I’d love to hear how some of you handle it in a simple, reusable manner.
Please or to participate in this conversation.