Sha256: ae5f91b30cac25d3d8a8cdb50bdf41e6c09b2c31a0480647922a69f6bb2ba671

Contents?: true

Size: 1.17 KB

Versions: 11

Compression:

Stored size: 1.17 KB

Contents

module Spree
  module UserAddress
    extend ActiveSupport::Concern

    included do
      belongs_to :bill_address, foreign_key: :bill_address_id, class_name: 'Spree::Address',
                 optional: true
      alias_attribute :billing_address, :bill_address

      belongs_to :ship_address, foreign_key: :ship_address_id, class_name: 'Spree::Address',
                 optional: true
      alias_attribute :shipping_address, :ship_address

      accepts_nested_attributes_for :ship_address, :bill_address

      def persist_order_address(order)
        b_address = self.bill_address || self.build_bill_address
        b_address.attributes = order.bill_address.attributes.except('id', 'updated_at', 'created_at')
        b_address.save
        self.update_attributes(bill_address_id: b_address.id)

        # May not be present if delivery step has been removed
        if order.ship_address
          s_address = self.ship_address || self.build_ship_address
          s_address.attributes = order.ship_address.attributes.except('id', 'updated_at', 'created_at')
          s_address.save
          self.update_attributes(ship_address_id: s_address.id)
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
spree_core-3.3.6 app/models/concerns/spree/user_address.rb
spree_core-3.3.5 app/models/concerns/spree/user_address.rb
spree_core-3.3.4 app/models/concerns/spree/user_address.rb
spree_core-3.3.3 app/models/concerns/spree/user_address.rb
spree_core-3.3.2 app/models/concerns/spree/user_address.rb
spree_core-3.3.1 app/models/concerns/spree/user_address.rb
spree_core-3.3.0 app/models/concerns/spree/user_address.rb
spree_core-3.3.0.rc4 app/models/concerns/spree/user_address.rb
spree_core-3.3.0.rc3 app/models/concerns/spree/user_address.rb
spree_core-3.3.0.rc2 app/models/concerns/spree/user_address.rb
spree_core-3.3.0.rc1 app/models/concerns/spree/user_address.rb