3 include DataMapper::Persistable
9 #t.integer "order_user_id", :default => 0, :null => false
11 property :first_name, :string, :length => 50, :default => "", :nullable => false
12 property :last_name, :string, :length => 50, :default => "", :nullable => false
13 property :telephone, :string, :length => 20
14 property :address, :string, :default => "", :nullable => false
15 property :city, :string, :length => 50
16 property :state, :string, :length => 30
17 property :zip, :string, :length => 10
20 #validates_presence_of :order_user_id, :country_id
21 #validates_presence_of :zip, :message => "#{ERROR_EMPTY} If you live in a country that doesn't have postal codes please enter '00000'."
22 #validates_presence_of :telephone, :message => ERROR_EMPTY
23 #validates_presence_of :first_name, :message => ERROR_EMPTY
24 #validates_presence_of :last_name, :message => ERROR_EMPTY
25 #validates_presence_of :address, :message => ERROR_EMPTY
27 #validates_length_of :first_name, :maximum => 50
28 #validates_length_of :last_name, :maximum => 50
29 #validates_length_of :address, :maximum => 255
31 #validates_exclusion_of :address, :in => ['PO BOX', 'P.O. BOX', 'AFO', 'A.F.O.', 'APO', 'A.P.O.'],
32 # :message => 'Sorry, we don\'nt ship to P.O. boxes'
34 # Makes sure validation address doesn't allow PO Box or variants
36 invalid_strings = ['PO BOX', 'P.O. BOX', 'P.O BOX', 'PO. BOX',
37 'POBOX', 'P.OBOX', 'P.O.BOX', 'PO.BOX', 'P.BOX',
38 'PBOX', 'AFO', 'A.F.O.', 'APO', 'A.P.O.']
39 cap_address = self.address.upcase()
40 invalid_strings.each do |string|
41 if cap_address.include?(string) then
42 errors.add(:address, "Sorry, we don't ship to P.O. boxes")
48 # Finds the shipping address for a given OrderUser
49 def self.find_shipping_address_for_user(user)
50 first(:conditions => ["order_user_id = ? AND is_shipping = 1", user.id])
54 "#{self.first_name} #{self.last_name}"