From 006829bc773df691042ec627658a16923907dba5 Mon Sep 17 00:00:00 2001 From: "adam.harbas@a-net.ba" Date: Tue, 16 Feb 2016 12:28:49 +0100 Subject: [PATCH] Create trello card before purchasing --- front-api/controllers/cart.rb | 37 ++++++++++++++++++--------------- front-api/views/cart_trello.erb | 2 ++ 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/front-api/controllers/cart.rb b/front-api/controllers/cart.rb index 6774025..b8d522d 100644 --- a/front-api/controllers/cart.rb +++ b/front-api/controllers/cart.rb @@ -42,23 +42,10 @@ get '/cart/delivery_destination' do cart.delivery_destination.to_json(:except => [:created_at, :email_verification_code, :phone_verification_code]) 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", - "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! - cart.delivery_destination.to_json(:except => [:created_at, :email_verification_code, :phone_verification_code]) -} -put '/cart/delivery_destination', &update_delivery_destination -post '/cart/delivery_destination', &update_delivery_destination - def report_to_trello(cart) Thread.new do @cart = cart - board = Trello::Board.find(RibicaConfig.TRELLO_BOARD_NAME) + board = Trello::Board.find(RibicaConfig::TRELLO_BOARD_NAME) list = board.lists.first card = Trello::Card.new card.list_id = list.id @@ -69,6 +56,22 @@ def report_to_trello(cart) end 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", + "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! + + report_to_trello(cart) + + cart.delivery_destination.to_json(:except => [:created_at, :email_verification_code, :phone_verification_code]) +} +put '/cart/delivery_destination', &update_delivery_destination +post '/cart/delivery_destination', &update_delivery_destination + def send_order_email(cart) Thread.new do client = SendGrid::Client.new( @@ -98,7 +101,7 @@ post '/cart/confirmation' do # since there is no more ordered cart this needs to be done # in order for next call of Cart#just_find to be ready Cart.find_or_create(anonymous, logged_in_user_id) - report_to_trello(cart) + #report_to_trello(cart) send_order_email(cart) "OK".to_json end @@ -120,7 +123,7 @@ post '/payment/confirmation' do end Cart.find_or_create(anonymous, user) - report_to_trello(cart) + #report_to_trello(cart) send_order_email(cart) "OK".to_json end @@ -138,7 +141,7 @@ get '/pikpay/confirmation' do end Cart.find_or_create(anonymous, user) - report_to_trello(cart) + #report_to_trello(cart) send_order_email(cart) redirect "#{RibicaConfig::ROOT_ADDRESS}/hvala" diff --git a/front-api/views/cart_trello.erb b/front-api/views/cart_trello.erb index 8f1bfa4..58fd00f 100644 --- a/front-api/views/cart_trello.erb +++ b/front-api/views/cart_trello.erb @@ -37,6 +37,8 @@ Bosna i Hercegovina **Naručeno:** <%= @cart.updated_at.in_time_zone("Europe/Sarajevo").strftime("%A %d.%m.%Y. %H:%M") %> +<% end %> + <% if dd.instant_delivery %> ** OVO JE NARUDŽBA ZA INSTANT DOSTAVU **