Kgshop commited on
Commit
cc3fee3
·
verified ·
1 Parent(s): 4fd6041

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +126 -60
app.py CHANGED
@@ -201,7 +201,8 @@ def get_env_data(env_id):
201
  "admin_password_enabled": False,
202
  "admin_password": "",
203
  "checkout_fields_enabled": False,
204
- "checkout_fields": {"name": False, "phone": False, "city": False, "address": False, "zip": False}
 
205
  }
206
 
207
  env_data = all_data.get(env_id, {})
@@ -562,10 +563,10 @@ CATALOG_TEMPLATE = '''
562
  @media (min-width: 768px) { .product-grid { grid-template-columns: repeat(3, 1fr); gap: 15px; padding: 0 20px; } }
563
  @media (min-width: 1024px) { .product-grid { grid-template-columns: repeat(4, 1fr); gap: 20px; padding: 0 20px; } }
564
 
565
- .product-card { width: 100%; aspect-ratio: 1 / 1; display: flex; flex-direction: column; background: #ffffff; border-radius: 12px; overflow: hidden; cursor: pointer; transition: opacity 0.2s ease-in-out, transform 0.2s; box-shadow: 0 4px 10px rgba(0,0,0,0.1); position: relative; }
566
  .dark-theme .product-card { background: #2a2a2a; }
567
  .product-card:active { transform: scale(0.96); }
568
- .product-image-container { width: 100%; height: 100%; position: relative; background-color: #f5f5f5; }
569
  .dark-theme .product-image-container { background-color: #1a1a1a; }
570
  .product-image-container img { width: 100%; height: 100%; object-fit: cover; }
571
  .top-product-indicator { position: absolute; top: 10px; right: 10px; background-color: var(--accent); color: var(--text-dark); padding: 4px 10px; font-size: 0.75rem; border-radius: 12px; font-weight: 700; z-index: 10; box-shadow: 0 2px 5px rgba(0,0,0,0.2); }
@@ -573,6 +574,15 @@ CATALOG_TEMPLATE = '''
573
  .product-info-bottom { display: none; }
574
  .no-results-message { padding: 40px 20px; text-align: center; font-size: 1.2rem; color: var(--text-light); opacity: 0.7; font-weight: 500; }
575
 
 
 
 
 
 
 
 
 
 
576
  .floating-buttons-container { position: fixed; bottom: 25px; right: 25px; display: flex; flex-direction: column; gap: 15px; z-index: 1000; }
577
  .floating-button { background-color: var(--accent); color: var(--text-dark); border: none; border-radius: 50%; width: 60px; height: 60px; font-size: 1.6rem; cursor: pointer; display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 20px rgba(0,0,0,0.3); transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); text-decoration: none; }
578
  .floating-button:hover { background-color: var(--accent-hover); transform: translateY(-5px) scale(1.05); }
@@ -728,6 +738,7 @@ CATALOG_TEMPLATE = '''
728
  const envId = '{{ env_id }}';
729
  const bType = '{{ settings.business_type }}';
730
  const orgName = `{{ settings.organization_name }}`.replace(/`/g, '');
 
731
  let cart = JSON.parse(localStorage.getItem(`mekaCart_${envId}`) || '[]');
732
 
733
  const itemsPerPage = 20;
@@ -771,74 +782,119 @@ CATALOG_TEMPLATE = '''
771
  renderCatalog();
772
  }
