fixed problem with multiple carts and a whole load of problems with crazy delivery destination logic / if I didn't write it i would have thought it was written by a drug abuser during high

This commit is contained in:
Senad Uka
2015-03-14 08:17:06 +01:00
parent e7793f0884
commit 8815267a79
12 changed files with 195 additions and 25 deletions

View File

@@ -2,10 +2,13 @@ class DeliveryDestination < ActiveRecord::Base
has_one :cart
belongs_to :user
def self.find_or_create(anonymous_id, user_id)
def self.create_from_last(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
dd ||= DeliveryDestination.new({user_id: user_id, anonymous_id_string: anonymous_id })
attributes = dd.as_json
attributes.delete("id")
result = DeliveryDestination.create!(attributes)
return result
end
end