Kgshop commited on
Commit
bf2f558
·
verified ·
1 Parent(s): 2ba83c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -4
app.py CHANGED
@@ -869,15 +869,37 @@ MAIN_HTML = '''
869
  `;
870
  }
871
 
 
 
 
 
 
 
 
 
 
 
 
 
 
872
  let actionsHtml = '';
873
  if (role !== 'public') {
874
  if (activeLoc !== 'all') {
875
  if (stock > 0) {
876
  let varHtml = '';
877
  if (p.variants && p.variants.length > 0) {
878
- varHtml = `<select id="var_${pIdx}" class="form-control" style="padding:6px; font-size:0.8rem; margin-bottom:4px; height:auto;" onchange="updateMaxQty(${pIdx})">
879
- ${p.variants.map((v, i) => `<option value="${i}">${v.name} (+${v.price} ₸)</option>`).join('')}
880
- </select>`;
 
 
 
 
 
 
 
 
 
881
  }
882
 
883
  actionsHtml += `
@@ -972,7 +994,15 @@ MAIN_HTML = '''
972
  let vIdx = parseInt(vSelect.value);
973
  max = getLocStock(p.variants[vIdx].stocks);
974
  } else if (p.variants && p.variants.length > 0) {
975
- max = getLocStock(p.variants[0].stocks);
 
 
 
 
 
 
 
 
976
  } else {
977
  max = getLocStock(p.stocks);
978
  }
 
869
  `;
870
  }
871
 
872
+ if (p.variants && p.variants.length > 0) {
873
+ let pOpts = [];
874
+ p.variants.forEach((v, i) => {
875
+ let vStock = getLocStock(v.stocks);
876
+ if (activeLoc === 'all' || vStock > 0) {
877
+ pOpts.push(`<div style="font-size:0.8rem; color:var(--text-muted); margin-bottom:2px;">• ${v.name}: ${vStock} шт</div>`);
878
+ }
879
+ });
880
+ if (pOpts.length > 0) {
881
+ priceHtml += `<div style="margin-top:6px; margin-bottom:6px; background:#f9fafb; padding:6px; border-radius:6px; border:1px solid var(--border);">${pOpts.join('')}</div>`;
882
+ }
883
+ }
884
+
885
  let actionsHtml = '';
886
  if (role !== 'public') {
887
  if (activeLoc !== 'all') {
888
  if (stock > 0) {
889
  let varHtml = '';
890
  if (p.variants && p.variants.length > 0) {
891
+ let opts = [];
892
+ p.variants.forEach((v, i) => {
893
+ let vStock = getLocStock(v.stocks);
894
+ if (vStock > 0) {
895
+ opts.push(`<option value="${i}">${v.name} (+${v.price} ₸) - ${vStock} шт</option>`);
896
+ }
897
+ });
898
+ if (opts.length > 0) {
899
+ varHtml = `<select id="var_${pIdx}" class="form-control" style="padding:6px; font-size:0.8rem; margin-bottom:4px; height:auto;" onchange="updateMaxQty(${pIdx})">
900
+ ${opts.join('')}
901
+ </select>`;
902
+ }
903
  }
904
 
905
  actionsHtml += `
 
994
  let vIdx = parseInt(vSelect.value);
995
  max = getLocStock(p.variants[vIdx].stocks);
996
  } else if (p.variants && p.variants.length > 0) {
997
+ let firstValidStock = 0;
998
+ for (let i = 0; i < p.variants.length; i++) {
999
+ let vSt = getLocStock(p.variants[i].stocks);
1000
+ if (vSt > 0) {
1001
+ firstValidStock = vSt;
1002
+ break;
1003
+ }
1004
+ }
1005
+ max = firstValidStock;
1006
  } else {
1007
  max = getLocStock(p.stocks);
1008
  }