773
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
774
  function renderCatalog() {
775
  const searchTerm = document.getElementById('search-input').value.toLowerCase().trim();
 
776
 
777
- let filtered = allProducts.filter(p => {
778
- let matchCat = currentCategory === 'all' || p.category === currentCategory;
779
- let matchSearch = searchTerm === '' || (p.name || '').toLowerCase().includes(searchTerm) || (p.description || '').toLowerCase().includes(searchTerm);
780
- return matchCat && matchSearch;
781
- });
782
-
783
- const totalPages = Math.ceil(filtered.length / itemsPerPage) || 1;
784
- if (currentPage > totalPages) currentPage = totalPages;
785
 
786
- const start = (currentPage - 1) * itemsPerPage;
787
- const paginated = filtered.slice(start, start + itemsPerPage);
 
 
788
 
789
- const container = document.getElementById('catalog-content');
790
- if (filtered.length === 0) {
791
- container.innerHTML = '<p class="no-results-message">По вашему запросу ничего не найдено.</p>';
792
- return;
793
- }
 
 
 
 
794
 
795
- let html = '<div class="product-grid">';
796
- paginated.forEach(product => {
797
- let minPrice = 0;
798
- if (product.tags && product.tags.length > 0) {
799
- let prices = product.tags.map(t => bType === 'wholesale' ? (t.box_price || t.price) : t.price);
800
- minPrice = Math.min(...prices);
 
 
801
  }
802
-
803
- let photoUrl = (product.photos && product.photos.length > 0)
804
- ? `https://huggingface.co/datasets/${repoId}/resolve/main/photos/${product.photos[0]}`
805
- : `https://via.placeholder.com/300x300.png?text=${encodeURIComponent(orgName)}`;
806
-
807
- let topBadge = product.is_top ? '<span class="top-product-indicator"><i class="fas fa-star"></i></span>' : '';
808
- let priceBadge = minPrice > 0 ? `<div class="price-badge">От ${minPrice.toFixed(0)} ${currencyCode}</div>` : '';
 
809
 
810
- html += `
811
- <div class="product-card" onclick="openModalById('${product.product_id}')">
812
- <div class="product-image-container">
813
- ${topBadge}
814
- <img src="${photoUrl}" alt="${product.name}" loading="lazy" onerror="this.src='https://via.placeholder.com/300x300.png?text=Error'">
815
- ${priceBadge}
816
- </div>
817
- <div class="product-info-bottom"><h3 class="product-title">${product.name}</h3></div>
818
- </div>
819
- `;
820
- });
821
- html += '</div>';
822
 
823
- if (totalPages > 1) {
824
- html += '<div class="pagination">';
825
- if (currentPage > 1) {
826
- html += `<button onclick="changePage(${currentPage - 1})"><i class="fas fa-chevron-left"></i></button>`;
827
  }
828
- for (let i = 1; i <= totalPages; i++) {
829
- if (i === 1 || i === totalPages || (i >= currentPage - 1 && i <= currentPage + 1)) {
830
- html += `<button class="${i === currentPage ? 'active' : ''}" onclick="changePage(${i})">${i}</button>`;
831
- } else if (i === currentPage - 2 || i === currentPage + 2) {
832
- html += `<span class="dots">...</span>`;
 
 
 
 
 
 
833
  }
 
 
 
 
 
 
 
 
 
 
 
834
  }
835
- if (currentPage < totalPages) {
836
- html += `<button onclick="changePage(${currentPage + 1})"><i class="fas fa-chevron-right"></i></button>`;
837
- }
838
- html += '</div>';
839
  }
840
-
841
- container.innerHTML = html;
842
  }
843
 
844
  function changePage(page) {
@@ -1024,7 +1080,7 @@ CATALOG_TEMPLATE = '''
1024
  const product = getProductById(productId);
1025
  const tag = product.tags.find(t => t.id === tagId);
1026
  let variantName = colorCode.includes('_VAR_') ? colorCode.split('_VAR_')[1] : "";
1027
- let unitLabel = unitType === 'box' ? `[Упак: ${tag.box_qty}шт]` : ` [Шт]`;
1028
  let itemPrice = unitType === 'box' ? tag.box_price : tag.price;
1029
  let itemName = product.name + " (" + tag.name + (variantName ? ` - ${variantName}` : "") + ")" + unitLabel;
1030
  let photoUrl = product.photos && product.photos[tag.photo_index] ? product.photos[tag.photo_index] : null;
@@ -2619,6 +2675,14 @@ ADMIN_TEMPLATE = '''
2619
  {% endfor %}
2620
  </select>
2621
 
 
 
 
 
 
 
 
 
2622
  <button type="submit" class="add-button" style="margin-top: 20px;"><i class="fas fa-save"></i> Сохранить настройки</button>
2623
  </form>
2624
  </div>
@@ -3259,7 +3323,8 @@ def create_environment():
3259
  "color_scheme": "default",
3260
  "business_type": "retail", "env_mode": env_mode, "welcome_message_enabled": False, "welcome_message_text": "Добро пожаловать в наш магазин!",
3261
  "inventory_tracking": False, "admin_password_enabled": False, "admin_password": "",
3262
- "checkout_fields_enabled": False, "checkout_fields": {"name": False, "phone": False, "city": False, "address": False, "zip": False}
 
3263
  },
