Order Object Workflow through Checkout
I was having this discussion in IRC with DamZ, neclimdul, and one other person about how to handle the creation, update, and saving of the order object through checkout. In Ubercart, the workflow was as follows:
- View the checkout page, nothing is there. Any code that needed an order object would construct it on the fly using the cart contents.
- Submit the checkout page and an order was created with the ID stuffed into the session. The order status was "In Checkout" and it had an order ID and would be used for displaying the review page or setting default values on the checkout form if the customer went back.
- Complete the sale and the order status would get updated at least to Pending and maybe further depending on Conditional Actions.
The method it sounded like neclimdul implemented for e-Commerce 3.x and DamZ had implemented through a modified UC Advanced Checkout module was to create a cached order object at the beginning of checkout. It would have as many default values as possible, including a default address from the address book. As the customer went through checkout, it would be filled in, until upon checkout completion it would be saved. This served the advantage of not messing up the sequence of order IDs with data from people who bail on the checkout process. However, I pointed out the advantage of keeping the data around for the purposes of following up with potential customers to make sales.
As we discussed, this can be easily implemented as a contributed module working through the process neclimdul / DamZ were describing. I think it best to go this route and am interested in feedback. I'll be porting the Advanced Checkout module as a starting point for the Drupal Commerce checkout system, as it already tackles the definition of checkout panes and placement of panes onto checkout pages (single or multiple) with an optional review step.
- The shopping cart object extends the order object and supplies default values on load for the products in the cart. This happens on the fly at pageload, though I suppose we can even cache this cart object in the session or at least for logged in users.
- When the user comes into checkout, we instantiate an order that then is further filled out through the checkout process.
- Upon checkout completion, the order object is saved. If checkout is canceled or the cached order object is deleted, provide a hook for modules to capture the data for later use.
This is obviously very rough and needs to be fleshed out further, so all feedback is welcome.