cart now functional without bugs (at least the ones we know about)
fixed a small issue with ItemGroup REST call
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
def prepare_items_for_mass_display(items)
|
||||
def prepare_items_for_mass_display(items)
|
||||
items.to_json(
|
||||
:except => [:created_at, :current_input_price, :stock, :on_display],
|
||||
:include => [
|
||||
:include => [
|
||||
:unit ,
|
||||
:multi_media_descriptions ,
|
||||
:sub_category,
|
||||
@@ -15,7 +15,7 @@ end
|
||||
|
||||
|
||||
# gets single item for detailed display (like comments etc. ) # TODO: change when comments are added
|
||||
get '/item/:id' do |id_s|
|
||||
get '/item/:id' do |id_s|
|
||||
item = Item.find(id_s.to_i)
|
||||
prepare_items_for_mass_display(item)
|
||||
end
|
||||
@@ -32,7 +32,7 @@ end
|
||||
get '/item/offset/:offset/limit/:limit' do |offset_s, limit_s|
|
||||
offset, limit = mass_to_i(offset_s, limit_s)
|
||||
return [].to_json if offset_and_limit_invalid?(offset,limit)
|
||||
|
||||
|
||||
items = Item.best_selling(offset,limit)
|
||||
prepare_items_for_mass_display(items)
|
||||
end
|
||||
@@ -42,8 +42,8 @@ end
|
||||
get '/item/section/:section_id/offset/:offset/limit/:limit' do |section_id_s, offset_s, limit_s|
|
||||
section_id, offset, limit = mass_to_i(section_id_s, offset_s, limit_s)
|
||||
input_invalid = offset_and_limit_invalid?(offset,limit) or section_id <= 0
|
||||
return [].to_json if input_invalid
|
||||
|
||||
return [].to_json if input_invalid
|
||||
|
||||
items = Item.best_selling_in_section(section_id, offset, limit)
|
||||
prepare_items_for_mass_display(items)
|
||||
end
|
||||
@@ -53,7 +53,7 @@ end
|
||||
get '/item/category/:category_id/offset/:offset/limit/:limit' do |category_id_s, offset_s, limit_s|
|
||||
category_id, offset, limit = mass_to_i(category_id_s, offset_s, limit_s)
|
||||
input_invalid = offset_and_limit_invalid?(offset,limit) or category_id <= 0
|
||||
return [].to_json if input_invalid
|
||||
return [].to_json if input_invalid
|
||||
|
||||
all_in_cat = filter_by_traits(Item.all_in_category(category_id))
|
||||
items = Item.best_selling_in_category(category_id, offset,limit)
|
||||
@@ -69,13 +69,13 @@ get '/item/sub_category/:sub_category_id/offset/:offset/limit/:limit' do |sub_ca
|
||||
|
||||
sub_category_id, offset, limit = mass_to_i(sub_category_id_s, offset_s, limit_s)
|
||||
input_invalid = offset_and_limit_invalid?(offset,limit) or sub_category_id <= 0
|
||||
return [].to_json if input_invalid
|
||||
return [].to_json if input_invalid
|
||||
|
||||
all_in_sub_cat = filter_by_traits(Item.all_in_sub_category(sub_category_id))
|
||||
|
||||
items = Item.best_selling_in_sub_category(sub_category_id, offset, limit)
|
||||
items = filter_by_traits(items)
|
||||
|
||||
|
||||
add_total_count_header(all_in_sub_cat.count)
|
||||
|
||||
prepare_items_for_mass_display(items)
|
||||
@@ -83,13 +83,13 @@ end
|
||||
|
||||
|
||||
# gets list of items in cart without count
|
||||
get '/cart/item_details' do
|
||||
get '/cart/item_details' do
|
||||
cart = Cart.find_or_create(anonymous_id, -1)
|
||||
item_ids = cart.item_in_carts.map do |x|
|
||||
x.item_id
|
||||
end
|
||||
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)
|
||||
end
|
||||
|
||||
@@ -98,8 +98,9 @@ end
|
||||
get '/item/item_group/:item_group_id/offset/:offset/limit/:limit' do |item_group_id_s, offset_s, limit_s|
|
||||
item_group_id, offset, limit = mass_to_i(item_group_id_s, offset_s, limit_s)
|
||||
input_invalid = offset_and_limit_invalid?(offset,limit) or item_group_id <= 0
|
||||
return [].to_json if input_invalid
|
||||
return [].to_json if input_invalid
|
||||
|
||||
items = ItemGroup.find(item_group_id).all_items(offset, limit)
|
||||
prepare_items_for_mass_display(items)
|
||||
items = ItemGroup.find_by_id(item_group_id)
|
||||
return [].to_json if items.nil?
|
||||
prepare_items_for_mass_display(items.all_items(offset, limit))
|
||||
end
|
||||
|
||||
@@ -49,6 +49,13 @@ var CartActions = {
|
||||
actionType: CartConstants.TAKE_ITEM_OUT,
|
||||
itemId: id
|
||||
});
|
||||
},
|
||||
setItemCount: function(itemId, count) {
|
||||
AppDispatcher.handleAction({
|
||||
actionType: CartConstants.SET_ITEM_COUNT,
|
||||
itemId: itemId,
|
||||
count: count
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ var Login = React.createClass({
|
||||
{this.getValidationMessages('password').map(this.renderErrorMessage)}
|
||||
|
||||
</div>
|
||||
<input style={{color: 'white', fontWeight: 'bold', height: 44}} type="submit" onClick={this.onLoginClick} className=" mybutton center-block col-md-8 col-sm-8 col-xs-8 col-sm-push-2 col-xs-push-2 col-md-push-2" defaultValue="Prijava" />
|
||||
<input style={{color: 'white', fontWeight: 'bold', height: 44}} type="submit" onClick={this.onLoginClick} className=" mybutton center-block col-md-8 col-sm-8 col-xs-8 col-sm-push-2 col-xs-push-2 col-md-push-2" defaultValue="PRIJAVA" />
|
||||
</form>
|
||||
<div className="text-center col-lg-12">
|
||||
<h4>Niste registrovani? <Link to="registracija"><span>Registrujte se</span></Link></h4>
|
||||
|
||||
@@ -31,7 +31,7 @@ var CartIcon = React.createClass({
|
||||
<ul className="nav navbar-nav navbar-right hidden-md hidden-sm hidden-xs">
|
||||
<li><LoginStatus /></li>
|
||||
<li onClick={this._onClick} style={{borderTop: 'solid lightgray 1px', borderBottom: 'solid lightgray 1px', borderLeft: 'solid lightgray 1px', paddingBottom: 22}}><a ><div className="mycart"><span>{normalizeCount(this.state.count)}</span></div></a></li>
|
||||
<li onClick={this._onClick} style={{borderTop: 'solid lightgray 1px', borderBottom: 'solid lightgray 1px', paddingBottom: 2}}><a href="#" style={{ paddingRight: '5px'}}><CartTotal items={this.state.items} itemCounts={this.state.itemCounts} deliveryCosts={this.state.deliveryCosts} justMerchandise={true}/> </a></li>
|
||||
<li onClick={this._onClick} style={{borderTop: 'solid lightgray 1px', borderBottom: 'solid lightgray 1px', paddingBottom: 2}}><a href="#" style={{ paddingRight: '5px', backgroundColor: 'transparent' }}><CartTotal items={this.state.items} itemCounts={this.state.itemCounts} deliveryCosts={this.state.deliveryCosts} justMerchandise={true}/> </a></li>
|
||||
<li onClick={this._onClick} style={{borderTop: 'solid lightgray 1px', borderBottom: 'solid lightgray 1px', borderRight: 'solid lightgray 1px'}}>
|
||||
<a style={{marginBottom: 10, marginRight: 10}} className="mybutton" href="#">Završi narudžbu</a></li>
|
||||
|
||||
@@ -40,7 +40,7 @@ var CartIcon = React.createClass({
|
||||
<ul className="nav navbar-nav navbar-right hidden-lg">
|
||||
<li><LoginStatus /></li>
|
||||
<li onClick={this._onClick} style={{borderTop: 'solid lightgray 1px', borderBottom: 'solid lightgray 1px', borderLeft: 'solid lightgray 1px', paddingBottom: 22}}><a ><div className="mycart"><span>{normalizeCount(this.state.count)}</span></div></a></li>
|
||||
<li onClick={this._onClick} style={{borderTop: 'solid lightgray 1px', borderBottom: 'solid lightgray 1px',borderRight: 'solid lightgray 1px', paddingBottom: 2}}><a href="#" style={{ paddingRight: '5px'}}><CartTotal items={this.state.items} itemCounts={this.state.itemCounts} deliveryCosts={this.state.deliveryCosts} justMerchandise={true}/> </a></li>
|
||||
<li onClick={this._onClick} style={{borderTop: 'solid lightgray 1px', borderBottom: 'solid lightgray 1px',borderRight: 'solid lightgray 1px', paddingBottom: 2}}><a href="#" style={{ paddingRight: '5px', backgroundColor: 'transparent'}}><CartTotal items={this.state.items} itemCounts={this.state.itemCounts} deliveryCosts={this.state.deliveryCosts} justMerchandise={true}/> </a></li>
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -21,7 +21,7 @@ var CartPage = React.createClass({
|
||||
var displayedItems = this.state.items.filter(function(i) {
|
||||
if(!counts) return false;
|
||||
var count = counts[i.get('id')].get('count');
|
||||
return count > 0;
|
||||
return count > 0 || count === "";
|
||||
}).map(function (i) {
|
||||
var count = counts[i.get('id')].get('count');
|
||||
var price = i.get('list_price');
|
||||
@@ -40,7 +40,21 @@ var CartPage = React.createClass({
|
||||
</td>
|
||||
<td>{ Globals.FormatCurrency(price) }</td>
|
||||
<td>
|
||||
<input style={{textAlign: 'center'}} className="form-control qty-box" type='text' value={count}></input>
|
||||
<select style={{textAlign: 'center'}} value={count}
|
||||
onChange={self._onQuantityChange.bind(self, i.get('id'))}
|
||||
>
|
||||
|
||||
<option value="1">1</option>
|
||||
<option value="2">2</option>
|
||||
<option value="3">3</option>
|
||||
<option value="4">4</option>
|
||||
<option value="5">5</option>
|
||||
<option value="6">6</option>
|
||||
<option value="7">7</option>
|
||||
<option value="8">8</option>
|
||||
<option value="9">9</option>
|
||||
<option value="10">10</option>
|
||||
</select>
|
||||
</td>
|
||||
<td>
|
||||
{ Globals.FormatCurrency(count * price) }
|
||||
@@ -61,8 +75,6 @@ var CartPage = React.createClass({
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
|
||||
var cartTotal = (
|
||||
<div>
|
||||
<div className="row cart-total">
|
||||
@@ -109,8 +121,6 @@ var CartPage = React.createClass({
|
||||
</div>)
|
||||
}
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<div className="col-lg-12">
|
||||
<LinkBanner locationName="thankYouPage" />
|
||||
@@ -141,7 +151,9 @@ var CartPage = React.createClass({
|
||||
_onOrderClick: function () {
|
||||
NavigationActions.goToCheckout();
|
||||
},
|
||||
|
||||
_onQuantityChange(itemId, e) {
|
||||
CartActions.setItemCount(itemId, e.target.value);
|
||||
},
|
||||
getInitialState: function () {
|
||||
return CartStore.getWholeCartState();
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ var loadCart = function() {
|
||||
});
|
||||
|
||||
//_deliveryDestination.fetch({
|
||||
//success: function() {
|
||||
//success: function() {
|
||||
//validateDeliveryDestinationForm();
|
||||
//fetchPlace();
|
||||
//CartActions.dataLoaded();
|
||||
@@ -94,6 +94,30 @@ var takeItemOut = function(itemId) {
|
||||
saveCartStateForItem(itemId);
|
||||
};
|
||||
|
||||
var setItemCount = function(itemId, count) {
|
||||
var state = states[itemId] || new ItemInCart({
|
||||
item_id: itemId,
|
||||
count: 0
|
||||
});
|
||||
|
||||
if (count === "") {
|
||||
state.set('count', "");
|
||||
CartStore.emitChange();
|
||||
return;
|
||||
}
|
||||
|
||||
var cnt = parseInt(count);
|
||||
|
||||
if(isNaN(cnt) || cnt <= 0) {
|
||||
cnt = 1;
|
||||
}
|
||||
|
||||
state.set('count', cnt);
|
||||
|
||||
states[itemId] = state;
|
||||
saveCartStateForItem(itemId);
|
||||
// CartStore.emitChange();
|
||||
};
|
||||
|
||||
var addNItems = function(item, count) {
|
||||
|
||||
@@ -283,6 +307,9 @@ AppDispatcher.register(function(payload) {
|
||||
case CartConstants.ADD_N_ITEMS:
|
||||
addNItems(action.item, action.count);
|
||||
break;
|
||||
case CartConstants.SET_ITEM_COUNT:
|
||||
setItemCount(action.itemId, action.count);
|
||||
break;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user