3264
  'inventory_history':[]
3265
  }
@@ -4032,6 +4097,7 @@ def admin(env_id):
4032
  'address': 'cf_address' in request.form,
4033
  'zip': 'cf_zip' in request.form
4034
  }
 
4035
 
4036
  avatar_file = request.files.get('chat_avatar')
4037
  if avatar_file and avatar_file.filename:
 
201
  "admin_password_enabled": False,
202
  "admin_password": "",
203
  "checkout_fields_enabled": False,
204
+ "checkout_fields": {"name": False, "phone": False, "city": False, "address": False, "zip": False},
205
+ "categories_as_lines": False
206
  }
207
 
208
  env_data = all_data.get(env_id, {})
 
563
  @media (min-width: 768px) { .product-grid { grid-template-columns: repeat(3, 1fr); gap: 15px; padding: 0 20px; } }
564
  @media (min-width: 1024px) { .product-grid { grid-template-columns: repeat(4, 1fr); gap: 20px; padding: 0 20px; } }
565
 
566
+ .product-card { width: 100%; aspect-ratio: auto; display: flex; flex-direction: column; background: #ffffff; border-radius: 12px; overflow: hidden; cursor: pointer; transition: opacity 0.2s ease-in-out, transform 0.2s; box-shadow: 0 4px 10px rgba(0,0,0,0.1); position: relative; }
567
  .dark-theme .product-card { background: #2a2a2a; }
568
  .product-card:active { transform: scale(0.96); }
569
+ .product-image-container { width: 100%; aspect-ratio: 1/1; position: relative; background-color: #f5f5f5; }
570
  .dark-theme .product-image-container { background-color: #1a1a1a; }
571
  .product-image-container img { width: 100%; height: 100%; object-fit: cover; }
572
  .top-product-indicator { position: absolute; top: 10px; right: 10px; background-color: var(--accent); color: var(--text-dark); padding: 4px 10px; font-size: 0.75rem; border-radius: 12px; font-weight: 700; z-index: 10; box-shadow: 0 2px 5px rgba(0,0,0,0.2); }
 
574
  .product-info-bottom { display: none; }
575
  .no-results-message { padding: 40px 20px; text-align: center; font-size: 1.2rem; color: var(--text-light); opacity: 0.7; font-weight: 500; }
576
 
577
+ .category-line-section { margin-bottom: 40px; }
578
+ .category-line-title { font-size: 1.4rem; color: var(--bg-medium); margin: 0 15px 15px 15px; font-weight: 700; border-bottom: 2px solid var(--accent); display: inline-block; padding-bottom: 5px; }
579
+ .dark-theme .category-line-title { color: var(--accent); border-bottom-color: var(--bg-medium); }
580
+ .category-line-grid { display: grid; grid-template-rows: repeat(2, 1fr); grid-auto-flow: column; grid-auto-columns: 160px; gap: 15px; padding: 0 15px 10px 15px; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; }
581
+ @media (min-width: 768px) { .category-line-grid { grid-auto-columns: 200px; gap: 20px; padding: 0 20px 10px 20px; } .category-line-title { margin: 0 20px 15px 20px; } }
582
+ .category-line-grid::-webkit-scrollbar { display: none; }
583
+ .category-line-grid .product-card { scroll-snap-align: start; height: auto; }
584
+ .hide-chips .category-chips-container { display: none; }
585
+
586
  .floating-buttons-container { position: fixed; bottom: 25px; right: 25px; display: flex; flex-direction: column; gap: 15px; z-index: 1000; }
587
  .floating-button { background-color: var(--accent); color: var(--text-dark); border: none; border-radius: 50%; width: 60px; height: 60px; font-size: 1.6rem; cursor: pointer; display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 20px rgba(0,0,0,0.3); transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); text-decoration: none; }
588
  .floating-button:hover { background-color: var(--accent-hover); transform: translateY(-5px) scale(1.05); }
 
738
  const envId = '{{ env_id }}';
739
  const bType = '{{ settings.business_type }}';
740
  const orgName = `{{ settings.organization_name }}`.replace(/`/g, '');
741
+ const categoriesAsLines = {{ 'true' if settings.categories_as_lines else 'false' }};
742
  let cart = JSON.parse(localStorage.getItem(`mekaCart_${envId}`) || '[]');
743
 
744
  const itemsPerPage = 20;
 
782
  renderCatalog();
783
  }
784
 
785
+ function buildProductCard(product) {
786
+ let minPrice = 0;
787
+ if (product.tags && product.tags.length > 0) {
788
+ let prices = product.tags.map(t => bType === 'wholesale' ? (t.box_price || t.price) : t.price);
789
+ minPrice = Math.min(...prices);
790
+ }
791
+ let photoUrl = (product.photos && product.photos.length > 0)
792
+ ? `https://huggingface.co/datasets/${repoId}/resolve/main/photos/${product.photos[0]}`
793
+ : `https://via.placeholder.com/300x300.png?text=${encodeURIComponent(orgName)}`;
794
+ let topBadge = product.is_top ? '<span class="top-product-indicator"><i class="fas fa-star"></i></span>' : '';
795
+ let priceBadge = minPrice > 0 ? `<div class="price-badge">От ${minPrice.toFixed(0)} ${currencyCode}</div>` : '';
796
+ return `
797
+ <div class="product-card" onclick="openModalById('${product.product_id}')">
798
+ <div class="product-image-container">
799
+ ${topBadge}
800
+ <img src="${photoUrl}" alt="${product.name}" loading="lazy" onerror="this.src='https://via.placeholder.com/300x300.png?text=Error'">
801
+ ${priceBadge}
802
+ </div>
803
+ <div class="product-info-bottom"><h3 class="product-title">${product.name}</h3></div>
804
+ </div>
805
+ `;
806
+ }
807
+
808
+ function buildCategorySection(categoryName, products) {
809
+ let html = `<div class="category-line-section">`;
810
+ html += `<h2 class="category-line-title">${categoryName}</h2>`;
811
+ html += `<div class="category-line-grid">`;
812
+ products.forEach(product => {
813
+ html += buildProductCard(product);
814
+ });
815
+ html += `</div></div>`;
816
+ return html;
817
+ }
818
+
819
  function renderCatalog() {
820
  const searchTerm = document.getElementById('search-input').value.toLowerCase().trim();
821
+ const container = document.getElementById('catalog-content');
822
 
823
+ if (categoriesAsLines) {
824
+ document.body.classList.add('hide-chips');
825
+ let filtered = allProducts.filter(p => {
826
+ return searchTerm === '' || (p.name || '').toLowerCase().includes(searchTerm) || (p.description || '').toLowerCase().includes(searchTerm);
827
+ });
 
 
 
828
 
829
+ if (filtered.length === 0) {
830
+ container.innerHTML = '<p class="no-results-message">По вашему запросу ничего не найдено.</p>';
831
+ return;
832
+ }
833
 
834
+ let grouped = {};
835
+ orderedCategories.forEach(c => grouped[c] = []);
836
+ if (!grouped['Без категории']) grouped['Без категории'] =[];
837
+
838
+ filtered.forEach(p => {
839
+ let cat = p.category || 'Без категории';
840
+ if (!grouped[cat]) grouped[cat] = [];
841
+ grouped[cat].push(p);
842
+ });
843
 
844
+ let html = '';
845
+ orderedCategories.forEach(cat => {
846
+ if (grouped[cat] && grouped[cat].length > 0) {
847
+ html += buildCategorySection(cat, grouped[cat]);
848
+ }
849
+ });
850
+ if (grouped['Без категории'] && grouped['Без категории'].length > 0 && !orderedCategories.includes('Без категории')) {
851
+ html += buildCategorySection('Без категории', grouped['Без категории']);
852
  }
853
+ container.innerHTML = html;
854
+ } else {
855
+ document.body.classList.remove('hide-chips');
856
+ let filtered = allProducts.filter(p => {
857
+ let matchCat = currentCategory === 'all' || p.category === currentCategory;
858
+ let matchSearch = searchTerm === '' || (p.name || '').toLowerCase().includes(searchTerm) || (p.description || '').toLowerCase().includes(searchTerm);
859
+ return matchCat && matchSearch;
860
+ });
861
 
862
+ const totalPages = Math.ceil(filtered.length / itemsPerPage) || 1;
863
+ if (currentPage > totalPages) currentPage = totalPages;
864
+
865
+ const start = (currentPage - 1) * itemsPerPage;
866
+ const paginated = filtered.slice(start, start + itemsPerPage);
 
 
 
 
 
 
 
867
 
868
+ if (filtered.length === 0) {
869
+ container.innerHTML = '<p class="no-results-message">По вашему запросу ничего не найдено.</p>';
870
+ return;
 
871
  }
872
+
873
+ let html = '<div class="product-grid">';
874
+ paginated.forEach(product => {
875
+ html += buildProductCard(product);
876
+ });
877
+ html += '</div>';
878
+
879
+ if (totalPages > 1) {
880
+ html += '<div class="pagination">';
881
+ if (currentPage > 1) {
882
+ html += `<button onclick="changePage(${currentPage - 1})"><i class="fas fa-chevron-left"></i></button>`;
883
  }
884
+ for (let i = 1; i <= totalPages; i++) {
885
+ if (i === 1 || i === totalPages || (i >= currentPage - 1 && i <= currentPage + 1)) {
886
+ html += `<button class="${i === currentPage ? 'active' : ''}" onclick="changePage(${i})">${i}</button>`;
887
+ } else if (i === currentPage - 2 || i === currentPage + 2) {
888
+ html += `<span class="dots">...</span>`;
889
+ }
890
+ }
891
+ if (currentPage < totalPages) {
892
+ html += `<button onclick="changePage(${currentPage + 1})"><i class="fas fa-chevron-right"></i></button>`;
893
+ }
894
+ html += '</div>';
895
  }
896
+ container.innerHTML = html;
 
 
 
897
  }
 
 
898
  }
899
 
900
  function changePage(page) {
 
1080
  const product = getProductById(productId);
1081
  const tag = product.tags.find(t => t.id === tagId);
1082
  let variantName = colorCode.includes('_VAR_') ? colorCode.split('_VAR_')[1] : "";
1083
+ let unitLabel = unitType === 'box' ? `[Упак: ${tag.box_qty}шт]` : `[Шт]`;
1084
  let itemPrice = unitType === 'box' ? tag.box_price : tag.price;
1085
  let itemName = product.name + " (" + tag.name + (variantName ? ` - ${variantName}` : "") + ")" + unitLabel;
1086
  let photoUrl = product.photos && product.photos[tag.photo_index] ? product.photos[tag.photo_index] : null;
 
2675
  {% endfor %}
2676
  </select>
2677
 
2678
+ <div style="background: #E0F2F1; padding: 20px; border-radius: 12px; margin-top: 25px; margin-bottom: 25px; border: 1px solid #B2DFDB;">
2679
+ <h4 style="margin-top: 0; color: var(--bg-medium); font-size: 1.1rem;"><i class="fas fa-th-list"></i> Внешний вид каталога</h4>
2680
+ <label style="display: flex; align-items: center; gap: 8px;">
2681
+ <input type="checkbox" name="categories_as_lines" {% if settings.categories_as_lines %}checked{% endif %}>
2682
+ Отображать категории линиями (2 строки товаров с горизонтальной прокруткой)
2683
+ </label>
2684
+ </div>
2685
+
2686
  <button type="submit" class="add-button" style="margin-top: 20px;"><i class="fas fa-save"></i> Сохранить настройки</button>
2687
  </form>
2688
  </div>
 
3323
  "color_scheme": "default",
3324
  "business_type": "retail", "env_mode": env_mode, "welcome_message_enabled": False, "welcome_message_text": "Добро пожаловать в наш магазин!",
3325
  "inventory_tracking": False, "admin_password_enabled": False, "admin_password": "",
3326
+ "checkout_fields_enabled": False, "checkout_fields": {"name": False, "phone": False, "city": False, "address": False, "zip": False},
3327
+ "categories_as_lines": False
3328
  },
3329
  'inventory_history':[]
3330
  }
 
4097
  'address': 'cf_address' in request.form,
4098
  'zip': 'cf_zip' in request.form
4099
  }
4100
+ settings['categories_as_lines'] = 'categories_as_lines' in request.form
4101
 
4102
  avatar_file = request.files.get('chat_avatar')
4103
  if avatar_file and avatar_file.filename: