Sha256: e9546fd2bac0b04f60b77bffea9060c2c757b6b7f89c20dd0f002b66108c9ff9

Contents?: true

Size: 943 Bytes

Versions: 12

Compression:

Stored size: 943 Bytes

Contents

module Spree
  module Account
    module Addresses
      module Helper
        private

        attr_accessor :country

        def fill_country_and_state_ids(params)
          replace_country_iso_with_id(params)
          fill_state_id(params)
        end

        def replace_country_iso_with_id(params)
          iso = params[:country_iso]
          return params unless iso.present?

          country = Spree::Country.by_iso(iso)
          params[:country_id] = country&.id
          params.delete(:country_iso)
          params
        end

        def fill_state_id(params)
          state_name = params[:state_name]
          return params unless state_name.present?

          country ||= Spree::Country.find(params[:country_id]) if params[:country_id].present?
          return params unless country

          params[:state_id] = country.states.find_by(name: state_name)&.id
          params
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
spree_core-4.2.7 app/services/spree/account/addresses/helper.rb
spree_core-4.2.6 app/services/spree/account/addresses/helper.rb
spree_core-4.2.5 app/services/spree/account/addresses/helper.rb
spree_core-4.2.4 app/services/spree/account/addresses/helper.rb
spree_core-4.2.3.1 app/services/spree/account/addresses/helper.rb
spree_core-4.2.3 app/services/spree/account/addresses/helper.rb
spree_core-4.2.2 app/services/spree/account/addresses/helper.rb
spree_core-4.2.1 app/services/spree/account/addresses/helper.rb
spree_core-4.2.0 app/services/spree/account/addresses/helper.rb
spree_core-4.2.0.rc5 app/services/spree/account/addresses/helper.rb
spree_core-4.2.0.rc4 app/services/spree/account/addresses/helper.rb
spree_core-4.2.0.rc3 app/services/spree/account/addresses/helper.rb