flpolprojects commited on
Commit
a4eb49c
·
verified ·
1 Parent(s): 0318b2a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -13
app.py CHANGED
@@ -139,15 +139,15 @@ def catalog():
139
  box-shadow: 0 5px 25px rgba(0, 0, 0, 0.15);
140
  }
141
  .product-image {
142
- width: 100%;
143
  height: 200px;
144
  overflow: hidden;
145
  border-radius: 8px;
146
- margin-bottom: 15px;
147
  }
148
  .product-image img {
149
- width: 100%;
150
- height: 100%;
151
  object-fit: cover;
152
  transition: transform 0.3s ease;
153
  }
@@ -263,13 +263,31 @@ def catalog():
263
  object-fit: cover;
264
  margin-right: 10px;
265
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
266
  @media (max-width: 768px) {
267
  .products-grid {
268
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
269
  gap: 10px;
270
  }
271
  .product-image {
272
- height: 120px;
 
 
 
 
 
273
  }
274
  }
275
  </style>
@@ -291,7 +309,7 @@ def catalog():
291
  <div class="product-price">{{ product['price'] }} ₽</div>
292
  <p class="product-description">{{ product['description'][:100] }}{% if product['description']|length > 100 %}...{% endif %}</p>
293
  <button class="product-button" onclick="openModal({{ loop.index0 }})">Подробнее</button>
294
- <button class="product-button add-to-cart" onclick="addToCart({{ loop.index0 }})">В корзину</button>
295
  </div>
296
  {% endfor %}
297
  </div>
@@ -305,6 +323,16 @@ def catalog():
305
  </div>
306
  </div>
307
 
 
 
 
 
 
 
 
 
 
 
308
  <!-- Cart Modal -->
309
  <div id="cartModal" class="modal">
310
  <div class="modal-content">
@@ -313,6 +341,7 @@ def catalog():
313
  <div id="cartContent"></div>
314
  <div style="margin-top: 20px; text-align: right;">
315
  <strong>Итого: <span id="cartTotal">0</span> ₽</strong>
 
316
  </div>
317
  </div>
318
  </div>
@@ -325,6 +354,7 @@ def catalog():
325
  <script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/10.2.0/swiper-bundle.min.js"></script>
326
  <script>
327
  const products = {{ products|tojson }};
 
328
 
329
  function openModal(index) {
330
  loadProductDetails(index);
@@ -361,23 +391,35 @@ def catalog():
361
  });
362
  }
363
 
364
- function addToCart(index) {
 
 
 
 
 
 
 
 
 
 
 
365
  let cart = JSON.parse(localStorage.getItem('cart') || '[]');
366
- const product = products[index];
367
  const existingItem = cart.find(item => item.name === product.name);
368
 
369
  if (existingItem) {
370
- existingItem.quantity += 1;
371
  } else {
372
  cart.push({
373
  name: product.name,
374
  price: product.price,
375
  photo: product.photos?.[0] || '',
376
- quantity: 1
377
  });
378
  }
379
 
380
  localStorage.setItem('cart', JSON.stringify(cart));
 
381
  updateCartButton();
382
  }
383
 
@@ -420,6 +462,12 @@ def catalog():
420
  document.getElementById('cartModal').style.display = 'block';
421
  }
422
 
 
 
 
 
 
 
423
  window.onclick = function(event) {
424
  if (event.target.className === 'modal') {
425
  event.target.style.display = "none";
@@ -449,12 +497,14 @@ def product_detail(index):
449
  {% if product.get('photos') %}
450
  {% for photo in product['photos'] %}
451
  <div class="swiper-slide">
452
- <img src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/photos/{{ photo }}" alt="{{ product['name'] }}">
 
 
453
  </div>
454
  {% endfor %}
455
  {% else %}
456
  <div class="swiper-slide">
457
- <img src="https://via.placeholder.com/300" alt="No Image">
458
  </div>
459
  {% endif %}
460
  </div>
@@ -664,7 +714,7 @@ def admin():
664
  {% if product.get('photos') and product['photos']|length > 0 %}
665
  <img src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/photos/{{ product['photos'][0] }}"
666
  alt="{{ product['name'] }}"
667
- style="max-width: 100px;">
668
  {% endif %}
669
  <details>
670
  <summary>Редактировать</summary>
 
139
  box-shadow: 0 5px 25px rgba(0, 0, 0, 0.15);
140
  }
141
  .product-image {
142
+ width: 200px;
143
  height: 200px;
144
  overflow: hidden;
145
  border-radius: 8px;
146
+ margin: 0 auto 15px;
147
  }
148
  .product-image img {
149
+ width: 200px;
150
+ height: 200px;
151
  object-fit: cover;
152
  transition: transform 0.3s ease;
153
  }
 
263
  object-fit: cover;
264
  margin-right: 10px;
265
  }
