From 41ffffe17083c274d2944e7ea99d16815c2e5510 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Wed, 11 Aug 2021 16:19:42 +0100 Subject: [PATCH] Tidy up use of @checkout_step --- app/controllers/split_checkout_controller.rb | 7 +++---- app/helpers/checkout_helper.rb | 6 +++++- app/views/split_checkout/_form.html.haml | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/controllers/split_checkout_controller.rb b/app/controllers/split_checkout_controller.rb index d6974fb27e..b5fb482a49 100644 --- a/app/controllers/split_checkout_controller.rb +++ b/app/controllers/split_checkout_controller.rb @@ -15,7 +15,6 @@ 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 @@ -37,7 +36,7 @@ class SplitCheckoutController < ::BaseController def edit return handle_redirect_from_stripe if valid_payment_intent_provided? - redirect_to_step unless @checkout_step + 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 @@ -68,8 +67,8 @@ class SplitCheckoutController < ::BaseController private - def set_checkout_step - @checkout_step = params[:step] + def checkout_step + @checkout_step ||= params[:step] end def order_params diff --git a/app/helpers/checkout_helper.rb b/app/helpers/checkout_helper.rb index 3aefb48f4b..ad28194fae 100644 --- a/app/helpers/checkout_helper.rb +++ b/app/helpers/checkout_helper.rb @@ -123,7 +123,11 @@ module CheckoutHelper end end + def checkout_step + params[:step] + end + def checkout_step?(step) - params[:step] == step.to_s + checkout_step == step.to_s end end diff --git a/app/views/split_checkout/_form.html.haml b/app/views/split_checkout/_form.html.haml index 8aa242ae48..610fabdcf6 100644 --- a/app/views/split_checkout/_form.html.haml +++ b/app/views/split_checkout/_form.html.haml @@ -2,5 +2,5 @@ = inject_saved_credit_cards %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 + = form_with url: checkout_update_path(checkout_step), model: @order, method: :put do |f| + = render "split_checkout/#{checkout_step}", f: f