Update app.py
Browse files
app.py
CHANGED
|
@@ -394,30 +394,38 @@ def catalog():
|
|
| 394 |
function openQuantityModal(index) {
|
| 395 |
selectedProductIndex = index;
|
| 396 |
document.getElementById('quantityModal').style.display = 'block';
|
| 397 |
-
document.getElementById('quantityInput').value = 1;
|
| 398 |
}
|
| 399 |
|
| 400 |
function confirmAddToCart() {
|
| 401 |
-
if (selectedProductIndex === null)
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
|
|
|
|
|
|
|
|
|
| 405 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 406 |
let cart = JSON.parse(localStorage.getItem('cart') || '[]');
|
| 407 |
const product = products[selectedProductIndex];
|
| 408 |
const existingItem = cart.find(item => item.name === product.name);
|
| 409 |
-
|
| 410 |
if (existingItem) {
|
| 411 |
existingItem.quantity += quantity;
|
| 412 |
} else {
|
| 413 |
cart.push({
|
| 414 |
name: product.name,
|
| 415 |
price: product.price,
|
| 416 |
-
photo: product.photos
|
| 417 |
quantity: quantity
|
| 418 |
});
|
| 419 |
}
|
| 420 |
-
|
| 421 |
localStorage.setItem('cart', JSON.stringify(cart));
|
| 422 |
closeModal('quantityModal');
|
| 423 |
updateCartButton();
|
|
@@ -433,7 +441,7 @@ def catalog():
|
|
| 433 |
const cart = JSON.parse(localStorage.getItem('cart') || '[]');
|
| 434 |
const cartContent = document.getElementById('cartContent');
|
| 435 |
let total = 0;
|
| 436 |
-
|
| 437 |
if (cart.length === 0) {
|
| 438 |
cartContent.innerHTML = '<p>Корзина пуста</p>';
|
| 439 |
} else {
|
|
@@ -457,7 +465,7 @@ def catalog():
|
|
| 457 |
`;
|
| 458 |
}).join('');
|
| 459 |
}
|
| 460 |
-
|
| 461 |
document.getElementById('cartTotal').textContent = total;
|
| 462 |
document.getElementById('cartModal').style.display = 'block';
|
| 463 |
}
|
|
|
|
| 394 |
function openQuantityModal(index) {
|
| 395 |
selectedProductIndex = index;
|
| 396 |
document.getElementById('quantityModal').style.display = 'block';
|
| 397 |
+
document.getElementById('quantityInput').value = 1; // Сбрасываем значение на 1
|
| 398 |
}
|
| 399 |
|
| 400 |
function confirmAddToCart() {
|
| 401 |
+
if (selectedProductIndex === null) {
|
| 402 |
+
console.error("Товар не выбран!");
|
| 403 |
+
return;
|
| 404 |
+
}
|
| 405 |
+
|
| 406 |
+
const quantityInput = document.getElementById('quantityInput').value;
|
| 407 |
+
const quantity = parseInt(quantityInput) || 0; // Если не число, то 0
|
| 408 |
|
| 409 |
+
if (quantity <= 0) {
|
| 410 |
+
alert("Пожалуйста, укажите количество больше 0");
|
| 411 |
+
return;
|
| 412 |
+
}
|
| 413 |
+
|
| 414 |
let cart = JSON.parse(localStorage.getItem('cart') || '[]');
|
| 415 |
const product = products[selectedProductIndex];
|
| 416 |
const existingItem = cart.find(item => item.name === product.name);
|
| 417 |
+
|
| 418 |
if (existingItem) {
|
| 419 |
existingItem.quantity += quantity;
|
| 420 |
} else {
|
| 421 |
cart.push({
|
| 422 |
name: product.name,
|
| 423 |
price: product.price,
|
| 424 |
+
photo: product.photos && product.photos.length > 0 ? product.photos[0] : '',
|
| 425 |
quantity: quantity
|
| 426 |
});
|
| 427 |
}
|
| 428 |
+
|
| 429 |
localStorage.setItem('cart', JSON.stringify(cart));
|
| 430 |
closeModal('quantityModal');
|
| 431 |
updateCartButton();
|
|
|
|
| 441 |
const cart = JSON.parse(localStorage.getItem('cart') || '[]');
|
| 442 |
const cartContent = document.getElementById('cartContent');
|
| 443 |
let total = 0;
|
| 444 |
+
|
| 445 |
if (cart.length === 0) {
|
| 446 |
cartContent.innerHTML = '<p>Корзина пуста</p>';
|
| 447 |
} else {
|
|
|
|
| 465 |
`;
|
| 466 |
}).join('');
|
| 467 |
}
|
| 468 |
+
|
| 469 |
document.getElementById('cartTotal').textContent = total;
|
| 470 |
document.getElementById('cartModal').style.display = 'block';
|
| 471 |
}
|