From 05344fb6fc07481edceda8a3854fc56e16442137 Mon Sep 17 00:00:00 2001 From: PURVA ATHNERE <93878803+purvathnere@users.noreply.github.com> Date: Sun, 16 Jun 2024 14:42:59 +0530 Subject: [PATCH 1/2] Update viewcart --- viewcart/viewcart.js | 52 ++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/viewcart/viewcart.js b/viewcart/viewcart.js index 172262e7..7d41839b 100644 --- a/viewcart/viewcart.js +++ b/viewcart/viewcart.js @@ -1,4 +1,4 @@ -//Date and Time +// Date and Time const today = new Date(); const nextThreeDays = new Date(today); nextThreeDays.setDate(today.getDate() + 3); @@ -7,8 +7,9 @@ const daysOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Fri const dayOfWeek = daysOfWeek[nextThreeDays.getDay()]; const date = nextThreeDays.toLocaleDateString(); -//Cart JS -//Function to save data to local storage +// Cart JS + +// Function to save data to local storage function saveToLocalStorage(key, newData) { let existingData = getFromLocalStorage(key) || []; @@ -60,10 +61,20 @@ function fetchCartData(item) { totalItems += 1; totalPrice += item.price; + const discont=(Math.floor(item.rating*(parseInt((item.price.toString()).slice(0,2)))/10)) + const afterDiscontPrice=Math.round((100-discont)*item.price/100) + + function formatIndianRupee(number) { + const parts = number.toString().split("."); + const integerPart = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ","); + const formattedNumber = parts.length > 1 ? integerPart + "." + parts[1] : integerPart; + return formattedNumber; + } + return `
-
+
${item.name}
@@ -72,8 +83,8 @@ function fetchCartData(item) {

Forest Green Strap, Regular

Seller: Ezig

-
- ₹${item.price} 1 offer applied +
₹${formatIndianRupee(afterDiscontPrice)} ₹${formatIndianRupee(item.price)} ${discont}% off + 1 offer applied
@@ -84,9 +95,9 @@ function fetchCartData(item) {
- -
- +   +
  +
@@ -150,28 +161,36 @@ function updateCartDisplay(filteredProducts) { // Function to update the price detail section function updatePriceDetail(products) { + function formatIndianRupee(number) { + const parts = number.toString().split("."); + const integerPart = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ","); + const formattedNumber = parts.length > 1 ? integerPart + "." + parts[1] : integerPart; + return formattedNumber; + } totalItems = products.length; - totalPrice = products.reduce((acc, item) => acc + item.price, 0); - + totalMRP = products.reduce((acc, item) => acc + (item.price), 0); + totalPrice = products.reduce((acc, item) => acc + (Math.round((100-((Math.floor(item.rating*(parseInt((item.price.toString()).slice(0,2)))/10))))*item.price/100)), 0); + totalDiscount=totalMRP-totalPrice + let priceDetail = `
Price (${totalItems} items)
-
₹${totalPrice}
+
₹${formatIndianRupee(totalMRP)}
Discount
-
0
+
₹${formatIndianRupee(totalDiscount)}
Delivery Charges
Free
-
Total Amount
-
₹${totalPrice}
+
Total Amount
+
₹${formatIndianRupee(totalPrice)}
-
You will save ₹40 on this order
+
You will save ₹${formatIndianRupee(totalDiscount)} on this order
`; @@ -195,4 +214,5 @@ fetch("../json-api/product.json") searchFetch(savedFilteredProducts); }) .catch(error => console.error("Error fetching data:", error)); + // end From 935cce248f45c98e71002d7fa094f75312abb6c8 Mon Sep 17 00:00:00 2001 From: PURVA ATHNERE <93878803+purvathnere@users.noreply.github.com> Date: Sun, 16 Jun 2024 14:51:23 +0530 Subject: [PATCH 2/2] Update viewcart