address saving almost works
This commit is contained in:
@@ -30,6 +30,8 @@ end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
helpers Sinatra::Cookies
|
||||
|
||||
|
||||
|
||||
@@ -43,3 +43,19 @@ get '/cart/item/display' do
|
||||
items = Item.find(item_ids) if cart.item_in_carts.length > 0
|
||||
prepare_items_for_mass_display(items)
|
||||
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,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
|
||||
@@ -43,6 +43,11 @@ var CartActions = {
|
||||
property: property,
|
||||
value: value
|
||||
});
|
||||
},
|
||||
confirmDelivery: function() {
|
||||
AppDispatcher.handleAction({
|
||||
actionType: CartConstants.CONFIRM_DELIVERY,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -16,9 +16,8 @@ var CheckoutPage = React.createClass({
|
||||
render: function() {
|
||||
|
||||
return (
|
||||
|
||||
<div className="checkout-page center">
|
||||
<form className="form-horizontal">
|
||||
<div className="form-horizontal">
|
||||
<fieldset>
|
||||
<legend>Dostava</legend>
|
||||
<div className="form-group">
|
||||
@@ -29,12 +28,13 @@ var CheckoutPage = React.createClass({
|
||||
</div>
|
||||
</div>
|
||||
<div className="form-group">
|
||||
<label className="col-md-4 control-label" htmlFor="address">Adresa</label>
|
||||
<label className="col-md-4 control-label" htmlFor="name">Adresa</label>
|
||||
<div className="col-md-4">
|
||||
<input id="address" name="address" type="text" placeholder="Ulica i broj" className="form-control input-md" required="" value={this.state.deliveryDestination.get('address')} onChange={this._onFieldChange} />
|
||||
<span className="help-block">adresa na koju će roba biti isporučena</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<label className="col-md-4 control-label" htmlFor="place">Mjesto</label>
|
||||
<div className="col-md-4">
|
||||
@@ -51,7 +51,7 @@ var CheckoutPage = React.createClass({
|
||||
<option value="76204">Bijela</option>
|
||||
<option value="76300">Bijeljina</option>
|
||||
<option value="73263">Bijelo Brdo</option>
|
||||
<option value="89230">Bileca</option>
|
||||
<option value="89230">Bileca</option> ++++++++
|
||||
<option value="72248">Biljesevo</option>
|
||||
<option value="88407">Bjelimici</option>
|
||||
<option value="88201">Blagaj</option>
|
||||
@@ -577,11 +577,11 @@ var CheckoutPage = React.createClass({
|
||||
<div className="form-group">
|
||||
<label className="col-md-4 control-label" htmlFor="order"></label>
|
||||
<div className="col-md-8">
|
||||
<CartTotal items={this.state.items} itemCounts={this.state.itemCounts} /> <button id="order" name="order" className="btn btn-success">Naruči</button>
|
||||
<CartTotal items={this.state.items} itemCounts={this.state.itemCounts} /> <button id="order" name="order" className="btn btn-success" onClick={this._onOrderClick}>Naruči</button>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -607,6 +607,10 @@ var CheckoutPage = React.createClass({
|
||||
CartActions.changeDeliveryDestinationProperty(event.target.name, event.target.value);
|
||||
},
|
||||
|
||||
_onOrderClick: function (event) {
|
||||
CartActions.confirmDelivery();
|
||||
},
|
||||
|
||||
getInitialState: function () {
|
||||
return CartStore.getWholeCartState();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user