Refactor updating order state

It makes the code a bit easier to read
This commit is contained in:
Gaetan Craig-Riou
2023-10-20 16:40:02 +11:00
parent 5ba21e486a
commit 25af178011
4 changed files with 28 additions and 14 deletions

View File

@@ -23,10 +23,12 @@ class SplitCheckoutController < ::BaseController
before_action :hide_ofn_navigation, only: [:edit, :update]
def edit
redirect_to_step_based_on_order unless params[:step]
update_order_state if params[:step]
check_step if params[:step]
if params[:step].blank?
redirect_to_step_based_on_order
else
update_order_state
check_step
end
return if available_shipping_methods.any?
@@ -128,4 +130,15 @@ class SplitCheckoutController < ::BaseController
def order_params
@order_params ||= Checkout::Params.new(@order, params, spree_current_user).call
end
# Update order state based on the step we are loading to avoid discrepancy between step and order
# state. We need to do this when moving back to a previous checkout step, the update action takes
# care of moving the order state forward.
def update_order_state
return @order.back_to_payment if @order.confirmation? && payment_step?
return unless @order.after_delivery_state? && details_step?
@order.back_to_address
end
end