function fuBuyNow() {
var prodqty = 1;
var prodid = localStorage.ls_productID;
var prodprice = $('#ppriceoffer').html();
var cartItem = {
productid: prodid,
productqty: prodqty,
productprice: prodprice
};
var cartItemJSON = JSON.stringify(cartItem);
console.log(cartItemJSON);
var cartArray = new Array();
// If javascript shopping cart session is not empty
if (localStorage.getItem('shopping-cart')) {
cartArray = JSON.parse(localStorage.getItem('shopping-cart'));
}
cartArray.push(cartItemJSON);
var cartJSON = JSON.stringify(cartArray);
localStorage.setItem('shopping-cart', cartJSON);
}
now i have cart data in an array, I want to sum of
var obj = "[{"slno":"1","productid":"10001","qty":"1","price":"250"},{"slno":"2","productid":"10005","qty":"1","price":"350"},{"slno":"3","productid":"10001","qty":"1","price":"250"},{"slno":"4","productid":"10003","qty":"1","price":"450"},{"slno":"5","productid":"10005","qty":"1","price":"350"}]";
Я пытаюсь создать корзину с помощью js [code] function fuBuyNow() {
var prodqty = 1; var prodid = localStorage.ls_productID; var prodprice = $('#ppriceoffer').html(); var cartItem = { productid: prodid, productqty: prodqty, productprice: prodprice }; var cartItemJSON = JSON.stringify(cartItem); console.log(cartItemJSON);
var cartArray = new Array(); // If javascript shopping cart session is not empty if (localStorage.getItem('shopping-cart')) { cartArray = JSON.parse(localStorage.getItem('shopping-cart')); } cartArray.push(cartItemJSON);
var cartJSON = JSON.stringify(cartArray); localStorage.setItem('shopping-cart', cartJSON);
} [/code] now i have cart data in an array, I want to sum of [code]productid[/code] = 10005, [code]productid[/code] = 10001 price and create new array [code]var obj = "[{"slno":"1","productid":"10001","qty":"1","price":"250"},{"slno":"2","productid":"10005","qty":"1","price":"350"},{"slno":"3","productid":"10001","qty":"1","price":"250"},{"slno":"4","productid":"10003","qty":"1","price":"450"},{"slno":"5","productid":"10005","qty":"1","price":"350"}]"; [/code]