Sha256: 21abb88e22b84f01bf6de69930e529b56d764ed302d7acbcae26bdc69fa472d1

Contents?: true

Size: 846 Bytes

Versions: 17

Compression:

Stored size: 846 Bytes

Contents

module Spree
  module Addresses
    class Update
      prepend Spree::ServiceModule::Base
      include Spree::Addresses::Helper

      attr_accessor :country

      def call(address:, address_params:)
        address_params[:country_id] ||= address.country_id
        address_params = fill_country_and_state_ids(address_params)

        if address&.editable?
          address.update(address_params) ? success(address) : failure(address)
        else
          if new_address(address_params).valid?
            address.destroy
            success(new_address)
          else
            failure(new_address)
          end
        end
      end

      private

      def new_address(address_params = {})
        @new_address ||= ::Spree::Address.find_or_create_by(address_params.except(:id, :updated_at, :created_at))
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
spree_core-4.7.3 app/services/spree/addresses/update.rb
spree_core-4.6.6 app/services/spree/addresses/update.rb
spree_core-4.5.5 app/services/spree/addresses/update.rb
spree_core-4.5.4 app/services/spree/addresses/update.rb
spree_core-4.6.5 app/services/spree/addresses/update.rb
spree_core-4.7.2 app/services/spree/addresses/update.rb
spree_core-4.7.1 app/services/spree/addresses/update.rb
spree_core-4.6.4 app/services/spree/addresses/update.rb
spree_core-4.7.0 app/services/spree/addresses/update.rb
spree_core-4.6.3 app/services/spree/addresses/update.rb
spree_core-4.6.2 app/services/spree/addresses/update.rb
spree_core-4.6.1 app/services/spree/addresses/update.rb
spree_core-4.6.0 app/services/spree/addresses/update.rb
spree_core-4.5.3 app/services/spree/addresses/update.rb
spree_core-4.5.2 app/services/spree/addresses/update.rb
spree_core-4.5.1 app/services/spree/addresses/update.rb
spree_core-4.5.0 app/services/spree/addresses/update.rb