var date = new Date(); let day = date.getDate(); let month = date.getMonth() + 1; let year = date.getFullYear(); let date1 = `${month}/${day}/${year}`; var date2 = '04/01/2026'; var date3 = new Date(date1); var date4 = new Date(date2); if ( date3 > date4 ){ document.getElementById("tarihgec").innerHTML = "Fiyatlar Güncel Değil"; } else { document.getElementById("tarihgec").innerHTML = "Fiyatlar Güncel"; } // localStorage.clear(); // tek sayfa kullanılıyorsa temizler //! variables const cartBtn = document.querySelector(".cart-btn"); const clearCartBtn = document.querySelector(".btn-clear"); const checkoutCartBtn = document.querySelector(".btn-checkout"); const cartItems = document.querySelector(".cart-items"); const cartTotal = document.querySelector(".total-value"); const cartContent = document.querySelector(".cart-list"); const productsDOM = document.querySelector("#products-dom"); var kurlar = "TL"; //databaseden let cart = []; let buttonsDOM = []; class Products { async getProducts() { try { // let result = await fetch("https://67a784d6203008941f67d30d.mockapi.io/products"); // let data = await result.json(); let data = [{"id":"1","title":"title","image":"https://brosur.tr/resim","image2":"https://brosur.tr/resim2","price":100}]; //databaseden let products = data; return products; } catch (error) { console.log(error); } } } class UI { displayProducts(products) { let result = ""; products.forEach(item => { // item.price = parseFloat(item.price.toFixed(2)); item.price = item.price.toFixed(2); result += ` `}); productsDOM.innerHTML = result; } getBagButtons() { const buttons = [...document.querySelectorAll(".btn-add-to-cart")]; buttonsDOM = buttons; buttons.forEach(button => { let id = button.dataset.id; let inCart = cart.find(item => item.id === id); if (inCart) { button.setAttribute("disabled", "disabled"); button.style.opacity = ".3"; } else { button.addEventListener("click", event => { event.target.disabled = true; event.target.style.opacity = ".3"; //* get product from products let cartItem = { ...Storage.getProduct(id), amount: 1 }; //* add procuct to the cart cart = [...cart, cartItem]; //* save cart in local storage Storage.saveCart(cart); //* save cart values this.saveCartValues(cart); //* display cart item this.addCartItem(cartItem) //* show the cart this.showCart(); }) } }) } saveCartValues(cart) { let tempTotal = 0; let itemsTotal = 0; cart.map(item => { tempTotal += item.price * item.amount; itemsTotal += item.amount; }); cartTotal.innerText = tempTotal.toFixed(2) + " " + kurlar; cartItems.innerText = itemsTotal; } addCartItem(item) { const li = document.createElement("li"); li.classList.add("cart-list-item"); li.innerHTML = `
${item.title} ${item.price} ${kurlar}
  ${item.amount}  
  
