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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
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.rbindex e70cd19f8e..3589428212 100644--- a/storefront/app/controllers/spree/checkout_controller.rb+++ b/storefront/app/controllers/spree/checkout_controller.rb@@ -22,7 +22,7 @@ module Spreebefore_action :remove_expired_gift_card, only: :edit- before_action :store_user_location, only: :edit+ before_action :store_location, only: :editafter_action :clean_analytics_session, only: :editafter_action :clear_checkout_completed_session, only: [:complete]@@ -152,14 +152,6 @@ module Spreeprivate- 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, etcdef load_order@@ -188,10 +180,10 @@ module Spreeredirect_to_cartelsif 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!enddiff --git a/storefront/app/controllers/spree/store_controller.rb b/storefront/app/controllers/spree/store_controller.rbindex 35a6fce0d7..dc319f9b56 100644--- a/storefront/app/controllers/spree/store_controller.rb+++ b/storefront/app/controllers/spree/store_controller.rb@@ -228,7 +228,11 @@ module Spreereturn 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)++ pathenddef redirect_to_cartdiff --git a/storefront/spec/controllers/spree/checkout_controller_spec.rb b/storefront/spec/controllers/spree/checkout_controller_spec.rbindex 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 doget :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+ endendcontext 'when guest checkout is not allowed' do