Skip to content

Commit

Permalink
Fix qty rules when there is no max set (#3356)
Browse files Browse the repository at this point in the history
  • Loading branch information
sofiamatulis authored Mar 25, 2024
1 parent 6b85358 commit ee4cacb
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions assets/product-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ if (!customElements.get('product-info')) {
const max = data.max === null ? data.max : data.max - data.cartQuantity;
if (max !== null) min = Math.min(min, max);
if (data.cartQuantity >= data.min) min = Math.min(min, data.step);

this.input.min = min;
this.input.max = max;

if (max) {
this.input.max = max;
} else {
this.input.removeAttribute('max')
}
this.input.value = min;
publish(PUB_SUB_EVENTS.quantityUpdate, undefined);
}
Expand Down Expand Up @@ -87,7 +91,11 @@ if (!customElements.get('product-info')) {
const attributes = ['data-cart-quantity', 'data-min', 'data-max', 'step'];
for (let attribute of attributes) {
const valueUpdated = updated.getAttribute(attribute);
if (valueUpdated !== null) current.setAttribute(attribute, valueUpdated);
if (valueUpdated !== null) {
current.setAttribute(attribute, valueUpdated)
} else {
current.removeAttribute(attribute)
}
}
} else {
current.innerHTML = updated.innerHTML;
Expand Down

0 comments on commit ee4cacb

Please sign in to comment.