Aleksmorshen commited on
Commit
386e465
·
verified ·
1 Parent(s): b9f8f06

Update script.js

Browse files
Files changed (1) hide show
  1. script.js +44 -39
script.js CHANGED
@@ -111,51 +111,56 @@ function updateCart() {
111
  }
112
  }
113
 
114
- document.querySelectorAll('.add-to-cart-btn').forEach(button => {
115
- button.addEventListener('click', () => {
116
- const serviceCard = button.closest('.service-card');
117
- const serviceName = serviceCard.getAttribute('data-service');
118
- if (!cart.includes(serviceName)) {
119
- cart.push(serviceName);
120
- updateCart();
121
- alert(`${serviceName} добавлено в корзину!`);
122
- } else {
123
- alert(`${serviceName} уже в корзине!`);
124
- }
 
 
 
125
  });
126
- });
127
 
128
- // Открытие/закрытие модального окна корзины
129
- const cartIcon = document.getElementById('cartIcon');
130
- const cartModal = document.getElementById('cartModal');
131
- const closeModal = document.getElementById('closeModal');
132
 
133
- cartIcon.addEventListener('click', () => {
134
- cartModal.style.display = 'flex';
135
- updateCart();
136
- });
137
 
138
- closeModal.addEventListener('click', () => {
139
- cartModal.style.display = 'none';
140
- });
141
 
142
- // Очистка корзины
143
- document.getElementById('clearCartBtn').addEventListener('click', () => {
144
- cart = [];
145
- updateCart();
146
- alert('Корзина очищена!');
147
- });
148
 
149
- // Рассчитать стоимость
150
- document.getElementById('calculateBtn').addEventListener('click', () => {
151
- if (cart.length > 0) {
152
- const message = `Здравствуйте! Интересуют следующие услуги: ${cart.join(', ')}. Прошу рассчитать стоимость.`;
153
- const whatsappUrl = `https://wa.me/996500398754?text=${encodeURIComponent(message)}`;
154
- window.open(whatsappUrl, '_blank');
155
- cartModal.style.display = 'none';
156
- } else {
157
- alert('Пожалуйста, выберите хотя бы одну услугу!');
158
- }
 
 
 
159
  });
160
 
161
  // Инициализация корзины при загрузке страницы
 
111
  }
112
  }
113
 
114
+ // Убедимся, что кнопки добавления в корзину работают
115
+ document.addEventListener('DOMContentLoaded', () => {
116
+ document.querySelectorAll('.add-to-cart-btn').forEach(button => {
117
+ button.addEventListener('click', () => {
118
+ const serviceCard = button.closest('.service-card');
119
+ const serviceName = serviceCard.getAttribute('data-service');
120
+ if (!cart.includes(serviceName)) {
121
+ cart.push(serviceName);
122
+ updateCart();
123
+ alert(`${serviceName} добавлено в корзину!`);
124
+ } else {
125
+ alert(`${serviceName} уже в корзине!`);
126
+ }
127
+ });
128
  });
 
129
 
130
+ // Открытие/закрытие модального окна корзины
131
+ const cartIcon = document.getElementById('cartIcon');
132
+ const cartModal = document.getElementById('cartModal');
133
+ const closeModal = document.getElementById('closeModal');
134
 
135
+ cartIcon.addEventListener('click', () => {
136
+ cartModal.style.display = 'flex';
137
+ updateCart();
138
+ });
139
 
140
+ closeModal.addEventListener('click', () => {
141
+ cartModal.style.display = 'none';
142
+ });
143
 
144
+ // Очистка корзины
145
+ document.getElementById('clearCartBtn').addEventListener('click', () => {
146
+ cart = [];
147
+ updateCart();
148
+ alert('Корзина очищена!');
149
+ });
150
 
151
+ // Рассчитать стоимость
152
+ document.getElementById('calculateBtn').addEventListener('click', () => {
153
+ if (cart.length > 0) {
154
+ const message = `Здравствуйте! Интересуют следующие услуги: ${cart.join(', ')}. Прошу рассчитать стоимость.`;
155
+ const whatsappUrl = `https://wa.me/996500398754?text=${encodeURIComponent(message)}`;
156
+ window.open(whatsappUrl, '_blank');
157
+ cartModal.style.display = 'none';
158
+ cart = []; // Очищаем корзину после отправки
159
+ updateCart();
160
+ } else {
161
+ alert('Пожалуйста, выберите хотя бы одну услугу!');
162
+ }
163
+ });
164
  });
165
 
166
  // Инициализация корзины при загрузке страницы