From a8ff82ad1e4e9c1e9d099dce4cada20fa8d52037 Mon Sep 17 00:00:00 2001 From: moepoi Date: Fri, 19 Nov 2021 12:42:19 +0700 Subject: [PATCH] Update checkout --- public/js/checkout.js | 40 ++++++++++++++++++++++++++++++++++++++++ views/pages/checkout.ejs | 10 +--------- 2 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 public/js/checkout.js diff --git a/public/js/checkout.js b/public/js/checkout.js new file mode 100644 index 0000000..a48b4d3 --- /dev/null +++ b/public/js/checkout.js @@ -0,0 +1,40 @@ +function view_checkout() { + 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}

+

${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; +} + +view_checkout(); \ No newline at end of file diff --git a/views/pages/checkout.ejs b/views/pages/checkout.ejs index f6cdc7e..0d8821c 100644 --- a/views/pages/checkout.ejs +++ b/views/pages/checkout.ejs @@ -19,15 +19,7 @@ Sub Total - - <%- include('../layouts/checkouttr.ejs') %> - <%- include('../layouts/checkouttr.ejs') %> - <%- include('../layouts/checkouttr.ejs') %> - - Total Price - - Rp 5.999.997,00 - +