`; cartContent.appendChild(li); } showCart() { cartBtn.click(); } setupAPP() { cart = Storage.getCart(); this.saveCartValues(cart); this.populateCart(cart); } populateCart(cart) { cart.forEach(item => this.addCartItem(item)); } cartLogic() { clearCartBtn.addEventListener("click", () => { this.clearCart(); }) checkoutCartBtn.addEventListener("click", () => { this.checkoutCart(); }) cartContent.addEventListener("click", event => { if (event.target.classList.contains("cart-remove-btn")) { let removeItem = event.target; let id = removeItem.dataset.id; removeItem.parentElement.parentElement.parentElement.remove(); this.removeItem(id); } else if (event.target.classList.contains("quantity-minus")) { let lowerAmount = event.target; let id = lowerAmount.dataset.id; let tempItem = cart.find(item => item.id === id); tempItem.amount = tempItem.amount - 1; if (tempItem.amount > 0) { Storage.saveCart(cart); this.saveCartValues(cart); lowerAmount.nextElementSibling.innerText = tempItem.amount; } else { lowerAmount.parentElement.parentElement.parentElement.remove(); this.removeItem(id); } } else if (event.target.classList.contains("quantity-plus")) { let addAmount = event.target; let id = addAmount.dataset.id; let tempItem = cart.find(item => item.id === id); tempItem.amount = tempItem.amount + 1; Storage.saveCart(cart); this.saveCartValues(cart); addAmount.previousElementSibling.innerText = tempItem.amount; } }) } clearCart() { let cartItems = cart.map(item => item.id); cartItems.forEach(id => this.removeItem(id)); while (cartContent.children.length > 0) { cartContent.removeChild(cartContent.children[0]) } } checkoutCart() { var yazilacak = "" ; var ttprice = 0 ; var tprice = 0 ; var ttprice6 = 0 ; var yazilacak6 = "" ; var ttprice9 = 0 ; var ttprice9k = 0 ; var yazilacak9 = "" ; var yazilacak0 = "" ; var tpricey = 0 ; var ttpricey = 0 ; var ttprice6y = 0 ; var ttprice9y = 0 ; var ttprice9ky = 0 ; const myJSON = JSON.parse(localStorage.getItem("cart")); var myObj = myJSON; for ( var baslangic = 0 ; baslangic < myObj.length ; baslangic ++ ) { tprice = myObj[baslangic].amount * myObj[baslangic].price ; tprice = parseFloat(tprice.toFixed(2)); ttprice = ttprice + tprice ; ttprice = parseFloat(ttprice.toFixed(2)); ttpricey = ttprice.toFixed(2); yazilacak0 = "
ARA TOPLAM : " + ttpricey +" "+ kurlar; if ( ttprice < 3000.00 || 3000.00 == 0 ) { ttprice6 = ttprice+200.00; ttprice6 = parseFloat(ttprice6.toFixed(2)); ttprice6y = ttprice6.toFixed(2); if ( 3000.00 > 0 ) { yazilacak6 = "
KARGO : " + "200.00" + " " + kurlar + "
( KARGO ÜCRETSİZ LİMİT 3000.00 " + kurlar + " )"; } else { yazilacak6 = "
KARGO : " + "200.00" + " " + kurlar ; } } else { ttprice6 = ttprice; ttprice6 = parseFloat(ttprice6.toFixed(2)); ttprice6y = ttprice6.toFixed(2); yazilacak6 = "
KARGO ÜCRETSİZ ( LİMİT 3000.00 " + kurlar + " )"; } ttprice9k = ((ttprice6/100)*20.00); ttprice9k = parseFloat(ttprice9k.toFixed(2)); ttprice9ky = ttprice9k.toFixed(2); ttprice9 = ttprice6 + ttprice9k; ttprice9 = parseFloat(ttprice9.toFixed(2)); ttprice9y = ttprice9.toFixed(2); yazilacak9 = "
KDV ( % 20.00 ) : " + ttprice9ky + " " + kurlar; tpricey = tprice.toFixed(2); yazilacak += "
[ " + myObj[baslangic].id + " ] " + myObj[baslangic].title + "
" + myObj[baslangic].amount + " adet x " + " ( " + myObj[baslangic].price + " " + kurlar + " ) = " + tpricey +" "+ kurlar +"
"; } yazilacak += yazilacak0; yazilacak += yazilacak6; yazilacak += yazilacak9; yazilacak += "

TOPLAM TUTAR : " + ttprice9y +" "+ kurlar + "
( Bilgi Amaçlıdır! )"; yazilacak += "

Fiyat Geçerlilik Tarihi : 01/07/2025 - 01/04/2026
"; if ( date3 > date4 ){ yazilacak += "Fiyatlar Güncel Değil

Güncel Fiyatlarla Birlikte"; } yazilacak += "
Bu sipariş için onay alabilir miyim ? "; yazilacak += "

Adı Soyadı : " + document.getElementById("basket-name").value; yazilacak += "
Telefon Numarası : " + document.getElementById("basket-phone").value; if ( baslangic > 0 ){ let wsparis = yazilacak.replace(/
/gi, "%0a"); var url = "https://wa.me/+902124268249?text=" +"brosur.tr ALIŞVERİŞ SEPETİ"+"%0a" +"------------------------------"+"%0a" +wsparis+"%0a"+"%0a" +"------------------------------"+"%0a"; let text = document.getElementById("demo").innerHTML = yazilacak + ` `; } else { let text = document.getElementById("demo").innerHTML = ""; } } removeItem(id) { cart = cart.filter(item => item.id !== id); this.saveCartValues(cart); Storage.saveCart(cart); let button = this.getSinleButton(id); button.disabled = false; button.style.opacity = "1"; } getSinleButton(id) { return buttonsDOM.find(button => button.dataset.id === id); } } class Storage { static saveProducts(products) { localStorage.setItem("products", JSON.stringify(products)); } static getProduct(id) { let products = JSON.parse(localStorage.getItem("products")); return products.find(product => product.id === id); } static saveCart(cart) { localStorage.setItem("cart", JSON.stringify(cart)); } static getCart() { return localStorage.getItem("cart") ? JSON.parse(localStorage.getItem("cart")) : []; } } document.addEventListener("DOMContentLoaded", () => { const ui = new UI(); const products = new Products(); ui.setupAPP(); products.getProducts().then(products => { ui.displayProducts(products); Storage.saveProducts(products); }).then(() => { ui.getBagButtons(); ui.cartLogic(); }) }); function removeElement() { document.getElementById("demo").style.display = "none"; } function changeVisibility() { document.getElementById("demo").style.display = "block"; document.getElementById("demo").style.visibility = "visible"; }