feat(api): integrated /cart and /order api's

This commit is contained in:
Azmat Ali
2026-03-09 15:23:32 +05:30
parent ea0835b564
commit c7549b1009
5 changed files with 138 additions and 2 deletions
+32
View File
@@ -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")