spree/spree — pull request #5585 by HoyaBoya (2014-11-07 22:40:43+00:00)
Title: Check Inventory And Restart Checkout If Insufficient

This PR tries to handle the case where at the final stages of checkout, inventory is sniped from the user. Currently, the validation below kicks in and the checkout stops. The order is left as 'complete' with no shipping or payments.

https://github.com/spree/spree/blob/master/core/app/models/spree/stock_item.rb#L11

Unfortunately the user can't recover the order and remove the offending items and re-checkout due to our API client implementation of not letting a user edit a "complete" order (which seems to be sensible). The end result is that the cart has just disappeared. :disappointed:

This PR attempts to fix this by making a call to ```ensure_line_items_are_in_stock``` before complete, and having that implementation re-set checkout so the state can go back to ```cart```. This should let the user make the appropriate changes.