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(
|
items.to_json(
|
||||||
:except => [:created_at, :current_input_price, :stock, :on_display],
|
:except => [:created_at, :current_input_price, :stock, :on_display],
|
||||||
:include => [
|
:include => [
|
||||||
:unit ,
|
:unit ,
|
||||||
:multi_media_descriptions ,
|
:multi_media_descriptions ,
|
||||||
:sub_category,
|
:sub_category,
|
||||||
@@ -15,7 +15,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
# gets single item for detailed display (like comments etc. ) # TODO: change when comments are added
|
# 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)
|
item = Item.find(id_s.to_i)
|
||||||
prepare_items_for_mass_display(item)
|
prepare_items_for_mass_display(item)
|
||||||
end
|
end
|
||||||
@@ -32,7 +32,7 @@ end
|
|||||||
get '/item/offset/:offset/limit/:limit' do |offset_s, limit_s|
|
get '/item/offset/:offset/limit/:limit' do |offset_s, limit_s|
|
||||||
offset, limit = mass_to_i(offset_s, limit_s)
|
offset, limit = mass_to_i(offset_s, limit_s)
|
||||||
return [].to_json if offset_and_limit_invalid?(offset,limit)
|
return [].to_json if offset_and_limit_invalid?(offset,limit)
|
||||||
|
|
||||||
items = Item.best_selling(offset,limit)
|
items = Item.best_selling(offset,limit)
|
||||||
prepare_items_for_mass_display(items)
|
prepare_items_for_mass_display(items)
|
||||||
end
|
end
|
||||||
@@ -42,8 +42,8 @@ end
|
|||||||
get '/item/section/:section_id/offset/:offset/limit/:limit' do |section_id_s, offset_s, limit_s|
|
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)
|
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
|
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)
|
items = Item.best_selling_in_section(section_id, offset, limit)
|
||||||
prepare_items_for_mass_display(items)
|
prepare_items_for_mass_display(items)
|
||||||
end
|
end
|
||||||
@@ -53,7 +53,7 @@ end
|
|||||||
get '/item/category/:category_id/offset/:offset/limit/:limit' do |category_id_s, offset_s, limit_s|
|
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)
|
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
|
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))
|
all_in_cat = filter_by_traits(Item.all_in_category(category_id))
|
||||||
items = Item.best_selling_in_category(category_id, offset,limit)
|
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)
|
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
|
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))
|
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 = Item.best_selling_in_sub_category(sub_category_id, offset, limit)
|
||||||
items = filter_by_traits(items)
|
items = filter_by_traits(items)
|
||||||
|
|
||||||
add_total_count_header(all_in_sub_cat.count)
|
add_total_count_header(all_in_sub_cat.count)
|
||||||
|
|
||||||
prepare_items_for_mass_display(items)
|
prepare_items_for_mass_display(items)
|
||||||
@@ -83,13 +83,13 @@ end
|
|||||||
|
|
||||||
|
|
||||||
# gets list of items in cart without count
|
# 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)
|
cart = Cart.find_or_create(anonymous_id, -1)
|
||||||
item_ids = cart.item_in_carts.map do |x|
|
item_ids = cart.item_in_carts.map do |x|
|
||||||
x.item_id
|
x.item_id
|
||||||
end
|
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)
|
||||||
end
|
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|
|
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)
|
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
|
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)
|
items = ItemGroup.find_by_id(item_group_id)
|
||||||
prepare_items_for_mass_display(items)
|
return [].to_json if items.nil?
|
||||||
|
prepare_items_for_mass_display(items.all_items(offset, limit))
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -49,6 +49,13 @@ var CartActions = {
|
|||||||
actionType: CartConstants.TAKE_ITEM_OUT,
|
actionType: CartConstants.TAKE_ITEM_OUT,
|
||||||
itemId: id
|
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)}
|
{this.getValidationMessages('password').map(this.renderErrorMessage)}
|
||||||
|
|
||||||
</div>
|
</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>
|
</form>
|
||||||
<div className="text-center col-lg-12">
|
<div className="text-center col-lg-12">
|
||||||
<h4>Niste registrovani? <Link to="registracija"><span>Registrujte se</span></Link></h4>
|
<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">
|
<ul className="nav navbar-nav navbar-right hidden-md hidden-sm hidden-xs">
|
||||||
<li><LoginStatus /></li>
|
<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', 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'}}>
|
<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>
|
<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">
|
<ul className="nav navbar-nav navbar-right hidden-lg">
|
||||||
<li><LoginStatus /></li>
|
<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', 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>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ var CartPage = React.createClass({
|
|||||||
var displayedItems = this.state.items.filter(function(i) {
|
var displayedItems = this.state.items.filter(function(i) {
|
||||||
if(!counts) return false;
|
if(!counts) return false;
|
||||||
var count = counts[i.get('id')].get('count');
|
var count = counts[i.get('id')].get('count');
|
||||||
return count > 0;
|
return count > 0 || count === "";
|
||||||
}).map(function (i) {
|
}).map(function (i) {
|
||||||
var count = counts[i.get('id')].get('count');
|
var count = counts[i.get('id')].get('count');
|
||||||
var price = i.get('list_price');
|
var price = i.get('list_price');
|
||||||
@@ -40,7 +40,21 @@ var CartPage = React.createClass({
|
|||||||
</td>
|
</td>
|
||||||
<td>{ Globals.FormatCurrency(price) }</td>
|
<td>{ Globals.FormatCurrency(price) }</td>
|
||||||
<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>
|
||||||
<td>
|
<td>
|
||||||
{ Globals.FormatCurrency(count * price) }
|
{ Globals.FormatCurrency(count * price) }
|
||||||
@@ -61,8 +75,6 @@ var CartPage = React.createClass({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var cartTotal = (
|
var cartTotal = (
|
||||||
<div>
|
<div>
|
||||||
<div className="row cart-total">
|
<div className="row cart-total">
|
||||||
@@ -109,8 +121,6 @@ var CartPage = React.createClass({
|
|||||||
</div>)
|
</div>)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="col-lg-12">
|
<div className="col-lg-12">
|
||||||
<LinkBanner locationName="thankYouPage" />
|
<LinkBanner locationName="thankYouPage" />
|
||||||
@@ -141,7 +151,9 @@ var CartPage = React.createClass({
|
|||||||
_onOrderClick: function () {
|
_onOrderClick: function () {
|
||||||
NavigationActions.goToCheckout();
|
NavigationActions.goToCheckout();
|
||||||
},
|
},
|
||||||
|
_onQuantityChange(itemId, e) {
|
||||||
|
CartActions.setItemCount(itemId, e.target.value);
|
||||||
|
},
|
||||||
getInitialState: function () {
|
getInitialState: function () {
|
||||||
return CartStore.getWholeCartState();
|
return CartStore.getWholeCartState();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ var loadCart = function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//_deliveryDestination.fetch({
|
//_deliveryDestination.fetch({
|
||||||
//success: function() {
|
//success: function() {
|
||||||
//validateDeliveryDestinationForm();
|
//validateDeliveryDestinationForm();
|
||||||
//fetchPlace();
|
//fetchPlace();
|
||||||
//CartActions.dataLoaded();
|
//CartActions.dataLoaded();
|
||||||
@@ -94,6 +94,30 @@ var takeItemOut = function(itemId) {
|
|||||||
saveCartStateForItem(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) {
|
var addNItems = function(item, count) {
|
||||||
|
|
||||||
@@ -283,6 +307,9 @@ AppDispatcher.register(function(payload) {
|
|||||||
case CartConstants.ADD_N_ITEMS:
|
case CartConstants.ADD_N_ITEMS:
|
||||||
addNItems(action.item, action.count);
|
addNItems(action.item, action.count);
|
||||||
break;
|
break;
|
||||||
|
case CartConstants.SET_ITEM_COUNT:
|
||||||
|
setItemCount(action.itemId, action.count);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user