Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Fix redirect path after the user logs in on the checkout page (#12666)

Damian Kaczmarczykc02420f50de9
diff --git a/storefront/app/controllers/spree/checkout_controller.rb b/storefront/app/controllers/spree/checkout_controller.rb
index e70cd19f8e..3589428212 100644
--- a/storefront/app/controllers/spree/checkout_controller.rb
+++ b/storefront/app/controllers/spree/checkout_controller.rb
@@ -22,7 +22,7 @@ module Spree
before_action :remove_expired_gift_card, only: :edit
- before_action :store_user_location, only: :edit
+ before_action :store_location, only: :edit
after_action :clean_analytics_session, only: :edit
after_action :clear_checkout_completed_session, only: [:complete]
@@ -152,14 +152,6 @@ module Spree
private
- def store_user_location
- if try_spree_current_user
- store_location
- else
- store_location(spree.cart_path)
- end
- end
-
# rather then using cookies like in old Spree we're going to fetch the order based on the
# token passed in the parameters, this allows us to share carts, send payment links, etc
def load_order
@@ -188,10 +180,10 @@ module Spree
redirect_to_cart
elsif try_spree_current_user.nil? && [email protected]?
if params[:guest] && current_store.prefers_guest_checkout?
- @order = current_store
- .orders
- .create!(current_order_params.except(:token, :user_id))
- .tap do |order|
+ @order = current_store.
+ orders.
+ create!(current_order_params.except(:token, :user_id)).
+ tap do |order|
order.merge!(@order, discard_merged: false)
order.disassociate_user!
end
diff --git a/storefront/app/controllers/spree/store_controller.rb b/storefront/app/controllers/spree/store_controller.rb
index 35a6fce0d7..dc319f9b56 100644
--- a/storefront/app/controllers/spree/store_controller.rb
+++ b/storefront/app/controllers/spree/store_controller.rb
@@ -228,7 +228,11 @@ module Spree
return unless defined?(after_sign_in_path_for)
return unless defined?(Devise)
- after_sign_in_path_for(Devise.mappings.keys.first)
+ path = after_sign_in_path_for(Devise.mappings.keys.first)
+
+ store_location(path)
+
+ path
end
def redirect_to_cart
diff --git a/storefront/spec/controllers/spree/checkout_controller_spec.rb b/storefront/spec/controllers/spree/checkout_controller_spec.rb
index 87297030ad..6ab435dd1e 100644
--- a/storefront/spec/controllers/spree/checkout_controller_spec.rb
+++ b/storefront/spec/controllers/spree/checkout_controller_spec.rb
@@ -81,6 +81,20 @@ describe Spree::CheckoutController, type: :controller do
get :edit, params: { token: order.token }
expect(response).to redirect_to(spree.checkout_state_path(order.token, 'address'))
end
+
+ context 'when Devise is installed' do
+ before do
+ allow(controller).to receive(:store_location_for)
+
+ stub_const('Devise', double(mappings: { user: nil }))
+ end
+
+ it 'saves the location so that we can redirect back after login' do
+ get :edit, params: { state: 'address', token: order.token }
+
+ expect(controller).to have_received(:store_location_for).with(:user, spree.checkout_state_path(order.token, 'address'))
+ end
+ end
end
context 'when guest checkout is not allowed' do