cart display now shows price and amount per item
This commit is contained in:
@@ -34,7 +34,7 @@ ActiveRecord::Schema.define(version: 20150207120207) do
|
|||||||
t.string "title"
|
t.string "title"
|
||||||
t.string "field_name"
|
t.string "field_name"
|
||||||
t.integer "type"
|
t.integer "type"
|
||||||
t.integer "owner_type"
|
t.string "owner_type"
|
||||||
t.integer "owner_id"
|
t.integer "owner_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -86,8 +86,10 @@ ActiveRecord::Schema.define(version: 20150207120207) do
|
|||||||
end
|
end
|
||||||
|
|
||||||
create_table "sub_categories", force: :cascade do |t|
|
create_table "sub_categories", force: :cascade do |t|
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.integer "category_id"
|
t.integer "category_id"
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "units", force: :cascade do |t|
|
create_table "units", force: :cascade do |t|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ var CartActions = require('../../actions/cartActions.js');
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
var countStyle = {
|
var buttonHolderStyle = {
|
||||||
width: '100%'
|
display: 'inline-block'
|
||||||
};
|
};
|
||||||
|
|
||||||
var AddToCart = React.createClass({
|
var AddToCart = React.createClass({
|
||||||
@@ -14,9 +14,11 @@ var AddToCart = React.createClass({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="row-fluid add-to-cart">
|
<div className="row-fluid add-to-cart">
|
||||||
<div className="col-xs-offset-1 col-xs-1"><button className="btn btn-success" onClick={this._onIncreaseClick}>+</button></div>
|
<div className="span12">
|
||||||
<div className="col-xs-2"><button className="btn" style={countStyle} > { this.state.item.get('count') } </button></div>
|
<div style={buttonHolderStyle}><button className="btn btn-success" onClick={this._onIncreaseClick}>+</button></div>
|
||||||
<div className="col-xs-1"><button className="btn btn-success" onClick={this._onDecreaseClick}>-</button></div>
|
<div style={buttonHolderStyle}><button className="btn"> { this.state.item.get('count') } </button></div>
|
||||||
|
<div style={buttonHolderStyle}><button className="btn btn-success" onClick={this._onDecreaseClick}>-</button></div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -3,20 +3,31 @@ var React = require('react'),
|
|||||||
AddToCart = require('../cart/addToCart'),
|
AddToCart = require('../cart/addToCart'),
|
||||||
CartActions = require('../../actions/cartActions'),
|
CartActions = require('../../actions/cartActions'),
|
||||||
SingleItem = require('../items/singleItem'),
|
SingleItem = require('../items/singleItem'),
|
||||||
AddToCart = require('../cart/addToCart');
|
AddToCart = require('../cart/addToCart'),
|
||||||
|
Globals = require('../../globals');
|
||||||
|
;
|
||||||
|
|
||||||
var Router = require('react-router');
|
var Router = require('react-router');
|
||||||
|
|
||||||
|
|
||||||
var ItemWithDetailsPage = React.createClass({
|
var CartPage = React.createClass({
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
|
|
||||||
|
var counts = this.state.itemCounts;
|
||||||
|
|
||||||
var displayedItems = this.state.items.map(function (i) {
|
var displayedItems = this.state.items.map(function (i) {
|
||||||
|
|
||||||
|
var count = counts[i.get('id')].get('count');
|
||||||
|
var price = i.get('list_price');
|
||||||
return (
|
return (
|
||||||
<div key={i.get('id')} className="row">
|
<div key={i.get('id')} className="row cart-items">
|
||||||
<div className="col-md-3"><SingleItem item={i} /> </div>
|
<div className="col-md-3"><SingleItem item={i} hidePrice={true}/> </div>
|
||||||
<div className="col-md-6"> <AddToCart itemId={i.get('id')} /> </div>
|
<div className="col-md-2"> { Globals.FormatCurrency(price) }</div>
|
||||||
|
<div className="col-md-1"> X </div>
|
||||||
|
<div className="col-md-3"> <AddToCart itemId={i.get('id')} /> </div>
|
||||||
|
<div className="col-md-1"> = </div>
|
||||||
|
<div className="col-md-2"> { Globals.FormatCurrency(count * price) }</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
@@ -54,4 +65,4 @@ var ItemWithDetailsPage = React.createClass({
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
module.exports = ItemWithDetailsPage;
|
module.exports = CartPage;
|
||||||
|
|||||||
@@ -7,17 +7,28 @@ var Router = require('react-router');
|
|||||||
|
|
||||||
var SingleItem = React.createClass({
|
var SingleItem = React.createClass({
|
||||||
render: function() {
|
render: function() {
|
||||||
|
var hidePrice = this.props.hidePrice || false;
|
||||||
var self = this;
|
var self = this;
|
||||||
var itemClick = this.itemClick;
|
var itemClick = this.itemClick;
|
||||||
var firstImage = this.props.item.get('multi_media_descriptions')[0];
|
var firstImage = this.props.item.get('multi_media_descriptions')[0];
|
||||||
firstImage = firstImage || { url: "https://res.cloudinary.com/lfvt7ps2n/image/upload/c_crop,g_center,w_300/v1421732950/http_www.asms.ru_bitrix_templates_main_images_nophoto_irnofq.png" } ;
|
firstImage = firstImage || { url: "https://res.cloudinary.com/lfvt7ps2n/image/upload/c_crop,g_center,w_300/v1421732950/http_www.asms.ru_bitrix_templates_main_images_nophoto_irnofq.png" } ;
|
||||||
return (
|
if (hidePrice) {
|
||||||
|
return (
|
||||||
<div className="single_item" onClick={itemClick}>
|
<div className="single_item" onClick={itemClick}>
|
||||||
<img src={firstImage.url} className="item_list_image" />
|
<img src={firstImage.url} className="item_list_image" />
|
||||||
<h1> { this.props.item.get('name') }</h1>
|
<h1> { this.props.item.get('name') }</h1>
|
||||||
<div> { this.props.item.get('list_price') } KM </div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return (
|
||||||
|
<div className="single_item" onClick={itemClick}>
|
||||||
|
<img src={firstImage.url} className="item_list_image" />
|
||||||
|
<h1> { this.props.item.get('name') }</h1>
|
||||||
|
<div> { this.props.item.get('list_price') } KM </div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
itemClick: function(e) {
|
itemClick: function(e) {
|
||||||
|
|||||||
@@ -19,3 +19,13 @@
|
|||||||
right: -10px;
|
right: -10px;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.add-to-cart button {
|
||||||
|
font-size: 20px;
|
||||||
|
margin: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cart-items {
|
||||||
|
vertical-align:middle;
|
||||||
|
font-size: 17px;
|
||||||
|
}
|
||||||
@@ -1,3 +1,7 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
ApiUrl: 'http://localhost:4567'
|
ApiUrl: 'http://localhost:4567',
|
||||||
|
FormatCurrency: function(amount_s) {
|
||||||
|
var amount = parseFloat(amount_s);
|
||||||
|
return ( amount.toFixed(2) + " KM" )
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -102,7 +102,8 @@ var CartStore = _.extend({}, EventEmitter.prototype, {
|
|||||||
|
|
||||||
var state = {
|
var state = {
|
||||||
count: numberOfItems,
|
count: numberOfItems,
|
||||||
items: _itemsForDisplay
|
items: _itemsForDisplay,
|
||||||
|
itemCounts: states
|
||||||
};
|
};
|
||||||
return state;
|
return state;
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user