Sha256: ea93ac34600e3882a8fc4d195fa4f50ee6d1dedbee25e80d64db19c7c0533cd3

Contents?: true

Size: 809 Bytes

Versions: 9

Compression:

Stored size: 809 Bytes

Contents

module Spree
  class LocaleController < Spree::StoreController
    def index
      render :index, layout: false
    end

    def set
      new_locale = (params[:switch_to_locale] || params[:locale]).to_s

      if new_locale.present? && supported_locale?(new_locale)
        if should_build_new_url?
          redirect_to BuildLocalizedRedirectUrl.call(
            url: request.env['HTTP_REFERER'],
            locale: new_locale,
            default_locale: current_store.default_locale
          ).value
        else
          redirect_to root_path(locale: new_locale)
        end
      else
        redirect_to root_path
      end
    end

    private

    def should_build_new_url?
      request.env['HTTP_REFERER'].present? && request.env['HTTP_REFERER'] != request.env['REQUEST_URI']
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
spree_frontend-4.2.7 app/controllers/spree/locale_controller.rb
spree_frontend-4.2.6 app/controllers/spree/locale_controller.rb
spree_frontend-4.2.5 app/controllers/spree/locale_controller.rb
spree_frontend-4.2.4 app/controllers/spree/locale_controller.rb
spree_frontend-4.2.3.1 app/controllers/spree/locale_controller.rb
spree_frontend-4.2.3 app/controllers/spree/locale_controller.rb
spree_frontend-4.2.2 app/controllers/spree/locale_controller.rb
spree_frontend-4.2.1 app/controllers/spree/locale_controller.rb
spree_frontend-4.2.0 app/controllers/spree/locale_controller.rb