diff --git a/.history/addtokart/index_20240720195426.html b/.history/addtokart/index_20240720195426.html deleted file mode 100644 index 30dfdc01..00000000 --- a/.history/addtokart/index_20240720195426.html +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - Flipkart | Online Shopping Site for Mobiles, Electronics, Furniture, Grocery, Lifestyle, Books & More. - Best Offers! - - - - - - -
- This is Header -
- - -
-
-
-
-
-
-
-
- - -
-
Similar products
-
-
-
- - - - - - - - \ No newline at end of file diff --git a/.history/addtokart/index_20240720205151.html b/.history/addtokart/index_20240720205151.html deleted file mode 100644 index 66d7c5c2..00000000 --- a/.history/addtokart/index_20240720205151.html +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - Flipkart | Online Shopping Site for Mobiles, Electronics, Furniture, Grocery, Lifestyle, Books & More. Best Offers! - - - - - - -
- This is Header -
- - -
-
-
-
-
-
-
-
- - -
-
Similar products
-
-
-
- - - - - - - - \ No newline at end of file diff --git a/.history/viewcart/viewcart_20240720195426.js b/.history/viewcart/viewcart_20240720195426.js deleted file mode 100644 index 2e7dad5f..00000000 --- a/.history/viewcart/viewcart_20240720195426.js +++ /dev/null @@ -1,228 +0,0 @@ -// Date and Time -const today = new Date(); -const nextThreeDays = new Date(today); -nextThreeDays.setDate(today.getDate() + 3); - -const daysOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; -const dayOfWeek = daysOfWeek[nextThreeDays.getDay()]; -const date = nextThreeDays.toLocaleDateString(); - -// Cart JS - -// Function to save data to local storage -function saveToLocalStorage(key, newData) { - let existingData = getFromLocalStorage(key) || []; - - // Check for duplicates and add only unique products - newData.forEach(newProduct => { - const isDuplicate = existingData.some(existingProduct => existingProduct.name === newProduct.name); - if (!isDuplicate) { - existingData.push(newProduct); - } - }); - - localStorage.setItem(key, JSON.stringify(existingData)); -} - -// Function to retrieve data from local storage -function getFromLocalStorage(key) { - const data = localStorage.getItem(key); - return data ? JSON.parse(data) : []; -} - -// Function to get query parameter -function getQueryParameter(name) { - const urlParams = new URLSearchParams(window.location.search); - return urlParams.get(name); -} - -// Function to display search results -function searchFetch(products) { - const searchList = document.getElementById("itemsInCart"); - searchList.innerHTML = products.map(product => fetchCartData(product)).join(""); - - // Add event listeners for remove buttons - document.querySelectorAll('.cartItmSfLRmBtn.remove').forEach(button => { - button.addEventListener('click', function () { - const productName = this.getAttribute('data-name'); - confirmRemoveItem(productName); - }); - }); - - updateCartDisplay(products); - updatePriceDetail(products); -} - -let totalPrice = 0; -let totalItems = 0; - -// Function to generate HTML for a cart item -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} -
-
-
-

${item.name}

-

Forest Green Strap, Regular

-

Seller: Ezig

-
-
₹${formatIndianRupee(afterDiscontPrice)} ₹${formatIndianRupee(item.price)} ${discont}% off - 1 offer applied -
-
-
- Delivery by ${dayOfWeek}, ${date} | ₹40 Free -
-
-
-
-
-
-   -
  - -
-
-
-
Save for later
-
Remove
-
-
-
-
- `; -} -// Function to confirm and remove an item from the cart -function confirmRemoveItem(name) { - const confirmRemove = confirm(`Are you sure you want to remove "${name}" from the cart?`); - if (confirmRemove) { - removeItem(name); - } -} - -// Function to remove an item from the cart -function removeItem(name) { - let existingData = getFromLocalStorage("filteredProducts") || []; - const updatedData = existingData.filter(item => item.name !== name); - localStorage.setItem("filteredProducts", JSON.stringify(updatedData)); - - // Update the displayed cart and price details - searchFetch(updatedData); - - // Show success popup - showPopup(`"${name}" has been removed from your cart successfully.`); -} - -// Function to show a popup message -function showPopup(message) { - const popup = document.getElementById('popupCartItem'); - popup.textContent = message; - popup.classList.remove('hidden'); - popup.classList.add('visible'); - - // Hide the popup after 1 second - setTimeout(() => { - popup.classList.remove('visible'); - popup.classList.add('hidden'); - }, 3000); -} - -// Function to show or hide cart based on product list -function updateCartDisplay(filteredProducts) { - let cartInProduct = document.getElementById("cardInProduct"); - let cartisEmpty = document.getElementById("cardisEmpty"); - - if (filteredProducts.length === 0) { - cartInProduct.style.display = "none"; - cartisEmpty.style.display = "block"; - } else { - cartInProduct.style.display = "block"; - cartisEmpty.style.display = "none"; - } -} - -// 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; - 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)
-
₹${formatIndianRupee(totalMRP)}
-
-
-
Discount
-
₹${formatIndianRupee(totalDiscount)}
-
-
-
Delivery Charges
-
Free
-
-
-
Total Amount
-
₹${formatIndianRupee(totalPrice)}
-
-
You will save ₹${formatIndianRupee(totalDiscount)} on this order
-
- `; - - document.getElementById("priceDetail").innerHTML = priceDetail; -} - -// Fetch data from the JSON file and filter products based on the query -fetch("https://raw.githubusercontent.com/csathnere/APIs/main/json-ec/product.json") - .then(response => response.json()) - .then(data => { - const query = getQueryParameter("query"); - const filteredProducts = data.filter(product => product.name === query); - - // Save filtered products to local storage without overwriting existing data - saveToLocalStorage("filteredProducts", filteredProducts); - - // Retrieve updated filtered products from local storage - const savedFilteredProducts = getFromLocalStorage("filteredProducts"); - - // Display the filtered products - searchFetch(savedFilteredProducts); - }) - .catch(error => console.error("Error fetching data:", error)); - -// end diff --git a/.history/viewcart/viewcart_20240720203845.js b/.history/viewcart/viewcart_20240720203845.js deleted file mode 100644 index 318f313b..00000000 --- a/.history/viewcart/viewcart_20240720203845.js +++ /dev/null @@ -1,243 +0,0 @@ -// Date and Time -const today = new Date(); -const nextThreeDays = new Date(today); -nextThreeDays.setDate(today.getDate() + 3); - -const daysOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; -const dayOfWeek = daysOfWeek[nextThreeDays.getDay()]; -const date = nextThreeDays.toLocaleDateString(); - -// Cart JS - -// Function to save data to local storage -function saveToLocalStorage(key, newData) { - let existingData = getFromLocalStorage(key) || []; - - // Check for duplicates and add only unique products - newData.forEach(newProduct => { - const isDuplicate = existingData.some(existingProduct => existingProduct.name === newProduct.name); - if (!isDuplicate) { - existingData.push(newProduct); - } - }); - - localStorage.setItem(key, JSON.stringify(existingData)); -} - -// Function to retrieve data from local storage -function getFromLocalStorage(key) { - const data = localStorage.getItem(key); - return data ? JSON.parse(data) : []; -} - -// Function to get query parameter -function getQueryParameter(name) { - const urlParams = new URLSearchParams(window.location.search); - return urlParams.get(name); -} - -// Function to display search results -function searchFetch(products) { - const searchList = document.getElementById("itemsInCart"); - searchList.innerHTML = products.map((product, index) => fetchCartData(product, index)).join(""); // Added index parameter - - // Add event listeners for remove buttons - document.querySelectorAll('.cartItmSfLRmBtn.remove').forEach(button => { - button.addEventListener('click', function() { - const productName = this.getAttribute('data-name'); - confirmRemoveItem(productName); - }); - }); - - updateCartDisplay(products); - updatePriceDetail(products); -} - - -let totalPrice = 0; -let totalItems = 0; -// Function to increase the quantity of a specific item -function increaseQuantity(index) { // Added function to handle increasing quantity - const input = document.getElementById(`quantity-${index}`); // Use index to target specific input - input.value = Number(input.value) + 1; -} - -// Function to decrease the quantity of a specific item -function decreaseQuantity(index) { // Added function to handle decreasing quantity - const input = document.getElementById(`quantity-${index}`); // Use index to target specific input - const currentValue = Number(input.value); - if (currentValue > 1) { - input.value = currentValue - 1; - } else { - const productName = input.closest('.cartItmListInviewCart').querySelector('.remove').getAttribute('data-name'); - confirmRemoveItem(productName); - } -} - -// Function to generate HTML for a cart item -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 fetchCartData(item, index) { // Added index parameter - totalItems += 1; - totalPrice += item.price; - - const discount = (Math.floor(item.rating * (parseInt((item.price.toString()).slice(0, 2))) / 10)) - const afterDiscountPrice = Math.round((100 - discount) * 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} -
-
-
-

