Gift support changes

This commit is contained in:
adam.harbas@a-net.ba
2016-01-12 13:26:43 +01:00
parent aca81d97ec
commit 9142e0c4db
10 changed files with 103 additions and 133 deletions

View File

@@ -1,8 +1,6 @@
class Cart < ActiveRecord::Base
has_many :item_in_carts, -> { order "created_at" }
belongs_to :delivery_destination, :class_name => 'DeliveryDestination', :foreign_key => 'delivery_destination_id'
belongs_to :delivery_destination, :class_name => 'DeliveryDestination', :foreign_key => 'recipient_destination_id'
has_many :item_in_carts, -> { order "created_at" }
belongs_to :delivery_destination
def self.find_or_create(anonymous_id, user_id)
cart = nil

View File

@@ -1,12 +1,21 @@
class DeliveryDestination < ActiveRecord::Base
has_many :carts
has_one :cart
belongs_to :user
def self.create_from_last(anonymous_id, user_id)
dd = DeliveryDestination.where(["user_id is not null and user_id = ?", user_id]).order("id desc").first
dd ||= DeliveryDestination.where(["anonymous_id_string is not null and anonymous_id_string = ?", anonymous_id]).order("id desc").first
dd ||= DeliveryDestination.new({user_id: user_id, anonymous_id_string: anonymous_id })
dd.payment_method ||= "cash_on_delivery"
dd.gift = false
dd.recipient_name = ""
dd.recipient_phone = ""
dd.recipient_email = ""
dd.recipient_address = ""
dd.recipient_place = ""
dd.recipient_postal_code = ""
attributes = dd.as_json
attributes.delete("id")
result = DeliveryDestination.create!(attributes)