confirming works, last address is now persisted, thank you page is up but not yet accessible

This commit is contained in:
Senad Uka
2015-03-03 07:26:18 +01:00
parent 4befef5bf4
commit 0f47367cd0
9 changed files with 153 additions and 20 deletions

View File

@@ -7,7 +7,7 @@ class Cart < ActiveRecord::Base
cart ||= Cart.where(anonymous_id_string: anonymous_id).where(ordered: false).first
safe_user_id = (user_id > 0) ? user_id : nil
cart ||= Cart.create!(anonymous_id_string: anonymous_id, user_id: safe_user_id, ordered: false )
cart.delivery_destination ||= DeliveryDestination.create!
cart.delivery_destination ||= DeliveryDestination.find_or_create(anonymous_id, user_id);
return cart
end
end
end

View File

@@ -1,4 +1,11 @@
class DeliveryDestination < ActiveRecord::Base
has_one :cart
belongs_to :user
def self.find_or_create(anonymous_id, user_id)
dd = DeliveryDestination.where(user_id: user_id).order("id desc").first
dd ||= DeliveryDestination.where(anonymous_id_string: anonymous_id).order("id desc").first
dd ||= DeliveryDestination.create!({user_id: user_id, anonymous_id_string: anonymous_id })
return dd
end
end