diff --git a/front-api/app.rb b/front-api/app.rb
index 3e0dc31..156bb33 100644
--- a/front-api/app.rb
+++ b/front-api/app.rb
@@ -30,6 +30,8 @@ end
+
+
helpers Sinatra::Cookies
diff --git a/front-api/controllers/cart.rb b/front-api/controllers/cart.rb
index 2c44e5b..97780c2 100644
--- a/front-api/controllers/cart.rb
+++ b/front-api/controllers/cart.rb
@@ -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
\ No newline at end of file
+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
\ No newline at end of file
diff --git a/front-api/controllers/category.rb b/front-api/controllers/category.rb
index 722a36a..8134829 100644
--- a/front-api/controllers/category.rb
+++ b/front-api/controllers/category.rb
@@ -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
diff --git a/front-api/controllers/filter_criteria.rb b/front-api/controllers/filter_criteria.rb
index 8c08288..9a381c8 100644
--- a/front-api/controllers/filter_criteria.rb
+++ b/front-api/controllers/filter_criteria.rb
@@ -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]
diff --git a/front-api/models/cart.rb b/front-api/models/cart.rb
index dc92954..b03f293 100644
--- a/front-api/models/cart.rb
+++ b/front-api/models/cart.rb
@@ -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
\ No newline at end of file
diff --git a/front-api/models/delivery_destination.rb b/front-api/models/delivery_destination.rb
new file mode 100644
index 0000000..ac8594b
--- /dev/null
+++ b/front-api/models/delivery_destination.rb
@@ -0,0 +1,4 @@
+class DeliveryDestination < ActiveRecord::Base
+ has_one :cart
+ belongs_to :user
+end
diff --git a/front-ui/app/actions/cartActions.js b/front-ui/app/actions/cartActions.js
index e2998fe..59dc3d3 100644
--- a/front-ui/app/actions/cartActions.js
+++ b/front-ui/app/actions/cartActions.js
@@ -43,6 +43,11 @@ var CartActions = {
property: property,
value: value
});
+ },
+ confirmDelivery: function() {
+ AppDispatcher.handleAction({
+ actionType: CartConstants.CONFIRM_DELIVERY,
+ });
}
};
diff --git a/front-ui/app/components/cart/checkoutPage.js b/front-ui/app/components/cart/checkoutPage.js
index d5924c2..bd67ed1 100644
--- a/front-ui/app/components/cart/checkoutPage.js
+++ b/front-ui/app/components/cart/checkoutPage.js
@@ -16,572 +16,572 @@ var CheckoutPage = React.createClass({
render: function() {
return (
-
-
+
+
+
);
@@ -606,6 +606,10 @@ var CheckoutPage = React.createClass({
_onFieldChange: function (event) {
CartActions.changeDeliveryDestinationProperty(event.target.name, event.target.value);
},
+
+ _onOrderClick: function (event) {
+ CartActions.confirmDelivery();
+ },
getInitialState: function () {
return CartStore.getWholeCartState();
diff --git a/front-ui/app/constants/cartConstants.js b/front-ui/app/constants/cartConstants.js
index 5f8414d..4a919fa 100644
--- a/front-ui/app/constants/cartConstants.js
+++ b/front-ui/app/constants/cartConstants.js
@@ -9,5 +9,6 @@ module.exports = keyMirror({
TAKE_ITEM_OUT: null ,
CART_DATA_LOADED: null,
SAVE_CART_STATE_FOR_ITEM: null,
- CHANGE_DELIVERY_DESTINATION_PROPERTY: null
+ CHANGE_DELIVERY_DESTINATION_PROPERTY: null,
+ CONFIRM_DELIVERY: null
});
diff --git a/front-ui/app/stores/cartStore.js b/front-ui/app/stores/cartStore.js
index 25559f2..685641d 100644
--- a/front-ui/app/stores/cartStore.js
+++ b/front-ui/app/stores/cartStore.js
@@ -34,6 +34,11 @@ var loadCart = function() {
CartActions.dataLoaded();
}
})
+ _deliveryDestination.fetch({
+ success: function() {
+ CartActions.dataLoaded();
+ }
+ })
};
@@ -74,7 +79,13 @@ var changeDeliveryDestinationProperty = function (property, value) {
_deliveryDestination.set(property, value);
};
-
+var saveDeliveryDestination = function() {
+ _deliveryDestination.save({
+ success: function() {
+ CartActions.dataLoaded();
+ }
+ })
+};
// Extend CartStore with EventEmitter to add eventing capabilities
@@ -156,6 +167,8 @@ AppDispatcher.register(function(payload) {
break;
case CartConstants.CHANGE_DELIVERY_DESTINATION_PROPERTY:
changeDeliveryDestinationProperty(action.propety, action.value)
+ case CartConstants.CONFIRM_DELIVERY:
+ saveDeliveryDestination();
default:
return true;
}