266
+ .quantity-input {
267
+ width: 60px;
268
+ padding: 5px;
269
+ margin: 10px 0;
270
+ }
271
+ .clear-cart {
272
+ background-color: #e74c3c;
273
+ margin-top: 10px;
274
+ float: right;
275
+ }
276
+ .clear-cart:hover {
277
+ background-color: #c0392b;
278
+ }
279
  @media (max-width: 768px) {
280
  .products-grid {
281
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
282
  gap: 10px;
283
  }
284
  .product-image {
285
+ width: 150px;
286
+ height: 150px;
287
+ }
288
+ .product-image img {
289
+ width: 150px;
290
+ height: 150px;
291
  }
292
  }
293
  </style>
 
309
  <div class="product-price">{{ product['price'] }} ₽</div>
310
  <p class="product-description">{{ product['description'][:100] }}{% if product['description']|length > 100 %}...{% endif %}</p>
311
  <button class="product-button" onclick="openModal({{ loop.index0 }})">Подробнее</button>
312
+ <button class="product-button add-to-cart" onclick="openQuantityModal({{ loop.index0 }})">В корзину</button>
313
  </div>
314
  {% endfor %}
315
  </div>
 
323
  </div>
324
  </div>
325
 
326
+ <!-- Quantity Modal -->
327
+ <div id="quantityModal" class="modal">
328
+ <div class="modal-content">
329
+ <span class="close" onclick="closeModal('quantityModal')">×</span>
330
+ <h2>Укажите количество</h2>
331
+ <input type="number" id="quantityInput" class="quantity-input" min="1" value="1">
332
+ <button class="product-button" onclick="confirmAddToCart()">Добавить</button>
333
+ </div>
334
+ </div>
335
+
336
  <!-- Cart Modal -->
337
  <div id="cartModal" class="modal">
338
  <div class="modal-content">
 
341
  <div id="cartContent"></div>
342
  <div style="margin-top: 20px; text-align: right;">
343
  <strong>Итого: <span id="cartTotal">0</span> ₽</strong>
344
+ <button class="product-button clear-cart" onclick="clearCart()">Очистить корзину</button>
345
  </div>
346
  </div>
347
  </div>
 
354
  <script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/10.2.0/swiper-bundle.min.js"></script>
355
  <script>
356
  const products = {{ products|tojson }};
357
+ let selectedProductIndex = null;
358
 
359
  function openModal(index) {
360
  loadProductDetails(index);
 
391
  });
392
  }
393
 
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) return;
402
+
403
+ const quantity = parseInt(document.getElementById('quantityInput').value);
404
+ if (quantity < 1) return;
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?.[0] || '',
417
+ quantity: quantity
418
  });
419
  }
420
 
421
  localStorage.setItem('cart', JSON.stringify(cart));
422
+ closeModal('quantityModal');
423
  updateCartButton();
424
  }
425
 
 
462
  document.getElementById('cartModal').style.display = 'block';
463
  }
464
 
465
+ function clearCart() {
466
+ localStorage.removeItem('cart');
467
+ closeModal('cartModal');
468
+ updateCartButton();
469
+ }
470
+
471
  window.onclick = function(event) {
472
  if (event.target.className === 'modal') {
473
  event.target.style.display = "none";
 
497
  {% if product.get('photos') %}
498
  {% for photo in product['photos'] %}
499
  <div class="swiper-slide">
500
+ <img src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/photos/{{ photo }}"
501
+ alt="{{ product['name'] }}"
502
+ style="width: 200px; height: 200px; object-fit: cover;">
503
  </div>
504
  {% endfor %}
505
  {% else %}
506
  <div class="swiper-slide">
507
+ <img src="https://via.placeholder.com/200" alt="No Image">
508
  </div>
509
  {% endif %}
510
  </div>
 
714
  {% if product.get('photos') and product['photos']|length > 0 %}
715
  <img src="https://huggingface.co/datasets/{{ repo_id }}/resolve/main/photos/{{ product['photos'][0] }}"
716
  alt="{{ product['name'] }}"
717
+ style="width: 100px; height: 100px; object-fit: cover;">
718
  {% endif %}
719
  <details>
720
  <summary>Редактировать</summary>