address saving almost works

This commit is contained in:
Senad Uka
2015-02-26 06:48:34 +01:00
parent 6e327c758f
commit 1ca7d4509a
10 changed files with 618 additions and 571 deletions

View File

@@ -1,10 +1,13 @@
class Cart < ActiveRecord::Base
has_many :item_in_carts, -> { order "created_at" }
belongs_to :delivery_destination
def self.find_or_create(anonymous_id, user_id)
cart = Cart.where(user_id: user_id).where(ordered: false).first
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!
return cart
end
end

View File

@@ -0,0 +1,4 @@
class DeliveryDestination < ActiveRecord::Base
has_one :cart
belongs_to :user
end