feat(api): integrated /cart and /order api's
This commit is contained in:
@@ -160,6 +160,38 @@
|
||||
<script src="assets/js/cart.js"></script>
|
||||
|
||||
<script>
|
||||
const checkoutBtn = document.getElementById("btn-checkout");
|
||||
|
||||
if (checkoutBtn) {
|
||||
checkoutBtn.addEventListener("click", async () => {
|
||||
try {
|
||||
checkoutBtn.classList.add("loading");
|
||||
checkoutBtn.disabled = true;
|
||||
|
||||
console.log("/api/cart hit");
|
||||
|
||||
const cart = Cart.getCart();
|
||||
|
||||
const res = await fetch("/.netlify/functions/cart", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(cart),
|
||||
});
|
||||
|
||||
console.log(res);
|
||||
|
||||
window.location.href = "checkout.html";
|
||||
} catch (err) {
|
||||
console.error("Cart API failed", err);
|
||||
} finally {
|
||||
checkoutBtn.classList.remove("loading");
|
||||
checkoutBtn.disabled = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function applyCoupon() {
|
||||
const code = document
|
||||
.getElementById("coupon-input")
|
||||
|
||||
Reference in New Issue
Block a user