From 36be224d9f6742c512c7f89d9583aab714534e89 Mon Sep 17 00:00:00 2001 From: Richard Wilson Date: Wed, 23 Sep 2015 13:48:33 -0700 Subject: [PATCH 1/2] Use the order updater to update the shipment state. We don't need to do this ourselves. Additionally a user may define hooks, which are run by the order updater that wouldn't get triggered whenever shipments are shipped, which is something worth knowing about. We also don't necessarily know that updating the shipment state shouldn't update other states or parts of the order. --- core/app/models/spree/order_shipping.rb | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/core/app/models/spree/order_shipping.rb b/core/app/models/spree/order_shipping.rb index 535fa9c2745..96813105000 100644 --- a/core/app/models/spree/order_shipping.rb +++ b/core/app/models/spree/order_shipping.rb @@ -74,7 +74,7 @@ def ship(inventory_units:, stock_location:, address:, shipping_method:, send_shipment_email(carton) if stock_location.fulfillable? && !suppress_mailer # e.g. digital gift cards that aren't actually shipped fulfill_order_stock_locations(stock_location) - update_order_state + @order.update! carton end @@ -85,14 +85,6 @@ def fulfill_order_stock_locations(stock_location) Spree::OrderStockLocation.fulfill_for_order_with_stock_location(@order, stock_location) end - def update_order_state - new_state = Spree::OrderUpdater.new(@order).update_shipment_state - @order.update_columns( - shipment_state: new_state, - updated_at: Time.now, - ) - end - def send_shipment_email(carton) Spree::CartonMailer.shipped_email(carton.id).deliver_later end From a1dd8582ebe7af449679a661808c5181301750fb Mon Sep 17 00:00:00 2001 From: Richard Wilson Date: Wed, 23 Sep 2015 14:27:42 -0700 Subject: [PATCH 2/2] Fully update the order after payments are saved. While we keep the intention of only updating the order when the order or payment is in a certain state, we shouldn't be doing this manually. The order updater exposes a method that's responsible for the total update of an order, a payment shouldn't know that shipments need to be updated when the payment is saved. Additionally, this bypasses the order updater hooks, which run as part of the update process, preventing users who rely on these hooks for information about when state changes may occur from using the hooks to accomplish that goal. --- core/app/models/spree/payment.rb | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/core/app/models/spree/payment.rb b/core/app/models/spree/payment.rb index 736f14f1e72..ac904f21e93 100644 --- a/core/app/models/spree/payment.rb +++ b/core/app/models/spree/payment.rb @@ -243,18 +243,8 @@ def invalidate_old_payments end def update_order - if completed? || void? - order.updater.update_payment_total - end - - if order.completed? - order.updater.update_payment_state - order.updater.update_shipments - order.updater.update_shipment_state - end - - if self.completed? || order.completed? - order.persist_totals + if order.completed? || completed? || void? + order.update! end end