Laced Records/ Devolver Qty limits
This is mainly for Laced Records & Devolver stores, but might be useful in future builds. This will limit product qty to 5 per checkout (assuming there are no custom line item properties).
product-form.liquid
Find quantity input should look like this:
<input type="text" name="quantity" id="quantity" value="1" />change to
<input type="number" name="quantity" id="quantity" value="1" max="5" />
page-cart.liquid
Find the quantity input and change it's parent <td> element max value to 5.
<td class="cart-item-quantity" {% unless item.variant.inventory_management == blank or item.variant.inventory_policy == 'continue' %}data-max="{{ item.variant.inventory_quantity }}"{% endunless %}>
change to
<td class="cart-item-quantity" {% unless item.variant.inventory_management == blank or item.variant.inventory_policy == 'continue' %}data-max="5"{% endunless %}>
also add below script to trigger value staying at 5 on page load.
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$( document ).ready(function() {
$( '.cart-item-quantity-display' ).each(function() {
if( $(this).val() > 5 ){
$(this).val(5).trigger('change');
}
});
});
</script>
theme.js.liquid
Find the popup for low inventory and remove/comment out completely as it is not needed... looks like (line 1056):
if (newQuantity > inventory) {
modalContent = new ModalContent({
title: "Not Available",
message: "<p>Sorry, we only have " + inventory + " in stock.</p>",
button: "Okay"
});
new ModalView({
model: modalContent,
el: this.$(".modal-wrapper")
});
}
also remove/comment out
inventory = parseInt(productRow.find(".cart-item-quantity").data("max"), 10);
between the two codes that are removed/comment out, should look like this:
if ($(e.target).hasClass(".cart-item-quantity-display")) {
newQuantity = productQuantity;
} else if ($(e.target).hasClass("cart-item-increase")) {
newQuantity = oldQuantity + 1;
} else {
newQuantity = oldQuantity - 1;
}
if (newQuantity === 0) {
this.removeProduct(null, variant);
return;
}
needs conditions for the 5 limit, so change to:
if ($(e.target).hasClass("cart-item-quantity-display")) {
if(oldQuantity < 5){
newQuantity = productQuantity;
}
else{
newQuantity = 5;
}
} else if ($(e.target).hasClass("cart-item-increase")) {
if(oldQuantity < 5){
newQuantity = oldQuantity + 1;
}
} else {
newQuantity = oldQuantity - 1;
}
if (newQuantity === 0) {
this.removeProduct(null, variant);
return;
}
theme.liquid
the {% include 'redirect' %} will need to be contained in an unless cart page; otherwise, it will break the change event on qty... like so
{% unless template contains "cart" %}
{% include 'redirect' %}
{% endunless %}