Sha256: 0834e91d1781b571cbddb4e1fe23ee81d9023890494c72c73e2fe7833b698cb0

Contents?: true

Size: 1.23 KB

Versions: 4

Compression:

Stored size: 1.23 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 spree.edit_admin_general_settings_path
      end

      def clear_cache
        Rails.cache.clear
        invoke_callbacks(:clear_cache, :after)
        head :no_content
      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

4 entries across 4 versions & 1 rubygems

Version Path
spree_backend-4.4.1 app/controllers/spree/admin/general_settings_controller.rb
spree_backend-4.4.0 app/controllers/spree/admin/general_settings_controller.rb
spree_backend-4.4.0.rc2 app/controllers/spree/admin/general_settings_controller.rb
spree_backend-4.4.0.rc1 app/controllers/spree/admin/general_settings_controller.rb