Files
old-ribica/front-api/models/delivery_destination.rb

38 lines
1.0 KiB
Ruby
Raw Normal View History

2016-01-08 09:36:28 +01:00
class DeliveryDestination < ActiveRecord::Base
2016-01-12 13:26:43 +01:00
has_one :cart
2015-02-26 06:48:34 +01:00
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 })
2016-01-12 13:26:43 +01:00
2016-01-11 10:52:18 +01:00
dd.payment_method ||= "cash_on_delivery"
2016-01-12 13:26:43 +01:00
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)
return result
end
2016-01-08 09:36:28 +01:00
def get_payment_string
case self.payment_method
when 'cash_on_delivery'
2016-01-11 10:52:18 +01:00
'Prilikom preuzimanja'
2016-01-08 09:36:28 +01:00
when 'paypal'
'Paypal'
when 'pikpay'
'Pikpay'
else
'Nepoznato'
end
end
2015-02-26 06:48:34 +01:00
end