address saving almost works
This commit is contained in:
@@ -30,6 +30,8 @@ end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
helpers Sinatra::Cookies
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
|
||||
|
||||
|
||||
helpers do
|
||||
def anonymous_id
|
||||
@@ -42,4 +42,20 @@ get '/cart/item/display' do
|
||||
items = []
|
||||
items = Item.find(item_ids) if cart.item_in_carts.length > 0
|
||||
prepare_items_for_mass_display(items)
|
||||
end
|
||||
end
|
||||
|
||||
get '/cart/delivery_destination' do
|
||||
cart = Cart.find_or_create(anonymous_id, -1)
|
||||
cart.delivery_destination.to_json(:except => [:created_at, :email_verification_code, :phone_verification_code])
|
||||
end
|
||||
|
||||
update_delivery_destination = ->() {
|
||||
cart = Cart.find_or_create(anonymous_id, -1)
|
||||
allowed_keys = ["name", "address", "place", "postal_code", "phone", "email", "note"]
|
||||
params = @json_params.reject { |key,_| !allowed_keys.include?(key) }
|
||||
cart.delivery_destination.update_attributes(params)
|
||||
cart.delivery_destination.save!
|
||||
cart.delivery_destination.to_json
|
||||
}
|
||||
put '/cart/delivery_destination', &update_delivery_destination
|
||||
post '/cart/delivery_destination', &update_delivery_destination
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
get '/category' do
|
||||
Category.order(:name).all.to_json(:include => [:section, :sub_categories, :filter_criterias =>{:include => :filter_criteria_values} ])
|
||||
|
||||
end
|
||||
|
||||
get '/category/:id' do
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
get '/filter/section/:id' do |id_s|
|
||||
get '/filter/section/:id' do |id_s|
|
||||
# get filter criteria for a section with id
|
||||
FilterCriteria.where(:owner_type => "Section").where(:owner_id => id_s.to_i).to_json(
|
||||
:include => [:filter_criteria_values]
|
||||
|
||||
@@ -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
|
||||
4
front-api/models/delivery_destination.rb
Normal file
4
front-api/models/delivery_destination.rb
Normal file
@@ -0,0 +1,4 @@
|
||||
class DeliveryDestination < ActiveRecord::Base
|
||||
has_one :cart
|
||||
belongs_to :user
|
||||
end
|
||||
Reference in New Issue
Block a user