From b83ec8d3578ecabf304ec24b9b149d63f947ffe1 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Sun, 23 Dec 2018 00:23:49 +0000 Subject: [PATCH] Add order.shipments reload to line_item.update_inventory. This is necessary when destroying line items as update_inventory may delete the shipment from the order --- app/models/spree/line_item_decorator.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/models/spree/line_item_decorator.rb b/app/models/spree/line_item_decorator.rb index 2cb82c5761..7f17d57a7a 100644 --- a/app/models/spree/line_item_decorator.rb +++ b/app/models/spree/line_item_decorator.rb @@ -132,6 +132,10 @@ Spree::LineItem.class_eval do def update_inventory_with_scoping scoper.scope(variant) update_inventory_without_scoping + + # This is required because update_inventory may delete the last shipment in the order + # and that makes update_order fail if we don't reload the shipments relation here + order.shipments.reload end alias_method_chain :update_inventory, :scoping