${item.name}

-

Forest Green Strap, Regular

-

Seller: Ezig

-
-
₹${formatIndianRupee(afterDiscountPrice)} ₹${formatIndianRupee(item.price)} ${discount}% off - 1 offer applied -
-
-
- Delivery by ${dayOfWeek}, ${date} | ₹40 Free -
-
-
-
-
-
-   -
  - -
-
-
-
Save for later
-
Remove
-
-
-
-
- `; - } -} -// Function to confirm and remove an item from the cart -function confirmRemoveItem(name) { - const confirmRemove = confirm(`Are you sure you want to remove "${name}" from the cart?`); - if (confirmRemove) { - removeItem(name); - } -} - -// Function to remove an item from the cart -function removeItem(name) { - let existingData = getFromLocalStorage("filteredProducts") || []; - const updatedData = existingData.filter(item => item.name !== name); - localStorage.setItem("filteredProducts", JSON.stringify(updatedData)); - - // Update the displayed cart and price details - searchFetch(updatedData); - - // Show success popup - showPopup(`"${name}" has been removed from your cart successfully.`); -} - -// Function to show a popup message -function showPopup(message) { - const popup = document.getElementById('popupCartItem'); - popup.textContent = message; - popup.classList.remove('hidden'); - popup.classList.add('visible'); - - // Hide the popup after 1 second - setTimeout(() => { - popup.classList.remove('visible'); - popup.classList.add('hidden'); - }, 3000); -} - -// Function to show or hide cart based on product list -function updateCartDisplay(filteredProducts) { - let cartInProduct = document.getElementById("cardInProduct"); - let cartisEmpty = document.getElementById("cardisEmpty"); - - if (filteredProducts.length === 0) { - cartInProduct.style.display = "none"; - cartisEmpty.style.display = "block"; - } else { - cartInProduct.style.display = "block"; - cartisEmpty.style.display = "none"; - } -} - -// 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; - 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)
-
₹${formatIndianRupee(totalMRP)}
-
-
-
Discount
-
₹${formatIndianRupee(totalDiscount)}
-
-
-
Delivery Charges
-
Free
-
-
-
Total Amount
-
₹${formatIndianRupee(totalPrice)}
-
-
You will save ₹${formatIndianRupee(totalDiscount)} on this order
-
- `; - - document.getElementById("priceDetail").innerHTML = priceDetail; -} - -// Fetch data from the JSON file and filter products based on the query -fetch("https://raw.githubusercontent.com/csathnere/APIs/main/json-ec/product.json") - .then(response => response.json()) - .then(data => { - const query = getQueryParameter("query"); - const filteredProducts = data.filter(product => product.name === query); - - // Save filtered products to local storage without overwriting existing data - saveToLocalStorage("filteredProducts", filteredProducts); - - // Retrieve updated filtered products from local storage - const savedFilteredProducts = getFromLocalStorage("filteredProducts"); - - // Display the filtered products - searchFetch(savedFilteredProducts); - }) - .catch(error => console.error("Error fetching data:", error)); - -// end \ No newline at end of file diff --git a/.history/viewcart/viewcart_20240720204749.js b/.history/viewcart/viewcart_20240720204749.js deleted file mode 100644 index 335782a6..00000000 --- a/.history/viewcart/viewcart_20240720204749.js +++ /dev/null @@ -1,233 +0,0 @@ -// Existing code... - -const today = new Date(); -const nextThreeDays = new Date(today); -nextThreeDays.setDate(today.getDate() + 3); - -const daysOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; -const dayOfWeek = daysOfWeek[nextThreeDays.getDay()]; -const date = nextThreeDays.toLocaleDateString(); - -// Cart JS - -// Function to save data to local storage -function saveToLocalStorage(key, newData) { - let existingData = getFromLocalStorage(key) || []; - - // Check for duplicates and add only unique products - newData.forEach(newProduct => { - const isDuplicate = existingData.some(existingProduct => existingProduct.name === newProduct.name); - if (!isDuplicate) { - existingData.push(newProduct); - } - }); - - localStorage.setItem(key, JSON.stringify(existingData)); -} - -// Function to retrieve data from local storage -function getFromLocalStorage(key) { - const data = localStorage.getItem(key); - return data ? JSON.parse(data) : []; -} - -// Function to get query parameter -function getQueryParameter(name) { - const urlParams = new URLSearchParams(window.location.search); - return urlParams.get(name); -} - -// Function to display search results -function searchFetch(products) { - const searchList = document.getElementById("itemsInCart"); - searchList.innerHTML = products.map((product, index) => fetchCartData(product, index)).join(""); // Added index parameter to the map function - - // Add event listeners for remove buttons - document.querySelectorAll('.cartItmSfLRmBtn.remove').forEach(button => { - button.addEventListener('click', function() { - const productName = this.getAttribute('data-name'); - confirmRemoveItem(productName); - }); - }); - - updateCartDisplay(products); - updatePriceDetail(products); -} - -let totalPrice = 0; -let totalItems = 0; - -// Function to generate HTML for a cart item -function fetchCartData(item, index) { // Added index parameter to the function - totalItems += 1; - totalPrice += item.price; - - const discount = (Math.floor(item.rating * (parseInt((item.price.toString()).slice(0, 2))) / 10)); - const afterDiscountPrice = Math.round((100 - discount) * 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} -
-
-
-

${item.name}

-

Forest Green Strap, Regular

-

Seller: Ezig

-
-
₹${formatIndianRupee(afterDiscountPrice)} ₹${formatIndianRupee(item.price)} ${discount}% off - 1 offer applied -
-
-
- Delivery by ${dayOfWeek}, ${date} | ₹40 Free -
-
-
-
-
-
-   -
  - -
-
-
-
Save for later
-
Remove
-
-
-
-
- `; -} - -// Function to increase the quantity of a specific item -function increaseQuantity(index) { // Added function to handle increasing quantity - const input = document.getElementById(`quantity-${index}`); // Use index to target specific input - input.value = Number(input.value) + 1; -} - -// Function to decrease the quantity of a specific item -function decreaseQuantity(index) { // Added function to handle decreasing quantity - const input = document.getElementById(`quantity-${index}`); // Use index to target specific input - const currentValue = Number(input.value); - if (currentValue > 1) { - input.value = currentValue - 1; - } else { - const productName = input.closest('.cartItmListInviewCart').querySelector('.remove').getAttribute('data-name'); - confirmRemoveItem(productName); - } -} - -// Function to confirm and remove an item from the cart -function confirmRemoveItem(name) { - const confirmRemove = confirm(`Are you sure you want to remove "${name}" from the cart?`); - if (confirmRemove) { - removeItem(name); - } -} - -// Function to remove an item from the cart -function removeItem(name) { - let existingData = getFromLocalStorage("filteredProducts") || []; - const updatedData = existingData.filter(item => item.name !== name); - localStorage.setItem("filteredProducts", JSON.stringify(updatedData)); - - // Update the displayed cart and price details - searchFetch(updatedData); - - // Show success popup - showPopup(`"${name}" has been removed from your cart successfully.`); -} - -// Function to show a popup message -function showPopup(message) { - const popup = document.getElementById('popupCartItem'); - popup.textContent = message; - popup.classList.remove('hidden'); - popup.classList.add('visible'); - - // Hide the popup after 1 second - setTimeout(() => { - popup.classList.remove('visible'); - popup.classList.add('hidden'); - }, 3000); -} - -// Function to show or hide cart based on product list -function updateCartDisplay(filteredProducts) { - let cartInProduct = document.getElementById("cardInProduct"); - let cartisEmpty = document.getElementById("cardisEmpty"); - - if (filteredProducts.length === 0) { - cartInProduct.style.display = "none"; - cartisEmpty.style.display = "block"; - } else { - cartInProduct.style.display = "block"; - cartisEmpty.style.display = "none"; - } -} - -// 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; - 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)
-
₹${formatIndianRupee(totalMRP)}
-
-
-
Discount
-
₹${formatIndianRupee(totalDiscount)}
-
-
-
Delivery Charges
-
Free
-
-
-
Total Amount
-
₹${formatIndianRupee(totalPrice)}
-
-
` - - document.getElementById("priceDetail").innerHTML = priceDetail; -} - -// Fetch and display data -fetch("https://raw.githubusercontent.com/csathnere/APIs/main/json-ec/product.json") - .then(response => response.json()) - .then(data => { - const query = getQueryParameter("query"); - const filteredProducts = data.filter(product => product.name === query); - - // Save filtered products to local storage without overwriting existing data - saveToLocalStorage("filteredProducts", filteredProducts); - - // Retrieve updated filtered products from local storage - const savedFilteredProducts = getFromLocalStorage("filteredProducts"); - - // Display the filtered products - searchFetch(savedFilteredProducts); - }) - .catch(error => console.error("Error fetching data:", error)); \ No newline at end of file diff --git a/.history/viewcart/viewcart_20240720205155.js b/.history/viewcart/viewcart_20240720205155.js deleted file mode 100644 index 335782a6..00000000 --- a/.history/viewcart/viewcart_20240720205155.js +++ /dev/null @@ -1,233 +0,0 @@ -// Existing code... - -const today = new Date(); -const nextThreeDays = new Date(today); -nextThreeDays.setDate(today.getDate() + 3); - -const daysOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; -const dayOfWeek = daysOfWeek[nextThreeDays.getDay()]; -const date = nextThreeDays.toLocaleDateString(); - -// Cart JS - -// Function to save data to local storage -function saveToLocalStorage(key, newData) { - let existingData = getFromLocalStorage(key) || []; - - // Check for duplicates and add only unique products - newData.forEach(newProduct => { - const isDuplicate = existingData.some(existingProduct => existingProduct.name === newProduct.name); - if (!isDuplicate) { - existingData.push(newProduct); - } - }); - - localStorage.setItem(key, JSON.stringify(existingData)); -} - -// Function to retrieve data from local storage -function getFromLocalStorage(key) { - const data = localStorage.getItem(key); - return data ? JSON.parse(data) : []; -} - -// Function to get query parameter -function getQueryParameter(name) { - const urlParams = new URLSearchParams(window.location.search); - return urlParams.get(name); -} - -// Function to display search results -function searchFetch(products) { - const searchList = document.getElementById("itemsInCart"); - searchList.innerHTML = products.map((product, index) => fetchCartData(product, index)).join(""); // Added index parameter to the map function - - // Add event listeners for remove buttons - document.querySelectorAll('.cartItmSfLRmBtn.remove').forEach(button => { - button.addEventListener('click', function() { - const productName = this.getAttribute('data-name'); - confirmRemoveItem(productName); - }); - }); - - updateCartDisplay(products); - updatePriceDetail(products); -} - -let totalPrice = 0; -let totalItems = 0; - -// Function to generate HTML for a cart item -function fetchCartData(item, index) { // Added index parameter to the function - totalItems += 1; - totalPrice += item.price; - - const discount = (Math.floor(item.rating * (parseInt((item.price.toString()).slice(0, 2))) / 10)); - const afterDiscountPrice = Math.round((100 - discount) * 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} -
-
-
-

