From 0ea968a9004016d85c36ec411c55119c839577cd Mon Sep 17 00:00:00 2001 From: Andy Brett Date: Sat, 17 Jul 2021 15:09:32 -0700 Subject: [PATCH] add redirection to correct step --- app/controllers/split_checkout_controller.rb | 24 +++++++++++++++++--- config/routes.rb | 3 +++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/app/controllers/split_checkout_controller.rb b/app/controllers/split_checkout_controller.rb index 48f48b8f84..aef3a1fdfe 100644 --- a/app/controllers/split_checkout_controller.rb +++ b/app/controllers/split_checkout_controller.rb @@ -1,15 +1,17 @@ class SplitCheckoutController < CheckoutController + def edit + redirect_to_step if request.path == "/checkout" + super + end + def update - byebug params_adapter = Checkout::FormDataAdapter.new(permitted_params, @order, spree_current_user) return action_failed unless @order.update(params_adapter.params[:order] || {}) checkout_workflow(params_adapter.shipping_method_id, params[:advance_to_state] || "delivery") rescue Spree::Core::GatewayError => e - byebug rescue_from_spree_gateway_error(e) rescue StandardError => e - byebug flash[:error] = I18n.t("checkout.failed") action_failed(e) ensure @@ -18,9 +20,25 @@ class SplitCheckoutController < CheckoutController private + def redirect_to_step + if @order.state = "payment" + if @order.payment_method_id.nil? + redirect_to checkout_payment_method_path + else + redirect_to checkout_order_summary_path + end + elsif @order.state == "cart" + redirect_to checkout_your_details_path + end + end + def redirect_to_payment_gateway return unless params&.dig(:order)&.dig(:payments_attributes)&.first&.dig(:payments_attributes) super end + + def update_response + redirect_to checkout_payment_method_path + end end diff --git a/config/routes.rb b/config/routes.rb index 1e44f533d0..c0f68a28a9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -72,6 +72,9 @@ Openfoodnetwork::Application.routes.draw do constraints(SplitCheckoutConstraint.new) do get '/checkout', to: 'split_checkout#edit', as: :checkout put '/checkout', to: 'split_checkout#update', as: :update_checkout + get '/checkout/enter-your-details', to: 'split_checkout#edit', as: :checkout_your_details + get '/checkout/payment-method', to: 'split_checkout#edit', as: :checkout_payment_method + get '/checkout/order-summary', to: 'split_checkout#edit', as: :checkout_summary get '/checkout/:state', to: 'split_checkout#edit', as: :checkout_state get '/checkout/paypal_payment/:order_id', to: 'split_checkout#paypal_payment', as: :paypal_payment end