5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'app/controllers/spree/settings_controller.rb', line 5
def update
new_locale = (params[:switch_to_locale] || params[:locale]).to_s
new_currency = params[:switch_to_currency]&.upcase
if new_currency.present? && supported_currency?(new_currency)
current_order&.update(currency: new_currency)
session[:currency] = new_currency
end
if new_locale.present? && supported_locale?(new_locale)
if try_spree_current_user && try_spree_current_user.selected_locale != new_locale
try_spree_current_user.update!(selected_locale: new_locale)
end
locale_for_slug = new_locale
new_locale = nil if new_locale.to_s == current_store.default_locale.to_s
if request.referer.present?
uri = URI(request.referer)
previous_params = begin
Spree::Core::Engine.routes.recognize_path(uri.path)
rescue ActionController::RoutingError
Rails.application.routes.recognize_path(uri.path)
end
redirect_to spree.root_path(locale: new_locale) && return if previous_params.blank?
new_params = previous_params.clone.merge(locale: new_locale)
new_params[:id] = find_slug_in_current_locale(previous_params, locale_for_slug)
redirect_to new_params
else
redirect_to spree.root_path(locale: new_locale)
end
else
redirect_to spree.root_path
end
end
|