${item.name}

-

Forest Green Strap, Regular

-

Seller: Ezig

-
-
₹${formatIndianRupee(afterDiscountPrice)} ₹${formatIndianRupee(item.price)} ${discount}% off - 1 offer applied -
-
-
- Delivery by ${dayOfWeek}, ${date} | ₹40 Free -
-
-
-
-
-
-   -
  - -
-
-
-
Save for later
-
Remove
-
-
-
-
- `; -} - -// Function to increase the quantity of a specific item -function increaseQuantity(index) { // Added function to handle increasing quantity - const input = document.getElementById(`quantity-${index}`); // Use index to target specific input - input.value = Number(input.value) + 1; -} - -// Function to decrease the quantity of a specific item -function decreaseQuantity(index) { // Added function to handle decreasing quantity - const input = document.getElementById(`quantity-${index}`); // Use index to target specific input - const currentValue = Number(input.value); - if (currentValue > 1) { - input.value = currentValue - 1; - } else { - const productName = input.closest('.cartItmListInviewCart').querySelector('.remove').getAttribute('data-name'); - confirmRemoveItem(productName); - } -} - -// Function to confirm and remove an item from the cart -function confirmRemoveItem(name) { - const confirmRemove = confirm(`Are you sure you want to remove "${name}" from the cart?`); - if (confirmRemove) { - removeItem(name); - } -} - -// Function to remove an item from the cart -function removeItem(name) { - let existingData = getFromLocalStorage("filteredProducts") || []; - const updatedData = existingData.filter(item => item.name !== name); - localStorage.setItem("filteredProducts", JSON.stringify(updatedData)); - - // Update the displayed cart and price details - searchFetch(updatedData); - - // Show success popup - showPopup(`"${name}" has been removed from your cart successfully.`); -} - -// Function to show a popup message -function showPopup(message) { - const popup = document.getElementById('popupCartItem'); - popup.textContent = message; - popup.classList.remove('hidden'); - popup.classList.add('visible'); - - // Hide the popup after 1 second - setTimeout(() => { - popup.classList.remove('visible'); - popup.classList.add('hidden'); - }, 3000); -} - -// Function to show or hide cart based on product list -function updateCartDisplay(filteredProducts) { - let cartInProduct = document.getElementById("cardInProduct"); - let cartisEmpty = document.getElementById("cardisEmpty"); - - if (filteredProducts.length === 0) { - cartInProduct.style.display = "none"; - cartisEmpty.style.display = "block"; - } else { - cartInProduct.style.display = "block"; - cartisEmpty.style.display = "none"; - } -} - -// 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; - 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)
-
₹${formatIndianRupee(totalMRP)}
-
-
-
Discount
-
₹${formatIndianRupee(totalDiscount)}
-
-
-
Delivery Charges
-
Free
-
-
-
Total Amount
-
₹${formatIndianRupee(totalPrice)}
-
-
` - - document.getElementById("priceDetail").innerHTML = priceDetail; -} - -// Fetch and display data -fetch("https://raw.githubusercontent.com/csathnere/APIs/main/json-ec/product.json") - .then(response => response.json()) - .then(data => { - const query = getQueryParameter("query"); - const filteredProducts = data.filter(product => product.name === query); - - // Save filtered products to local storage without overwriting existing data - saveToLocalStorage("filteredProducts", filteredProducts); - - // Retrieve updated filtered products from local storage - const savedFilteredProducts = getFromLocalStorage("filteredProducts"); - - // Display the filtered products - searchFetch(savedFilteredProducts); - }) - .catch(error => console.error("Error fetching data:", error)); \ No newline at end of file diff --git a/addtokart/index.html b/addtokart/index.html index 52c29e8e..db2b4bf0 100644 --- a/addtokart/index.html +++ b/addtokart/index.html @@ -5,7 +5,8 @@ - Flipkart | Online Shopping Site for Mobiles, Electronics, Furniture, Grocery, Lifestyle, Books & More. Best Offers! + Flipkart | Online Shopping Site for Mobiles, Electronics, Furniture, Grocery, Lifestyle, Books & More. + Best Offers! diff --git a/viewcart/viewcart.js b/viewcart/viewcart.js index 335782a6..2e7dad5f 100644 --- a/viewcart/viewcart.js +++ b/viewcart/viewcart.js @@ -1,5 +1,4 @@ -// Existing code... - +// Date and Time const today = new Date(); const nextThreeDays = new Date(today); nextThreeDays.setDate(today.getDate() + 3); @@ -12,67 +11,66 @@ const date = nextThreeDays.toLocaleDateString(); // Function to save data to local storage function saveToLocalStorage(key, newData) { - let existingData = getFromLocalStorage(key) || []; - - // Check for duplicates and add only unique products - newData.forEach(newProduct => { - const isDuplicate = existingData.some(existingProduct => existingProduct.name === newProduct.name); - if (!isDuplicate) { - existingData.push(newProduct); - } - }); + let existingData = getFromLocalStorage(key) || []; - localStorage.setItem(key, JSON.stringify(existingData)); + // Check for duplicates and add only unique products + newData.forEach(newProduct => { + const isDuplicate = existingData.some(existingProduct => existingProduct.name === newProduct.name); + if (!isDuplicate) { + existingData.push(newProduct); + } + }); + + localStorage.setItem(key, JSON.stringify(existingData)); } // Function to retrieve data from local storage function getFromLocalStorage(key) { - const data = localStorage.getItem(key); - return data ? JSON.parse(data) : []; + const data = localStorage.getItem(key); + return data ? JSON.parse(data) : []; } // Function to get query parameter function getQueryParameter(name) { - const urlParams = new URLSearchParams(window.location.search); - return urlParams.get(name); + const urlParams = new URLSearchParams(window.location.search); + return urlParams.get(name); } // Function to display search results function searchFetch(products) { - const searchList = document.getElementById("itemsInCart"); - searchList.innerHTML = products.map((product, index) => fetchCartData(product, index)).join(""); // Added index parameter to the map function - - // Add event listeners for remove buttons - document.querySelectorAll('.cartItmSfLRmBtn.remove').forEach(button => { - button.addEventListener('click', function() { - const productName = this.getAttribute('data-name'); - confirmRemoveItem(productName); - }); + const searchList = document.getElementById("itemsInCart"); + searchList.innerHTML = products.map(product => fetchCartData(product)).join(""); + + // Add event listeners for remove buttons + document.querySelectorAll('.cartItmSfLRmBtn.remove').forEach(button => { + button.addEventListener('click', function () { + const productName = this.getAttribute('data-name'); + confirmRemoveItem(productName); }); + }); - updateCartDisplay(products); - updatePriceDetail(products); + updateCartDisplay(products); + updatePriceDetail(products); } let totalPrice = 0; let totalItems = 0; // Function to generate HTML for a cart item -function fetchCartData(item, index) { // Added index parameter to the function - totalItems += 1; - totalPrice += item.price; - - const discount = (Math.floor(item.rating * (parseInt((item.price.toString()).slice(0, 2))) / 10)); - const afterDiscountPrice = Math.round((100 - discount) * 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 ` +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 `
@@ -84,7 +82,7 @@ function fetchCartData(item, index) { // Added index parameter to the function

Forest Green Strap, Regular

Seller: Ezig

-
₹${formatIndianRupee(afterDiscountPrice)} ₹${formatIndianRupee(item.price)} ${discount}% off +
₹${formatIndianRupee(afterDiscontPrice)} ₹${formatIndianRupee(item.price)} ${discont}% off 1 offer applied
@@ -96,9 +94,21 @@ function fetchCartData(item, index) { // Added index parameter to the function
-   -
  - +   +
  +
@@ -110,88 +120,69 @@ function fetchCartData(item, index) { // Added index parameter to the function
`; } - -// Function to increase the quantity of a specific item -function increaseQuantity(index) { // Added function to handle increasing quantity - const input = document.getElementById(`quantity-${index}`); // Use index to target specific input - input.value = Number(input.value) + 1; -} - -// Function to decrease the quantity of a specific item -function decreaseQuantity(index) { // Added function to handle decreasing quantity - const input = document.getElementById(`quantity-${index}`); // Use index to target specific input - const currentValue = Number(input.value); - if (currentValue > 1) { - input.value = currentValue - 1; - } else { - const productName = input.closest('.cartItmListInviewCart').querySelector('.remove').getAttribute('data-name'); - confirmRemoveItem(productName); - } -} - // Function to confirm and remove an item from the cart function confirmRemoveItem(name) { - const confirmRemove = confirm(`Are you sure you want to remove "${name}" from the cart?`); - if (confirmRemove) { - removeItem(name); - } + const confirmRemove = confirm(`Are you sure you want to remove "${name}" from the cart?`); + if (confirmRemove) { + removeItem(name); + } } // Function to remove an item from the cart function removeItem(name) { - let existingData = getFromLocalStorage("filteredProducts") || []; - const updatedData = existingData.filter(item => item.name !== name); - localStorage.setItem("filteredProducts", JSON.stringify(updatedData)); + let existingData = getFromLocalStorage("filteredProducts") || []; + const updatedData = existingData.filter(item => item.name !== name); + localStorage.setItem("filteredProducts", JSON.stringify(updatedData)); - // Update the displayed cart and price details - searchFetch(updatedData); + // Update the displayed cart and price details + searchFetch(updatedData); - // Show success popup - showPopup(`"${name}" has been removed from your cart successfully.`); + // Show success popup + showPopup(`"${name}" has been removed from your cart successfully.`); } // Function to show a popup message function showPopup(message) { - const popup = document.getElementById('popupCartItem'); - popup.textContent = message; - popup.classList.remove('hidden'); - popup.classList.add('visible'); - - // Hide the popup after 1 second - setTimeout(() => { - popup.classList.remove('visible'); - popup.classList.add('hidden'); - }, 3000); + const popup = document.getElementById('popupCartItem'); + popup.textContent = message; + popup.classList.remove('hidden'); + popup.classList.add('visible'); + + // Hide the popup after 1 second + setTimeout(() => { + popup.classList.remove('visible'); + popup.classList.add('hidden'); + }, 3000); } // Function to show or hide cart based on product list function updateCartDisplay(filteredProducts) { - let cartInProduct = document.getElementById("cardInProduct"); - let cartisEmpty = document.getElementById("cardisEmpty"); - - if (filteredProducts.length === 0) { - cartInProduct.style.display = "none"; - cartisEmpty.style.display = "block"; - } else { - cartInProduct.style.display = "block"; - cartisEmpty.style.display = "none"; - } + let cartInProduct = document.getElementById("cardInProduct"); + let cartisEmpty = document.getElementById("cardisEmpty"); + + if (filteredProducts.length === 0) { + cartInProduct.style.display = "none"; + cartisEmpty.style.display = "block"; + } else { + cartInProduct.style.display = "block"; + cartisEmpty.style.display = "none"; + } } // 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; - 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 = ` + 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; + 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)
@@ -206,28 +197,32 @@ function updatePriceDetail(products) {
Free
-
Total Amount
-
₹${formatIndianRupee(totalPrice)}
+
Total Amount
+
₹${formatIndianRupee(totalPrice)}
-
` +
You will save ₹${formatIndianRupee(totalDiscount)} on this order
+
+ `; - document.getElementById("priceDetail").innerHTML = priceDetail; + document.getElementById("priceDetail").innerHTML = priceDetail; } -// Fetch and display data +// Fetch data from the JSON file and filter products based on the query fetch("https://raw.githubusercontent.com/csathnere/APIs/main/json-ec/product.json") - .then(response => response.json()) - .then(data => { - const query = getQueryParameter("query"); - const filteredProducts = data.filter(product => product.name === query); + .then(response => response.json()) + .then(data => { + const query = getQueryParameter("query"); + const filteredProducts = data.filter(product => product.name === query); + + // Save filtered products to local storage without overwriting existing data + saveToLocalStorage("filteredProducts", filteredProducts); - // Save filtered products to local storage without overwriting existing data - saveToLocalStorage("filteredProducts", filteredProducts); + // Retrieve updated filtered products from local storage + const savedFilteredProducts = getFromLocalStorage("filteredProducts"); - // Retrieve updated filtered products from local storage - const savedFilteredProducts = getFromLocalStorage("filteredProducts"); + // Display the filtered products + searchFetch(savedFilteredProducts); + }) + .catch(error => console.error("Error fetching data:", error)); - // Display the filtered products - searchFetch(savedFilteredProducts); - }) - .catch(error => console.error("Error fetching data:", error)); \ No newline at end of file +// end