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.

Add `Admin::BaseController#set_return_to`

Damian Legawiec8fa924317d49
diff --git a/admin/app/controllers/spree/admin/base_controller.rb b/admin/app/controllers/spree/admin/base_controller.rb
index f06ab5f952..81cc7931a8 100644
--- a/admin/app/controllers/spree/admin/base_controller.rb
+++ b/admin/app/controllers/spree/admin/base_controller.rb
@@ -17,6 +17,7 @@ module Spree
helper 'spree/currency'
before_action :authorize_admin
+ after_action :set_return_to, only: [:index]
protected
@@ -86,6 +87,24 @@ module Spree
def current_vendor
nil
end
+
+ def set_return_to
+ return unless defined?(model_class)
+ return unless request.format.html?
+
+ clear_return_to
+
+ session_key = "#{model_class.to_s.demodulize.pluralize.downcase}_return_to".to_sym
+ session[session_key] = "#{request.path}?#{request.query_string}"
+ rescue ActionDispatch::Cookies::CookieOverflow
+ clear_return_to
+ end
+
+ def clear_return_to
+ session.keys.find_all { |k| k.ends_with?('_return_to') }.each do |k|
+ session.delete(k)
+ end
+ end
end
end
end