fixed bugs with trello
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
|
|
||||||
create_the_cart = -> () {
|
create_the_cart = lambda do
|
||||||
# -1 is a placeholder for user id when we implement users
|
# -1 is a placeholder for user id when we implement users
|
||||||
# auid will still be used in case user is not logged in
|
# auid will still be used in case user is not logged in
|
||||||
Cart.find_or_create(anonymous_id, logged_in_user_id).to_json
|
Cart.find_or_create(anonymous_id, logged_in_user_id).to_json
|
||||||
}
|
end
|
||||||
post '/cart', &create_the_cart
|
post '/cart', &create_the_cart
|
||||||
put '/cart', &create_the_cart
|
put '/cart', &create_the_cart
|
||||||
|
|
||||||
@@ -16,22 +16,19 @@ get '/cart/item' do
|
|||||||
Cart.just_find(anonymous_id, logged_in_user_id).item_in_carts.to_json
|
Cart.just_find(anonymous_id, logged_in_user_id).item_in_carts.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
update_cart_item = ->() {
|
update_cart_item = lambda do
|
||||||
cart_id = Cart.just_find(anonymous_id, logged_in_user_id).id
|
cart_id = Cart.just_find(anonymous_id, logged_in_user_id).id
|
||||||
item_id = @json_params["item_id"].to_i
|
item_id = @json_params['item_id'].to_i
|
||||||
count = @json_params["count"].to_i
|
count = @json_params['count'].to_i
|
||||||
ItemInCart.update_state(cart_id, item_id, count).to_json
|
ItemInCart.update_state(cart_id, item_id, count).to_json
|
||||||
}
|
end
|
||||||
put '/cart/item', &update_cart_item
|
put '/cart/item', &update_cart_item
|
||||||
post '/cart/item', &update_cart_item
|
post '/cart/item', &update_cart_item
|
||||||
|
|
||||||
|
|
||||||
# gets list of items in cart without count
|
# gets list of items in cart without count
|
||||||
get '/cart/item/display' do
|
get '/cart/item/display' do
|
||||||
cart = Cart.just_find(anonymous_id, logged_in_user_id)
|
cart = Cart.just_find(anonymous_id, logged_in_user_id)
|
||||||
item_ids = cart.item_in_carts.map do |x|
|
item_ids = cart.item_in_carts.map(&:item_id)
|
||||||
x.item_id
|
|
||||||
end
|
|
||||||
items = []
|
items = []
|
||||||
items = Item.find(item_ids) if cart.item_in_carts.length > 0
|
items = Item.find(item_ids) if cart.item_in_carts.length > 0
|
||||||
prepare_items_for_mass_display(items)
|
prepare_items_for_mass_display(items)
|
||||||
@@ -39,32 +36,32 @@ end
|
|||||||
|
|
||||||
get '/cart/delivery_destination' do
|
get '/cart/delivery_destination' do
|
||||||
cart = Cart.just_find(anonymous_id, logged_in_user_id)
|
cart = Cart.just_find(anonymous_id, logged_in_user_id)
|
||||||
cart.delivery_destination.to_json(:except => [:created_at, :email_verification_code, :phone_verification_code])
|
cart.delivery_destination.to_json(except: [:created_at, :email_verification_code, :phone_verification_code])
|
||||||
end
|
end
|
||||||
|
|
||||||
update_delivery_destination = ->() {
|
update_delivery_destination = lambda do
|
||||||
cart = Cart.just_find(anonymous_id, logged_in_user_id)
|
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 = %w(name address place postal_code phone email note payment_method gift
|
||||||
"recipient_name", "recipient_address", "recipient_place", "recipient_postal_code", "recipient_phone", "recipient_email"]
|
recipient_name recipient_address recipient_place recipient_postal_code recipient_phone recipient_email)
|
||||||
|
|
||||||
params = @json_params.reject { |key,_| !allowed_keys.include?(key) }
|
params = @json_params.reject { |key, _| !allowed_keys.include?(key) }
|
||||||
cart.delivery_destination.update_attributes(params)
|
cart.delivery_destination.update_attributes(params)
|
||||||
cart.delivery_destination.save!
|
cart.delivery_destination.save!
|
||||||
cart.delivery_destination.to_json(:except => [:created_at, :email_verification_code, :phone_verification_code])
|
cart.delivery_destination.to_json(except: [:created_at, :email_verification_code, :phone_verification_code])
|
||||||
}
|
end
|
||||||
put '/cart/delivery_destination', &update_delivery_destination
|
put '/cart/delivery_destination', &update_delivery_destination
|
||||||
post '/cart/delivery_destination', &update_delivery_destination
|
post '/cart/delivery_destination', &update_delivery_destination
|
||||||
|
|
||||||
def report_to_trello(cart)
|
def report_to_trello(cart)
|
||||||
Thread.new do
|
Thread.new do
|
||||||
@cart = cart
|
@cart = cart
|
||||||
board = Trello::Board.find(RibicaConfig.TRELLO_BOARD_NAME)
|
board = Trello::Board.find(RibicaConfig::TRELLO_BOARD_NAME)
|
||||||
list = board.lists.first
|
list = board.lists.first
|
||||||
card = Trello::Card.new
|
card = Trello::Card.new
|
||||||
card.list_id = list.id
|
card.list_id = list.id
|
||||||
card.name = cart.title
|
card.name = cart.title
|
||||||
card.pos = "bottom"
|
card.pos = 'bottom'
|
||||||
card.desc = erb(:cart_trello, :layout => false)
|
card.desc = erb(:cart_trello, layout: false)
|
||||||
card.save
|
card.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -72,22 +69,21 @@ end
|
|||||||
def send_order_email(cart)
|
def send_order_email(cart)
|
||||||
Thread.new do
|
Thread.new do
|
||||||
client = SendGrid::Client.new(
|
client = SendGrid::Client.new(
|
||||||
api_user: RibicaConfig.SENDGRID_API_USER,
|
api_user: RibicaConfig::SENDGRID_API_USER,
|
||||||
api_key: RibicaConfig.SENDGRID_API_KEY
|
api_key: RibicaConfig::SENDGRID_API_KEY
|
||||||
)
|
)
|
||||||
|
|
||||||
email = SendGrid::Mail.new do |m|
|
email = SendGrid::Mail.new do |m|
|
||||||
m.to = RibicaConfig.BACKOFFICE_ORDER_EMAIL_TO
|
m.to = RibicaConfig::BACKOFFICE_ORDER_EMAIL_TO
|
||||||
m.from = RibicaConfig.BACKOFFICE_ORDER_EMAIL_FROM
|
m.from = RibicaConfig::BACKOFFICE_ORDER_EMAIL_FROM
|
||||||
m.from_name = "Prodavnica Ribica"
|
m.from_name = 'Prodavnica Ribica'
|
||||||
m.subject = "Nova Narudžba: #{cart.id}"
|
m.subject = "Nova Narudžba: #{cart.id}"
|
||||||
m.html = "Mušterija naručila nešto. <br /> Pogledati #{RibicaConfig.ROOT_ADDRESS}/backoffice/carts/#{cart.id}"
|
m.html = "Mušterija naručila nešto. <br /> Pogledati #{RibicaConfig::ROOT_ADDRESS}/backoffice/carts/#{cart.id}"
|
||||||
end
|
end
|
||||||
client.send(email)
|
client.send(email)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
post '/cart/confirmation' do
|
post '/cart/confirmation' do
|
||||||
anonymous = anonymous_id
|
anonymous = anonymous_id
|
||||||
cart = Cart.just_find(anonymous, logged_in_user_id)
|
cart = Cart.just_find(anonymous, logged_in_user_id)
|
||||||
@@ -98,48 +94,50 @@ post '/cart/confirmation' do
|
|||||||
# since there is no more ordered cart this needs to be done
|
# since there is no more ordered cart this needs to be done
|
||||||
# in order for next call of Cart#just_find to be ready
|
# in order for next call of Cart#just_find to be ready
|
||||||
Cart.find_or_create(anonymous, logged_in_user_id)
|
Cart.find_or_create(anonymous, logged_in_user_id)
|
||||||
|
|
||||||
report_to_trello(cart)
|
report_to_trello(cart)
|
||||||
send_order_email(cart)
|
send_order_email(cart)
|
||||||
"OK".to_json
|
|
||||||
|
'OK'.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
post '/payment/confirmation' do
|
post '/payment/confirmation' do
|
||||||
data = JSON.parse params[:custom]
|
data = JSON.parse params[:custom]
|
||||||
|
|
||||||
puts "Data #{data.inspect}"
|
puts "Data #{data.inspect}"
|
||||||
|
|
||||||
anonymous = data["anonymous_id_string"]
|
anonymous = data['anonymous_id_string']
|
||||||
user = data["user_id"]
|
user = data['user_id']
|
||||||
user ||= -1
|
user ||= -1
|
||||||
user = user.to_i
|
user = user.to_i
|
||||||
|
|
||||||
cart = Cart.just_find(anonymous, user)
|
cart = Cart.just_find(anonymous, user)
|
||||||
if cart.item_in_carts.length > 0
|
if cart.item_in_carts.length > 0
|
||||||
cart.ordered = true
|
cart.ordered = true
|
||||||
cart.save!
|
cart.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
Cart.find_or_create(anonymous, user)
|
Cart.find_or_create(anonymous, user)
|
||||||
report_to_trello(cart)
|
report_to_trello(cart)
|
||||||
send_order_email(cart)
|
send_order_email(cart)
|
||||||
"OK".to_json
|
'OK'.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/pikpay/confirmation' do
|
get '/pikpay/confirmation' do
|
||||||
anonymous = params["anonymous_id_string"]
|
anonymous = params['anonymous_id_string']
|
||||||
user = params["user_id"]
|
user = params['user_id']
|
||||||
user ||= -1
|
user ||= -1
|
||||||
user = user.to_i
|
user = user.to_i
|
||||||
|
|
||||||
cart = Cart.just_find(anonymous, user)
|
cart = Cart.just_find(anonymous, user)
|
||||||
if cart.item_in_carts.length > 0
|
if cart.item_in_carts.length > 0
|
||||||
cart.ordered = true
|
cart.ordered = true
|
||||||
cart.save!
|
cart.save!
|
||||||
end
|
end
|
||||||
|
|
||||||
Cart.find_or_create(anonymous, user)
|
Cart.find_or_create(anonymous, user)
|
||||||
report_to_trello(cart)
|
report_to_trello(cart)
|
||||||
send_order_email(cart)
|
send_order_email(cart)
|
||||||
|
|
||||||
redirect "#{RibicaConfig::ROOT_ADDRESS}/hvala"
|
redirect "#{RibicaConfig::ROOT_ADDRESS}/hvala"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -55,3 +55,4 @@ Dostava
|
|||||||
**UKUPNO:** <%= Helper.money(c.total) %>
|
**UKUPNO:** <%= Helper.money(c.total) %>
|
||||||
|
|
||||||
[Pogledati OVAJ LINK](https://www.ribica.ba/backoffice/carts/<%= @cart.id %>)
|
[Pogledati OVAJ LINK](https://www.ribica.ba/backoffice/carts/<%= @cart.id %>)
|
||||||
|
<% end %>
|
||||||
|
|||||||
Reference in New Issue
Block a user