From 4ec80f7c71e5ef5ea79e7c5ecde384a7b129c29b Mon Sep 17 00:00:00 2001 From: PSzyszkaSpark <44572993+PSzyszkaSpark@users.noreply.github.com> Date: Thu, 20 Feb 2020 14:15:15 +0100 Subject: [PATCH] [SD-613] Fixes redirect to paths after sign up (#478) * Fixes redirect to paths after sign in in user_registrations_controller.rb * Changes after_inactive_sign_up_path_for in user_registrations_controller.rb * Changes account_path to spree_account path in user_registrations_controller.rb --- .../spree/user_registrations_controller.rb | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/app/controllers/spree/user_registrations_controller.rb b/app/controllers/spree/user_registrations_controller.rb index 96241d745..05fb737b9 100644 --- a/app/controllers/spree/user_registrations_controller.rb +++ b/app/controllers/spree/user_registrations_controller.rb @@ -30,7 +30,7 @@ def create set_flash_message :notice, :signed_up sign_up(resource_name, resource) session[:spree_user_signup] = true - respond_with resource, location: after_sign_up_path_for(resource) + redirect_to_checkout_or_account_path(resource) else set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" expire_data_after_sign_in! @@ -80,6 +80,13 @@ def after_sign_up_path_for(resource) after_sign_in_redirect(resource) if is_navigational_format? end + def after_inactive_sign_up_path_for(resource) + scope = Devise::Mapping.find_scope!(resource) + router_name = Devise.mappings[scope].router_name + context = router_name ? send(router_name) : self + context.respond_to?(:login_path) ? context.login_path : "/login" + end + private def spree_user_params @@ -89,4 +96,14 @@ def spree_user_params def after_sign_in_redirect(resource_or_scope) stored_location_for(resource_or_scope) || account_path end + + def redirect_to_checkout_or_account_path(resource) + resource_path = after_sign_up_path_for(resource) + + if resource_path == spree.checkout_state_path(:address) + respond_with resource, location: spree.checkout_state_path(:address) + else + respond_with resource, location: spree.account_path + end + end end