Module: Spree::Order::AddressBook

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



26
27
28
29
# File 'app/models/spree/order/address_book.rb', line 26

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

#bill_address_id=(id) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'app/models/spree/order/address_book.rb', line 16

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
    bill_address.reload
  else
    self['bill_address_id'] = nil
  end
end

#clone_billing_addressObject



10
11
12
13
14
# File 'app/models/spree/order/address_book.rb', line 10

def clone_billing_address
  self.ship_address = bill_address if bill_address
  user.ship_address = bill_address if should_assign_user_default_address?(bill_address)
  true
end

#clone_shipping_addressObject



4
5
6
7
8
# File 'app/models/spree/order/address_book.rb', line 4

def clone_shipping_address
  self.bill_address = ship_address if ship_address
  user.bill_address = ship_address if should_assign_user_default_address?(ship_address)
  true
end

#ship_address_attributes=(attributes) ⇒ Object



41
42
43
44
45
# File 'app/models/spree/order/address_book.rb', line 41

def ship_address_attributes=(attributes)
  self.ship_address = update_or_create_address(attributes)
  user.ship_address = ship_address if should_assign_user_default_address?(ship_address)
  self.ship_address = nil if quick_checkout_address?(attributes[:quick_checkout]) && !ship_address.persisted?
end

#ship_address_id=(id) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'app/models/spree/order/address_book.rb', line 31

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
    ship_address.reload
  else
    self['ship_address_id'] = nil
  end
end