Sha256: ab201d796af6b62db01b9c61f32804d2e594dfe627b815bee0d21e1e896fde30

Contents?: true

Size: 1.33 KB

Versions: 11

Compression:

Stored size: 1.33 KB

Contents

module Spree
  module Admin
    class GeneralSettingsController < Spree::Admin::BaseController
      include Spree::Backend::Callbacks

      before_action :update_currency_settings, only: :update

      def edit
        @preferences_security = []
      end

      def update
        params.each do |name, value|
          next unless Spree::Config.has_preference? name

          Spree::Config[name] = value
        end

        flash[:success] = Spree.t(:successfully_updated, resource: Spree.t(:general_settings))
        redirect_to edit_admin_general_settings_path
      end

      def clear_cache
        Rails.cache.clear
        invoke_callbacks(:clear_cache, :after)
        head :no_content
      end

      def render(*args)
        @preferences_currency |= [:show_store_selector]
        super
      end

      private

      def update_currency_settings
        params.each do |name, value|
          next unless Spree::Config.has_preference?(name) && name.eql?('supported_currencies')

          value = update_value(value)
          Spree::Config[name] = value
        end
      end

      def update_value(value)
        value.split(',').
          map { |curr| ::Money::Currency.find(curr.strip).try(:iso_code) }.
          concat([Spree::Config[:currency]]).
          uniq.
          compact.
          join(',')
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
spree_backend-4.2.7 app/controllers/spree/admin/general_settings_controller.rb
spree_backend-4.2.6 app/controllers/spree/admin/general_settings_controller.rb
spree_backend-4.2.5 app/controllers/spree/admin/general_settings_controller.rb
spree_backend-4.2.4 app/controllers/spree/admin/general_settings_controller.rb
spree_backend-4.2.3.1 app/controllers/spree/admin/general_settings_controller.rb
spree_backend-4.2.3 app/controllers/spree/admin/general_settings_controller.rb
spree_backend-4.2.2 app/controllers/spree/admin/general_settings_controller.rb
spree_backend-4.2.1 app/controllers/spree/admin/general_settings_controller.rb
spree_backend-4.2.0 app/controllers/spree/admin/general_settings_controller.rb
spree_backend-4.2.0.rc5 app/controllers/spree/admin/general_settings_controller.rb
spree_backend-4.2.0.rc4 app/controllers/spree/admin/general_settings_controller.rb