Zaktualizowano rozmiary plików w cache oraz dodano alert o przekroczeniu stanu w formularzu ilości produktów
This commit is contained in:
@@ -83,7 +83,7 @@
|
||||
{if !$is_catalog}
|
||||
<td data-id-product="{$combination.id_product|intval}" data-id-product-attribute="{$combination.id_product_attribute|intval}" data-column="{l s='Select quantity' mod='pdproductattributeslist'}" class="option_gty">
|
||||
<div class="row extra-small-gutters product-quantity">
|
||||
<input type="number" name="qty" inputmode="numeric" pattern="[0-9]*" class="quantity input-group form-control" min="0" value="0" />
|
||||
<input type="number" name="qty" inputmode="numeric" pattern="[0-9]*" class="quantity input-group form-control" min="0" value="0" alert_max="{$combination.quantity}" />
|
||||
</div>
|
||||
</td>
|
||||
{/if}
|
||||
@@ -101,4 +101,54 @@
|
||||
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
{literal}
|
||||
<!-- wklej tuż przed zamknięciem </body> lub w zewnętrznym pliku JS załadowanym po tabeli -->
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
document.querySelectorAll('td.option_gty').forEach(td => {
|
||||
const input = td.querySelector('input.quantity');
|
||||
if (!input) return;
|
||||
|
||||
const max = parseInt(input.getAttribute('alert_max'), 10) || 0;
|
||||
|
||||
// funkcja tworząca/usuń alert
|
||||
function checkQty() {
|
||||
const val = parseInt(input.value, 10) || 0;
|
||||
const existing = td.querySelector('.alert-max-exceeded');
|
||||
|
||||
if (val > max) {
|
||||
if (!existing) {
|
||||
const msg = document.createElement('div');
|
||||
msg.className = 'alert-max-exceeded text-danger';
|
||||
msg.style.marginTop = '4px';
|
||||
msg.style.fontSize = '0.9em';
|
||||
msg.innerHTML = 'Przekroczono stan,<br>braki trafią do back order.';
|
||||
td.querySelector('.product-quantity')
|
||||
.insertAdjacentElement('afterend', msg);
|
||||
}
|
||||
} else {
|
||||
if (existing) existing.remove();
|
||||
}
|
||||
}
|
||||
|
||||
// od razu sprawdź raz przy starcie
|
||||
checkQty();
|
||||
|
||||
// łapiemy ręczne wpisywanie…
|
||||
input.addEventListener('input', checkQty);
|
||||
|
||||
// …i wszelkie inne zmiany przez polling w tle
|
||||
(function monitor(prevValue = input.value) {
|
||||
const curr = input.value;
|
||||
if (curr !== prevValue) {
|
||||
checkQty();
|
||||
prevValue = curr;
|
||||
}
|
||||
requestAnimationFrame(() => monitor(prevValue));
|
||||
})();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
{/literal}
|
||||
Reference in New Issue
Block a user