function proceedCheckout() { localStorage.removeItem("bag"); } function view_checkout() { if (localStorage.getItem("bag") === null) { localStorage.setItem("bag", "[]"); } var bag = JSON.parse(localStorage.getItem("bag")); var html = ''; var total_price = 0; for (var i = 0; i < bag.length; i++) { let request = new XMLHttpRequest(); request.open('GET', `api/getProduct?id=${bag[i].product_id}`, false); request.send(null); if (request.status === 200) { let data = JSON.parse(request.responseText); total_price += parseInt(data[0].PRICE * bag[i].quantity); html += ` placeholder image

${data[0].TITLE}

Size : ${data[0].SIZE}

Qty : ${bag[i].quantity}

Rp ${data[0].PRICE} Rp ${data[0].PRICE * bag[i].quantity} `; } } html += ` Total Price Rp ${total_price} ` document.getElementById("view-checkout").innerHTML = html; document.getElementById("data").value = JSON.stringify(bag); } view_checkout();