Simplify routes and partials

This commit is contained in:
Matt-Yorkley
2021-08-01 09:42:11 +01:00
committed by Jean-Baptiste Bellet
parent aba3cf99a3
commit a32ca23ca5
6 changed files with 22 additions and 20 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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")

View File

@@ -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")

View File

@@ -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