Sha256: 6310477a1b59ee4a4c1cda03a07f66d1911d972d023a54e39a0c007c03f5f90a

Contents?: true

Size: 984 Bytes

Versions: 14

Compression:

Stored size: 984 Bytes

Contents

module Spree
  module Account
    module Addresses
      class Base
        prepend Spree::ServiceModule::Base

        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

14 entries across 14 versions & 1 rubygems

Version Path
spree_core-4.0.9 app/services/spree/account/addresses/base.rb
spree_core-4.1.15 app/services/spree/account/addresses/base.rb
spree_core-4.1.14 app/services/spree/account/addresses/base.rb
spree_core-4.0.8 app/services/spree/account/addresses/base.rb
spree_core-4.1.13.1 app/services/spree/account/addresses/base.rb
spree_core-4.0.7.1 app/services/spree/account/addresses/base.rb
spree_core-4.0.7 app/services/spree/account/addresses/base.rb
spree_core-4.1.13 app/services/spree/account/addresses/base.rb
spree_core-4.0.6 app/services/spree/account/addresses/base.rb
spree_core-4.2.0.rc2 app/services/spree/account/addresses/base.rb
spree_core-4.1.12 app/services/spree/account/addresses/base.rb
spree_core-4.2.0.rc1 app/services/spree/account/addresses/base.rb
spree_core-4.1.11 app/services/spree/account/addresses/base.rb
spree_core-4.1.10 app/services/spree/account/addresses/base.rb