From c7f7e420eab75bace1106bda18ecfc33e66413a0 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 5 Jul 2018 16:34:11 +1000 Subject: [PATCH 1/2] Skip shipment creation for payment step https://github.com/openfoodfoundation/openfoodnetwork/issues/2007 Spree 2.0.4 creates in-memory shipments for the payment step. That means we don't need to create a shipment in that transition. This change copies the checkout_flow from the Spree code, but leaves one last customisation: removal of the confirm step. https://github.com/openfoodfoundation/openfoodnetwork/commit/75ec77dc31de2c57514948211755a05356eab938 --- app/models/spree/order_decorator.rb | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index c6def73d68..10cabd124a 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -30,20 +30,14 @@ Spree::Order.class_eval do checkout_flow do go_to_state :address go_to_state :delivery - go_to_state :payment, :if => lambda { |order| - # Fix for #2191 - if order.shipping_method.andand.delivery? - if order.ship_address.andand.valid? - order.create_shipment! - order.update_totals - end - end + go_to_state :payment, if: ->(order) { + order.update_totals order.payment_required? } # NOTE: :confirm step was removed because we were not actually using it # go_to_state :confirm, :if => lambda { |order| order.confirmation_required? } go_to_state :complete - remove_transition :from => :delivery, :to => :confirm + remove_transition from: :delivery, to: :confirm end # -- Scopes From 2334f0854caa1b74fdd28a11e892e3ab7421b0b1 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 11 Jul 2018 10:55:12 +1000 Subject: [PATCH 2/2] Less invasive modifying the checkout state machine --- app/models/spree/order_decorator.rb | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/app/models/spree/order_decorator.rb b/app/models/spree/order_decorator.rb index 10cabd124a..eed4cefd0b 100644 --- a/app/models/spree/order_decorator.rb +++ b/app/models/spree/order_decorator.rb @@ -27,18 +27,10 @@ Spree::Order.class_eval do before_save :update_shipping_fees!, if: :complete? before_save :update_payment_fees!, if: :complete? - checkout_flow do - go_to_state :address - go_to_state :delivery - go_to_state :payment, if: ->(order) { - order.update_totals - order.payment_required? - } - # NOTE: :confirm step was removed because we were not actually using it - # go_to_state :confirm, :if => lambda { |order| order.confirmation_required? } - go_to_state :complete - remove_transition from: :delivery, to: :confirm - end + # Orders are confirmed with their payment, we don't use the confirm step. + # Here we remove that step from Spree's checkout state machine. + # See: https://guides.spreecommerce.org/developer/checkout.html#modifying-the-checkout-flow + remove_checkout_step :confirm # -- Scopes scope :managed_by, lambda { |user|