B
BlackSHOP
тел.
+375 29 340-71-87
blackshopy@gmail.com
ООО «Лучший принтер»
Сортировка: По умолчанию
Цена: по возрастанию
Цена: по убыванию
Название: А-Я
В наличии
♡ Избранное
0
КОРЗИНА
0
✕
Оформление заказа
Отправить заказ
✕
♡
В корзину
productsData = window.productsData || []; } initApp(); } // ================= ЛОГИКА КАТАЛОГА ================= function initApp() { const catalog = document.getElementById("catalog"); const menuList = document.getElementById("menuList"); const paginationBox = document.getElementById("pagination"); const searchInput = document.getElementById("searchInput"); const inStockFilter = document.getElementById("inStockFilter"); const sortSelect = document.getElementById("sortSelect"); let currentCategory = null; let searchQuery = ""; let currentPage = 1; const itemsPerPage = 50; let currentSort = "default"; const uniqueCats = new Set(); productsData.forEach(p => { const cat = p.category || p.cat0; if (cat) uniqueCats.add(cat); }); const categories = ["Все товары", ...Array.from(uniqueCats).sort()]; function renderMenu() { menuList.innerHTML = categories.map(cat => `
${cat === "Все товары" ? `Все товары (${productsData.length})` : cat}
`).join(""); } window.setCategory = function(cat) { currentCategory = (cat === "Все товары") ? null : cat; currentPage = 1; renderMenu(); renderCatalog(); }; window.resetFilter = function() { currentCategory = null; searchQuery = ""; searchInput.value = ""; inStockFilter.checked = true; currentPage = 1; sortSelect.value = "default"; currentSort = "default"; renderMenu(); renderCatalog(); }; window.changePage = function(page) { currentPage = page; renderCatalog(); document.getElementById("productsWrapper").scrollTop = 0; } function renderCatalog() { let filtered = productsData; if (currentCategory) filtered = filtered.filter(p => (p.category === currentCategory) || (p.cat0 === currentCategory)); if (inStockFilter.checked) filtered = filtered.filter(p => p.stock > 0); if (searchQuery) { const q = searchQuery.toLowerCase(); filtered = filtered.filter(p => p.name.toLowerCase().includes(q) || (p.code && p.code.toLowerCase().includes(q))); } if (currentSort === "price-asc") filtered.sort((a, b) => a.price - b.price); else if (currentSort === "price-desc") filtered.sort((a, b) => b.price - a.price); else if (currentSort === "name-asc") filtered.sort((a, b) => a.name.localeCompare(b.name)); const totalPages = Math.ceil(filtered.length / itemsPerPage); if (currentPage > totalPages && totalPages > 0) currentPage = totalPages; const startIdx = (currentPage - 1) * itemsPerPage; const paginatedItems = filtered.slice(startIdx, startIdx + itemsPerPage); if (paginatedItems.length === 0) { catalog.innerHTML = '
Ничего не найдено
'; paginationBox.innerHTML = ""; } else { catalog.innerHTML = paginatedItems.map(p => { const isFav = favorites.includes(p.id); return `
${isFav ? '♥' : '♡'}
${p.name}
${p.price.toLocaleString("ru-RU", {minimumFractionDigits: 2})} BYN
В корзину
`}).join(""); if (totalPages > 1) { let pagHtml = `
Назад
`; for (let i = 1; i <= totalPages; i++) { if (i === 1 || i === totalPages || (i >= currentPage - 2 && i <= currentPage + 2)) { pagHtml += `
${i}
`; } else if (i === currentPage - 3 || i === currentPage + 3) { pagHtml += `
...
`; } } pagHtml += `
Вперед
`; paginationBox.innerHTML = pagHtml; } else { paginationBox.innerHTML = ""; } } } searchInput.addEventListener("input", (e) => { searchQuery = e.target.value; currentPage = 1; renderCatalog(); }); inStockFilter.addEventListener("change", () => { currentPage = 1; renderCatalog(); }); sortSelect.addEventListener("change", (e) => { currentSort = e.target.value; currentPage = 1; renderCatalog(); }); renderMenu(); renderCatalog(); renderCart(); renderFavorites(); } // ================= КОРЗИНА И ИЗБРАННОЕ ================= function addToCart(p) { const found = cart.find(x => x.id === p.id); if (found) found.qty++; else cart.push({ id: p.id, code: p.code, name: p.name, price: p.price, image: p.image, qty: 1 }); saveCart(); renderCart(); openCart(); closeProductModal(); } function changeQty(id, delta) { const item = cart.find(x => x.id === id); if (!item) return; item.qty += delta; if (item.qty <= 0) cart = cart.filter(x => x.id !== id); saveCart(); renderCart(); } function removeItem(id) { cart = cart.filter(x => x.id !== id); saveCart(); renderCart(); } function renderCart() { const count = cart.reduce((s, i) => s + i.qty, 0); const total = cart.reduce((s, i) => s + i.qty * i.price, 0); document.getElementById("cartCount").textContent = count; document.getElementById("cartTotal").textContent = total.toLocaleString("ru-RU", {minimumFractionDigits: 2}) + " BYN"; const box = document.getElementById("cartItems"); if (cart.length === 0) { box.innerHTML = '
Корзина пуста
'; return; } box.innerHTML = cart.map(i => `
${i.name}
${i.price.toLocaleString("ru-RU", {minimumFractionDigits: 2})} BYN
−
${i.qty}
+
Удалить
`).join(""); } function openCart() { closeAllPanels(); document.getElementById("cartPanel").classList.add("open"); document.getElementById("overlay").classList.add("open"); } function closeCart() { document.getElementById("cartPanel").classList.remove("open"); document.getElementById("overlay").classList.remove("open"); } function toggleFavorite(id) { const numId = Number(id); if (favorites.includes(numId)) favorites = favorites.filter(x => x !== numId); else favorites.push(numId); saveFav(); renderFavorites(); if(typeof initApp !== 'undefined') initApp(); // Перерисовка каталога if (document.getElementById("productModal").classList.contains("open")) updateProductModalFavBtn(numId); } function renderFavorites() { document.getElementById("favCount").textContent = favorites.length; const box = document.getElementById("favItems"); if (favorites.length === 0) { box.innerHTML = '
В избранном пусто
'; return; } const favProducts = productsData.filter(p => favorites.includes(p.id)); box.innerHTML = favProducts.map(p => `
${p.name}
${p.price.toLocaleString("ru-RU", {minimumFractionDigits: 2})} BYN
В корзину
Удалить
`).join(""); } function openFav() { closeAllPanels(); document.getElementById("favPanel").classList.add("open"); document.getElementById("overlay").classList.add("open"); } function closeFav() { document.getElementById("favPanel").classList.remove("open"); document.getElementById("overlay").classList.remove("open"); } function closeAllPanels() { closeCart(); closeFav(); } function openCheckout() { if (cart.length === 0) return alert("Корзина пуста!"); closeCart(); document.getElementById("checkoutModal").classList.add("open"); document.getElementById("checkoutOverlay").classList.add("open"); } function closeCheckout() { document.getElementById("checkoutModal").classList.remove("open"); document.getElementById("checkoutOverlay").classList.remove("open"); } async function submitOrder() { const name = document.getElementById("orderName").value.trim(); const phone = document.getElementById("orderPhone").value.trim(); const address = document.getElementById("orderAddress").value.trim(); const comment = document.getElementById("orderComment").value.trim(); if (!name || !phone || !address) return alert("Заполните имя, телефон и адрес!"); let message = `🔥 НОВЫЙ ЗАКАЗ\n\n👤 Имя: ${name}\n📞 Телефон: ${phone}\n📍 Адрес: ${address}\n`; if (comment) message += `💬 Комментарий: ${comment}\n`; message += `\n📦 Товары:\n`; cart.forEach(item => { message += `• [${item.code || 'Без арт.'}] ${item.name}\n ${item.qty} шт. × ${item.price.toFixed(2)} BYN = ${(item.qty * item.price).toFixed(2)} BYN\n`; }); const total = cart.reduce((s, i) => s + i.qty * i.price, 0); message += `\n💰 Итого: ${total.toFixed(2)} BYN`; try { const url = `https://api.telegram.org/bot${TG_BOT_TOKEN}/sendMessage`; const response = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ chat_id: TG_CHAT_ID, text: message }) }); if (response.ok) { alert("Заказ успешно отправлен! Мы свяжемся с вами."); cart = []; saveCart(); renderCart(); closeCheckout(); } else alert("Ошибка при отправке."); } catch (error) { alert("Ошибка сети."); } } function updateProductModalFavBtn(id) { const btn = document.getElementById("pmBtnFav"); if (favorites.includes(id)) { btn.textContent = "♥"; btn.style.color = "#e63946"; btn.style.borderColor = "#e63946"; } else { btn.textContent = "♡"; btn.style.color = "#fff"; btn.style.borderColor = "var(--border)"; } } window.openProductModal = function(id) { const p = productsData.find(x => x.id === Number(id)); if (!p) return; document.getElementById("pmImage").src = p.image || 'https://via.placeholder.com/300x300/fff/000?text=No+Image'; document.getElementById("pmName").textContent = p.name; document.getElementById("pmArticle").innerHTML = `Артикул:
${p.code || 'Нет'}
`; document.getElementById("pmDesc").innerHTML = p.description ? p.description : '
Описание отсутствует.
'; document.getElementById("pmPrice").textContent = p.price.toLocaleString("ru-RU", {minimumFractionDigits: 2}) + " BYN"; document.getElementById("pmBtnAdd").onclick = () => addToCart(p); document.getElementById("pmBtnFav").onclick = () => { toggleFavorite(p.id); updateProductModalFavBtn(p.id); }; updateProductModalFavBtn(p.id); document.getElementById("productModal").classList.add("open"); document.getElementById("productOverlay").classList.add("open"); } window.closeProductModal = function() { document.getElementById("productModal").classList.remove("open"); document.getElementById("productOverlay").classList.remove("open"); } // Инициализация при загрузке страницы window.addEventListener('load', loadProducts);