Module: Spree::Order::AddressBook

Extended by:
ActiveSupport::Concern
Included in:
Spree::Order
Defined in:
app/models/spree/order/address_book.rb

Instance Method Summary collapse

Instance Method Details

#bill_address_attributes=(attributes) ⇒ Object



32
33
34
35
# File 'app/models/spree/order/address_book.rb', line 32

def bill_address_attributes=(attributes)
  self.bill_address = update_or_create_address(attributes)
  user.bill_address = bill_address if user
end

#bill_address_id=(id) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'app/models/spree/order/address_book.rb', line 21

def bill_address_id=(id)
  address = Spree::Address.find_by(id: id)
  if address && address.user_id == user_id
    self['bill_address_id'] = address.id
    user.update_attribute(:bill_address_id, address.id)
    bill_address.reload
  else
    self['bill_address_id'] = nil
  end
end

#clone_billing_addressObject



14
15
16
17
18
19
# File 'app/models/spree/order/address_book.rb', line 14

def clone_billing_address
  if bill_address
    self.ship_address = bill_address
  end
  true
end

#clone_shipping_addressObject



7
8
9
10
11
12
# File 'app/models/spree/order/address_book.rb', line 7

def clone_shipping_address
  if ship_address
    self.bill_address = ship_address
  end
  true
end

#ship_address_attributes=(attributes) ⇒ Object



48
49
50
51
# File 'app/models/spree/order/address_book.rb', line 48

def ship_address_attributes=(attributes)
  self.ship_address = update_or_create_address(attributes)
  user.ship_address = ship_address if user
end

#ship_address_id=(id) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'app/models/spree/order/address_book.rb', line 37

def ship_address_id=(id)
  address = Spree::Address.find_by(id: id)
  if address && address.user_id == user_id
    self['ship_address_id'] = address.id
    user.update_attribute(:ship_address_id, address.id)
    ship_address.reload
  else
    self['ship_address_id'] = nil
  end
end