// Обработчик для кнопки добавления в корзину function addToCart(productId) { fetch(`/api/cart/add`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ productId }), }) .then(response => response.json()) .then(data => { alert('Товар добавлен в корзину'); }) .catch(error => { console.error('Ошибка:', error); }); }