Class: Piggybak::Address

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/piggybak/address.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#is_shippingObject

Returns the value of attribute is_shipping.



19
20
21
# File 'app/models/piggybak/address.rb', line 19

def is_shipping
  @is_shipping
end

Instance Method Details

#admin_labelObject Also known as: display



25
26
27
28
29
30
31
32
33
34
# File 'app/models/piggybak/address.rb', line 25

def admin_label
  address = "#{self.firstname} #{self.lastname}<br />"
  address += "#{self.address1}<br />"
  if self.address2 && self.address2 != ''
    address += "#{self.address2}<br />"
  end
  address += "#{self.city}, #{self.state_display} #{self.zip}<br />"
  address += "#{self.country.name}"
  address
end

#document_address_changesObject

TODO: Fix this. It isn’t working.



42
43
44
45
46
47
48
49
# File 'app/models/piggybak/address.rb', line 42

def document_address_changes
  if self.order_billing.present? && self.changed?
    self.order_billing.recorded_changes << self.formatted_changes
  end
  if self.order_shipping.present? && self.changed?
    self.order_shipping.recorded_changes << self.formatted_changes
  end
end

#set_default_countryObject



21
22
23
# File 'app/models/piggybak/address.rb', line 21

def set_default_country
  self.country ||= Country.where(abbr: Piggybak.config.default_country).first
end

#state_displayObject



37
38
39
# File 'app/models/piggybak/address.rb', line 37

def state_display
  self.state ? self.state.name : self.state_id
end