Last active
December 26, 2015 11:39
-
-
Save drewblumberg/7145555 to your computer and use it in GitHub Desktop.
js add products to cart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var productName = $(this).parent().parent().children('.product-name').text(); | |
var product = _.find(db.products, function(p) { return p.name === productName;}); | |
var isAdded = _.find(db.cart.products, function(p){ return p.name === productName; }) === undefined ? false : true; | |
if(db.customers.length) { | |
if(!db.cart.customer) { | |
db.cart.customer = _.find(db.customers, function(cust) { return cust.name === $('#select-customer').val();}); | |
} | |
if(!isAdded) { | |
db.cart.products.push(product); | |
db.cart.totals.count++; | |
db.cart.totals.amount += product.salePrice(); | |
db.cart.totals.weight += product.weight; | |
var shippingCost = db.cart.customer.isDomestic ? 0.5 : 1.5; | |
db.cart.totals.shipping += product.weight * shippingCost; | |
// htmlAddCartRow(product); | |
} else { | |
db.cart.products.push(product); | |
db.cart.totals.count++; | |
db.cart.totals.amount += product.price; | |
db.cart.totals.weight += product.weight; | |
var shippingCost2 = db.cart.customer.isDomestic ? 0.5 : 1.5; | |
db.cart.totals.shipping += product.weight * shippingCost2; | |
// htmlUpdateCartRow(product); | |
} | |
db.cart.totals.grand = db.cart.totals.amount + db.cart.totals.shipping; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment