diff --git a/app/controllers/split_checkout_controller.rb b/app/controllers/split_checkout_controller.rb index 7cb2753f93..367552a0ba 100644 --- a/app/controllers/split_checkout_controller.rb +++ b/app/controllers/split_checkout_controller.rb @@ -15,6 +15,7 @@ class SplitCheckoutController < ::BaseController # Otherwise we fail on duplicate indexes or end up with negative stock. prepend_around_action CurrentOrderLocker, only: [:edit, :update] + prepend_before_action :set_checkout_step prepend_before_action :check_hub_ready_for_checkout prepend_before_action :check_order_cycle_expiry prepend_before_action :require_order_cycle @@ -35,7 +36,7 @@ class SplitCheckoutController < ::BaseController def edit return handle_redirect_from_stripe if valid_payment_intent_provided? - redirect_to_step if request.path == "/checkout" + redirect_to_step unless @checkout_step # This is only required because of spree_paypal_express. If we implement # a version of paypal that uses this controller, and more specifically @@ -80,15 +81,19 @@ class SplitCheckoutController < ::BaseController private + def set_checkout_step + @checkout_step = params[:step] + end + def redirect_to_step if @order.state == "payment" if true# order.has_no_payment_method_chosen? - redirect_to checkout_payment_method_path + redirect_to checkout_step_path(:payment) else - redirect_to checkout_order_summary_path + redirect_to checkout_step_path(:summary) end else - redirect_to checkout_your_details_path + redirect_to checkout_step_path(:details) end end diff --git a/app/views/split_checkout/_your_details.html.haml b/app/views/split_checkout/_details.html.haml similarity index 100% rename from app/views/split_checkout/_your_details.html.haml rename to app/views/split_checkout/_details.html.haml diff --git a/app/views/split_checkout/_form.html.haml b/app/views/split_checkout/_form.html.haml index 97ecc74ffb..84a1d12edd 100644 --- a/app/views/split_checkout/_form.html.haml +++ b/app/views/split_checkout/_form.html.haml @@ -2,10 +2,6 @@ = inject_available_payment_methods = inject_saved_credit_cards -= form_with url: update_checkout_path, model: @order, method: :put do |f| - - %div.checkout-step.medium-6 - - if current_page?(checkout_your_details_path) - = render 'split_checkout/your_details', f: f - - elsif current_page?(checkout_payment_method_path) - = render "split_checkout/payment_method", f: f +%div.checkout-step.medium-6 + = form_with url: checkout_update_path(@checkout_step), model: @order, method: :put do |f| + = render "split_checkout/#{@checkout_step}", f: f diff --git a/app/views/split_checkout/_payment_method.html.haml b/app/views/split_checkout/_payment.html.haml similarity index 93% rename from app/views/split_checkout/_payment_method.html.haml rename to app/views/split_checkout/_payment.html.haml index 4a5308ba8e..73e515a961 100644 --- a/app/views/split_checkout/_payment_method.html.haml +++ b/app/views/split_checkout/_payment.html.haml @@ -18,5 +18,5 @@ %div.checkout-submit = f.submit t("split_checkout.step2.submit"), class: "button primary", disabled: @terms_and_conditions_accepted == false || @platform_tos_accepted == false - %a.button.cancel{href: main_app.checkout_your_details_path} + %a.button.cancel{href: main_app.checkout_step_path(:details)} = t("split_checkout.step2.cancel") diff --git a/app/views/split_checkout/_tabs.html.haml b/app/views/split_checkout/_tabs.html.haml index 5a2849b6b9..3b29750a94 100644 --- a/app/views/split_checkout/_tabs.html.haml +++ b/app/views/split_checkout/_tabs.html.haml @@ -1,10 +1,10 @@ %div.flex - %div.columns.three.text-center.checkout-tab{"class": ("selected" if current_page?(checkout_your_details_path))} + %div.columns.three.text-center.checkout-tab{"class": ("selected" if @checkout_step == "details")} %span = t("split_checkout.your_details") - %div.columns.three.text-center.checkout-tab{"class": ("selected" if current_page?(checkout_payment_method_path))} + %div.columns.three.text-center.checkout-tab{"class": ("selected" if @checkout_step == "payment")} %span = t("split_checkout.payment_method") - %div.columns.three.text-center.checkout-tab{"class": ("selected" if current_page?(checkout_summary_path))} + %div.columns.three.text-center.checkout-tab{"class": ("selected" if @checkout_step == "summary")} %span = t("split_checkout.order_summary") diff --git a/config/routes.rb b/config/routes.rb index c0f68a28a9..6e42921cfa 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -71,11 +71,12 @@ 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 + + constraints step: /(details|payment|summary)/ do + get '/checkout/:step', to: 'split_checkout#edit', as: :checkout_step + put '/checkout/:step', to: 'split_checkout#update', as: :checkout_update + end + get '/checkout/paypal_payment/:order_id', to: 'split_checkout#paypal_payment', as: :paypal_payment end