respect existing items in cart for order_min

This commit is contained in:
Richard Schreiber
2023-06-02 09:14:03 +02:00
parent 956ee2785f
commit 73d2077d67
2 changed files with 7 additions and 1 deletions

View File

@@ -21,7 +21,7 @@
</div>
<div role="rowgroup" class="firstchild-in-panel">
{% for line in cart.positions %}
<div role="row" class="row cart-row {% if hide_prices %}hide-prices{% endif %} {% if download %}has-downloads{% endif %}{% if editable %}editable{% endif %}">
<div role="row" class="row cart-row {% if hide_prices %}hide-prices{% endif %} {% if download %}has-downloads{% endif %}{% if editable %}editable{% endif %}" data-item="{{ line.item.id }}" data-count="{{ line.count }}">
<div role="cell" class="product">
<p>
{% if line.addon_to %}

View File

@@ -130,6 +130,12 @@ var form_handlers = function (el) {
}).on("change", function(e) {
var quantity = parseFloat(this.value) || 0;
var itemOrderMin = parseFloat(this.getAttribute("data-min")) || 0;
if (itemOrderMin) {
document.querySelectorAll(".cart-row[data-item='"+this.id.substring(5)+"']").forEach(function(row) {
itemOrderMin -= (parseFloat(row.getAttribute("data-count")) || 1)
});
if (itemOrderMin < 0) itemOrderMin = 0;
}
if (quantity && quantity < itemOrderMin) {
this.value = this.previousValue > quantity ? 0 : itemOrderMin;
}