Method: Spree::UserAddressBook#persist_order_address

Defined in:
app/models/concerns/spree/user_address_book.rb

#persist_order_address(order) ⇒ Object

saves order.ship_address and order.bill_address in address book sets ship_address to the default if automatic_default_address is set to true sets bill_address to the default if automatic_default_address is set to true and there is no ship_address if one address is nil, does not save that address



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'app/models/concerns/spree/user_address_book.rb', line 93

def persist_order_address(order)
  if order.ship_address
    address = save_in_address_book(
      order.ship_address.attributes,
      Spree::Config.automatic_default_address
    )
    self.ship_address_id = address.id if address&.persisted?
  end

  if order.bill_address
    address = save_in_address_book(
      order.bill_address.attributes,
      Spree::Config.automatic_default_address,
      :billing
    )
    self.bill_address_id = address.id if address&.persisted?
  end

  save! # In case the ship_address_id or bill_address_id was set
end