spree/spree — pull request #5611 by HoyaBoya (2014-11-14 16:49:29+00:00)
Title: Better Handle of Destroyed Variants in Order Line Items

This PR tries to better handle an order checkout where there is a line item of a soft-deleted product over the API. The experience we are seeing is that a product gets soft-deleted, but there is no way for a) a user to remove it from their order due to an HTTP 422 on ```Variant.find``` b) any feedback that this they won't be able to checkout for this.

https://github.com/spree/spree/blob/master/api/app/controllers/spree/api/line_items_controller.rb#L27

To solve this, this PR introduces:
1) An unscoped on the API Line Items #delete controller method so that the item can be deleted
2) An is_removed field in the variant payload in orders#show so that the FE can tell the user they have N/A items in their cart.
3) Guard on the checkout state machine to insure there is no checkout with deleted variants before moving to complete.

I think this should be enough to prevent a checkout, inform the user, and let them take corrective action over the API when there are deleted variants in line items.

The alternative approach was to listen to a variant destroy and start purging line_items from incomplete orders...but this felt way more dangerous. Not sure.