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

@@ -44,7 +44,9 @@ end
update_delivery_destination = ->() {
cart = Cart.just_find(anonymous_id, logged_in_user_id)
allowed_keys = ["name", "address", "place", "postal_code", "phone", "email", "note", "payment_method", "gift"]
allowed_keys = ["name", "address", "place", "postal_code", "phone", "email", "note", "payment_method", "gift",
"recipient_name", "recipient_address", "recipient_place", "recipient_postal_code", "recipient_phone", "recipient_email"]
params = @json_params.reject { |key,_| !allowed_keys.include?(key) }
cart.delivery_destination.update_attributes(params)
cart.delivery_destination.save!
@@ -53,22 +55,6 @@ update_delivery_destination = ->() {
put '/cart/delivery_destination', &update_delivery_destination
post '/cart/delivery_destination', &update_delivery_destination
get '/cart/recipient_destination' do
cart = Cart.just_find(anonymous_id, logged_in_user_id)
cart.recipient.to_json(:except => [:created_at, :email_verification_code, :phone_verification_code])
end
update_recipient_destination = ->() {
cart = Cart.just_find(anonymous_id, logged_in_user_id)
allowed_keys = ["name", "address", "place", "postal_code", "phone", "email"]
params = @json_params.reject { |key,_| !allowed_keys.include?(key) }
cart.recipient_destination.update_attributes(params)
cart.recipient_destination.save!
cart.recipient_destination.to_json(:except => [:created_at, :email_verification_code, :phone_verification_code])
}
put '/cart/recipient_destination', &update_delivery_destination
post '/cart/recipient_destination', &update_delivery_destination
def report_to_trello(cart)
Thread.new do
@cart = cart

View File

@@ -0,0 +1,10 @@
class AddRecipientDestinationToDeliveryDestination < ActiveRecord::Migration
def change
add_column :delivery_destinations, :recipient_name, :string
add_column :delivery_destinations, :recipient_address, :string
add_column :delivery_destinations, :recipient_place, :string
add_column :delivery_destinations, :recipient_postal_code, :string
add_column :delivery_destinations, :recipient_phone, :string
add_column :delivery_destinations, :recipient_email, :string
end
end

View File

@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160111105607) do
ActiveRecord::Schema.define(version: 20160112091903) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -22,18 +22,17 @@ ActiveRecord::Schema.define(version: 20160111105607) do
create_table "carts", force: :cascade do |t|
t.integer "user_id"
t.boolean "ordered", default: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "ordered", default: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "anonymous_id_string"
t.integer "delivery_destination_id"
t.boolean "confirmed", default: false
t.boolean "packed", default: false
t.boolean "canceled_on_check", default: false
t.boolean "canceled_on_delivery", default: false
t.boolean "delivered", default: false
t.boolean "confirmed", default: false
t.boolean "packed", default: false
t.boolean "canceled_on_check", default: false
t.boolean "canceled_on_delivery", default: false
t.boolean "delivered", default: false
t.text "internal_note"
t.integer "recipient_destination_id"
end
create_table "categories", force: :cascade do |t|
@@ -70,6 +69,12 @@ ActiveRecord::Schema.define(version: 20160111105607) do
t.boolean "instant_delivery", default: false
t.string "payment_method"
t.boolean "gift", default: false
t.string "recipient_name"
t.string "recipient_address"
t.string "recipient_place"
t.string "recipient_postal_code"
t.string "recipient_phone"
t.string "recipient_email"
end
create_table "delivery_time_estimations", force: :cascade do |t|

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)