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 1/4] 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 ** From a2bc1e192cdf5090718a4d48b24438a2a06cf96e Mon Sep 17 00:00:00 2001 From: "adam.harbas@a-net.ba" Date: Tue, 16 Feb 2016 14:31:51 +0100 Subject: [PATCH 2/4] Fix for cartLoad --- front-ui/app/components/cart/checkoutPage.js | 2 +- front-ui/app/stores/cartStore.js | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/front-ui/app/components/cart/checkoutPage.js b/front-ui/app/components/cart/checkoutPage.js index cbd1af6..61595fc 100644 --- a/front-ui/app/components/cart/checkoutPage.js +++ b/front-ui/app/components/cart/checkoutPage.js @@ -26,7 +26,7 @@ var CheckoutPage = React.createClass({ disabled={!this.state.isDeliveryDestinationValid} cashOnDeliveryDisabled={!this.state.isDeliveryDestinationValid || this.state.deliveryDestination.get('gift')} onCashClick={this._onOrderClick} - cartId={this.state.cart.get('id')} + cartId={this.state.deliveryDestination.get('id')} /> ); diff --git a/front-ui/app/stores/cartStore.js b/front-ui/app/stores/cartStore.js index ad22b17..dea9754 100644 --- a/front-ui/app/stores/cartStore.js +++ b/front-ui/app/stores/cartStore.js @@ -10,7 +10,6 @@ var DeliveryDestination = require('../models/deliveryDestination'); var OrderConfirmation = require('../models/orderConfirmation'); var Place = require('../models/place'); var Validation = require('../utils/validation'); -var Cart = require('../models/cart'); var _ = require('underscore'); @@ -26,8 +25,6 @@ var _deliveryCosts = new Place({ postalCode: _deliveryDestination.get('place') }); -var _cart = new Cart(); - var _addressColapsed = false; var supportedPlaces = [{ @@ -2571,7 +2568,6 @@ var nameOfThePlace = function(code) { } var loadCart = function() { - _cart.fetch({success: function() { _itemsInCart.fetch({ success: function() { states = {} @@ -2595,7 +2591,6 @@ var loadCart = function() { }); } }); - }}); _cartDataLoadCalled = true; }; From 2534ee71e148465809139b365fb70fe8ab7cd84f Mon Sep 17 00:00:00 2001 From: "adam.harbas@a-net.ba" Date: Tue, 16 Feb 2016 14:34:29 +0100 Subject: [PATCH 3/4] Fix for cartLoad --- front-ui/app/stores/cartStore.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/front-ui/app/stores/cartStore.js b/front-ui/app/stores/cartStore.js index dea9754..f72833f 100644 --- a/front-ui/app/stores/cartStore.js +++ b/front-ui/app/stores/cartStore.js @@ -2875,8 +2875,7 @@ var CartStore = _.extend({}, EventEmitter.prototype, { deliveryCosts: _deliveryCosts, destinationValid: isDeliveryDestinationValid(), address_colapsed: _addressColapsed, - deliveryCostsTarget: getDeliveryCostTarget(), - cart: _cart + deliveryCostsTarget: getDeliveryCostTarget() }; return state; }, From fdc3362719749bced6bf2931165a5b279c8ace40 Mon Sep 17 00:00:00 2001 From: "adam.harbas@a-net.ba" Date: Tue, 16 Feb 2016 14:37:18 +0100 Subject: [PATCH 4/4] Remove cart from state --- front-ui/app/components/cart/checkoutPage.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/front-ui/app/components/cart/checkoutPage.js b/front-ui/app/components/cart/checkoutPage.js index 61595fc..a4a0e2d 100644 --- a/front-ui/app/components/cart/checkoutPage.js +++ b/front-ui/app/components/cart/checkoutPage.js @@ -34,15 +34,15 @@ var CheckoutPage = React.createClass({ var last_used_payment; if(this.state.deliveryDestination.get('payment_method') == 'paypal') { last_used_payment = ( - + ); } else if(this.state.deliveryDestination.get('payment_method') == 'pikpay') { last_used_payment = ( - + ); } else { last_used_payment = ( - + ); }