context = window MIX_MODES = context.JK.MIX_MODES @ShoppingCartContents = React.createClass({ mixins: [Reflux.listenTo(@AppStore, "onAppInit"), Reflux.listenTo(@UserStore, "onUserChanged")] render: () -> carts = [] if this.props.carts? if this.props.carts.length == 0 carts = `
You have nothing in your cart
` else taxRate = 0 if this.props.tax taxRate = 0.0825 estimatedTax = 0 estimatedTotal = 0 for cart in this.props.carts cart_quantity = cart.product_info.quantity - cart.product_info.marked_for_redeem estimatedTax += cart.product_info.price * cart_quantity * taxRate estimatedTotal += cart.product_info.price * cart_quantity estimatedTax = Math.round(estimatedTax * 100) / 100 estimatedTotal = Math.round((estimatedTotal + estimatedTax) * 100) / 100 for cart in this.props.carts console.log("CART", cart) freeNotice = null if cart.product_info.free freeNotice = `| (first one free)` carts.push(`
{cart.product_info.sale_display} {freeNotice}
$ {Number(cart.product_info.real_price).toFixed(2)}
{cart.quantity}
`) carts.push(`
Tax
$ {estimatedTax.toFixed(2)}
`) carts.push(`
Total
$ {estimatedTotal.toFixed(2)}
`) else carts = `
Loading...
` `
YOUR ORDER INCLUDES:
PRICE
QUANTITY
{carts}
` onAppInit: (@app) -> @EVENTS = context.JK.EVENTS @rest = context.JK.Rest() @logger = context.JK.logger onUserChanged: (userState) -> @user = userState?.user })