var React = require('react'),
CartStore = require('../../stores/cartStore'),
AddToCart = require('../cart/addToCart'),
CartActions = require('../../actions/cartActions'),
NavigationActions = require('../../actions/navigationActions'),
SingleItem = require('../items/singleItem'),
Globals = require('../../globals'),
CartTotal = require('./cartTotal');
var Router = require('react-router');
var CartPage = React.createClass({
render: function() {
var counts = this.state.itemCounts;
var displayedItems = this.state.items.map(function (i) {
var count = counts[i.get('id')].get('count');
var price = i.get('list_price');
return (
{ Globals.FormatCurrency(price) }
X
=
{ Globals.FormatCurrency(count * price) }
)
});
var cartTotal = (
);
return (
{cartTotal}
{displayedItems}
{cartTotal}
);
},
// Add change listeners to stores
componentDidMount: function() {
CartStore.addChangeListener(this._onChange);
CartActions.load();
},
componentWillUnmount: function () {
CartStore.removeChangeListener(this._onChange);
},
_onChange: function () {
if (this.isMounted()) {
this.setState(CartStore.getWholeCartState());
}
},
_onOrderClick: function () {
NavigationActions.goToCheckout();
},
getInitialState: function () {
return CartStore.getWholeCartState();
}
});
module.exports = CartPage;