= 0 ? Number(maxInventoryRaw) : 0;
let enteredQuantity = Number(quantity);
if (isNaN(enteredQuantity) || enteredQuantity < 0) enteredQuantity = 0;
// Keep server call as-is (to preserve availability notification),
// but clamp the displayed quantity to available stock on the client.
changeCartItemQuantity(
item.key,
quantity,
true,
false
);
if (maxInventory > 0 && enteredQuantity > maxInventory) {
quantity = maxInventory;
}
setTimeout(function(){ button_loading = false}, 2000);
"
>
= 0 ? Number(maxInventoryRaw) : 0;
let enteredQuantity = Number(quantity);
if (isNaN(enteredQuantity) || enteredQuantity < 0) enteredQuantity = 0;
// Get current quantity in cart
const cartItem = cart.items.find(item => item.variant_id === 49103538061558);
const currentQuantity = cartItem ? cartItem.quantity : 0;
// If kolliAmount is missing or invalid, use entered quantity directly
if (!kolliAmount || isNaN(kolliAmount) || kolliAmount <= 0) {
let quantityToAdd = Math.max(enteredQuantity - currentQuantity, 0);
if (quantityToAdd > 0) {
addCartItem(
'49103538061558',
0,
quantityToAdd,
true,
false
);
} else if (enteredQuantity < currentQuantity) {
// User wants to decrease quantity
changeCartItemQuantity(
cartItem.key,
enteredQuantity,
true,
false
);
}
// Clamp the displayed quantity to available inventory,
// while still letting the server handle the true availability and notification.
if (maxInventory > 0 && enteredQuantity > maxInventory) {
quantity = maxInventory;
} else {
quantity = enteredQuantity;
}
setTimeout(function(){ button_loading = false}, 2000);
return;
}
// Round entered quantity up to nearest multiple of kolli
let targetQuantity = Math.ceil(enteredQuantity / kolliAmount) * kolliAmount;
// Cap at available inventory
if (targetQuantity > maxInventory) {
targetQuantity = Math.floor(maxInventory / kolliAmount) * kolliAmount;
}
// Ensure minimum of 1 kolli if user entered something
if (enteredQuantity > 0 && targetQuantity < kolliAmount) {
targetQuantity = kolliAmount;
// But still cap at inventory
if (targetQuantity > maxInventory) {
targetQuantity = maxInventory;
}
}
// Calculate how much to add/change
if (targetQuantity > currentQuantity) {
// Adding items
let quantityToAdd = targetQuantity - currentQuantity;
quantity = targetQuantity; // Update the input to show the rounded value
addCartItem(
'49103538061558',
0,
quantityToAdd,
true,
false
);
} else if (targetQuantity < currentQuantity) {
// Decreasing quantity
quantity = targetQuantity; // Update the input to show the rounded value
changeCartItemQuantity(
cartItem.key,
targetQuantity,
true,
false
);
} else {
// No change needed
quantity = targetQuantity; // Update the input to show the rounded value
}
setTimeout(function(){ button_loading = false}, 2000);
"
>
= 0 ? Number(maxInventoryRaw) : 0;
let enteredQuantity = Number(quantity);
if (isNaN(enteredQuantity) || enteredQuantity < 0) enteredQuantity = 0;
// Keep server call as-is (to preserve availability notification),
// but clamp the displayed quantity to available stock on the client.
changeCartItemQuantity(
item.key,
quantity,
true,
false
);
if (maxInventory > 0 && enteredQuantity > maxInventory) {
quantity = maxInventory;
}
setTimeout(function(){ button_loading = false}, 2000);
"
>
= 0 ? Number(maxInventoryRaw) : 0;
let enteredQuantity = Number(quantity);
if (isNaN(enteredQuantity) || enteredQuantity < 0) enteredQuantity = 0;
// Get current quantity in cart
const cartItem = cart.items.find(item => item.variant_id === 49103538094326);
const currentQuantity = cartItem ? cartItem.quantity : 0;
// If kolliAmount is missing or invalid, use entered quantity directly
if (!kolliAmount || isNaN(kolliAmount) || kolliAmount <= 0) {
let quantityToAdd = Math.max(enteredQuantity - currentQuantity, 0);
if (quantityToAdd > 0) {
addCartItem(
'49103538094326',
0,
quantityToAdd,
true,
false
);
} else if (enteredQuantity < currentQuantity) {
// User wants to decrease quantity
changeCartItemQuantity(
cartItem.key,
enteredQuantity,
true,
false
);
}
// Clamp the displayed quantity to available inventory,
// while still letting the server handle the true availability and notification.
if (maxInventory > 0 && enteredQuantity > maxInventory) {
quantity = maxInventory;
} else {
quantity = enteredQuantity;
}
setTimeout(function(){ button_loading = false}, 2000);
return;
}
// Round entered quantity up to nearest multiple of kolli
let targetQuantity = Math.ceil(enteredQuantity / kolliAmount) * kolliAmount;
// Cap at available inventory
if (targetQuantity > maxInventory) {
targetQuantity = Math.floor(maxInventory / kolliAmount) * kolliAmount;
}
// Ensure minimum of 1 kolli if user entered something
if (enteredQuantity > 0 && targetQuantity < kolliAmount) {
targetQuantity = kolliAmount;
// But still cap at inventory
if (targetQuantity > maxInventory) {
targetQuantity = maxInventory;
}
}
// Calculate how much to add/change
if (targetQuantity > currentQuantity) {
// Adding items
let quantityToAdd = targetQuantity - currentQuantity;
quantity = targetQuantity; // Update the input to show the rounded value
addCartItem(
'49103538094326',
0,
quantityToAdd,
true,
false
);
} else if (targetQuantity < currentQuantity) {
// Decreasing quantity
quantity = targetQuantity; // Update the input to show the rounded value
changeCartItemQuantity(
cartItem.key,
targetQuantity,
true,
false
);
} else {
// No change needed
quantity = targetQuantity; // Update the input to show the rounded value
}
setTimeout(function(){ button_loading = false}, 2000);
"
>
= 0 ? Number(maxInventoryRaw) : 0;
let enteredQuantity = Number(quantity);
if (isNaN(enteredQuantity) || enteredQuantity < 0) enteredQuantity = 0;
// Keep server call as-is (to preserve availability notification),
// but clamp the displayed quantity to available stock on the client.
changeCartItemQuantity(
item.key,
quantity,
true,
false
);
if (maxInventory > 0 && enteredQuantity > maxInventory) {
quantity = maxInventory;
}
setTimeout(function(){ button_loading = false}, 2000);
"
>
= 0 ? Number(maxInventoryRaw) : 0;
let enteredQuantity = Number(quantity);
if (isNaN(enteredQuantity) || enteredQuantity < 0) enteredQuantity = 0;
// Get current quantity in cart
const cartItem = cart.items.find(item => item.variant_id === 49103538127094);
const currentQuantity = cartItem ? cartItem.quantity : 0;
// If kolliAmount is missing or invalid, use entered quantity directly
if (!kolliAmount || isNaN(kolliAmount) || kolliAmount <= 0) {
let quantityToAdd = Math.max(enteredQuantity - currentQuantity, 0);
if (quantityToAdd > 0) {
addCartItem(
'49103538127094',
0,
quantityToAdd,
true,
false
);
} else if (enteredQuantity < currentQuantity) {
// User wants to decrease quantity
changeCartItemQuantity(
cartItem.key,
enteredQuantity,
true,
false
);
}
// Clamp the displayed quantity to available inventory,
// while still letting the server handle the true availability and notification.
if (maxInventory > 0 && enteredQuantity > maxInventory) {
quantity = maxInventory;
} else {
quantity = enteredQuantity;
}
setTimeout(function(){ button_loading = false}, 2000);
return;
}
// Round entered quantity up to nearest multiple of kolli
let targetQuantity = Math.ceil(enteredQuantity / kolliAmount) * kolliAmount;
// Cap at available inventory
if (targetQuantity > maxInventory) {
targetQuantity = Math.floor(maxInventory / kolliAmount) * kolliAmount;
}
// Ensure minimum of 1 kolli if user entered something
if (enteredQuantity > 0 && targetQuantity < kolliAmount) {
targetQuantity = kolliAmount;
// But still cap at inventory
if (targetQuantity > maxInventory) {
targetQuantity = maxInventory;
}
}
// Calculate how much to add/change
if (targetQuantity > currentQuantity) {
// Adding items
let quantityToAdd = targetQuantity - currentQuantity;
quantity = targetQuantity; // Update the input to show the rounded value
addCartItem(
'49103538127094',
0,
quantityToAdd,
true,
false
);
} else if (targetQuantity < currentQuantity) {
// Decreasing quantity
quantity = targetQuantity; // Update the input to show the rounded value
changeCartItemQuantity(
cartItem.key,
targetQuantity,
true,
false
);
} else {
// No change needed
quantity = targetQuantity; // Update the input to show the rounded value
}
setTimeout(function(){ button_loading = false}, 2000);
"
>
= 0 ? Number(maxInventoryRaw) : 0;
let enteredQuantity = Number(quantity);
if (isNaN(enteredQuantity) || enteredQuantity < 0) enteredQuantity = 0;
// Keep server call as-is (to preserve availability notification),
// but clamp the displayed quantity to available stock on the client.
changeCartItemQuantity(
item.key,
quantity,
true,
false
);
if (maxInventory > 0 && enteredQuantity > maxInventory) {
quantity = maxInventory;
}
setTimeout(function(){ button_loading = false}, 2000);
"
>
= 0 ? Number(maxInventoryRaw) : 0;
let enteredQuantity = Number(quantity);
if (isNaN(enteredQuantity) || enteredQuantity < 0) enteredQuantity = 0;
// Get current quantity in cart
const cartItem = cart.items.find(item => item.variant_id === 49103538159862);
const currentQuantity = cartItem ? cartItem.quantity : 0;
// If kolliAmount is missing or invalid, use entered quantity directly
if (!kolliAmount || isNaN(kolliAmount) || kolliAmount <= 0) {
let quantityToAdd = Math.max(enteredQuantity - currentQuantity, 0);
if (quantityToAdd > 0) {
addCartItem(
'49103538159862',
0,
quantityToAdd,
true,
false
);
} else if (enteredQuantity < currentQuantity) {
// User wants to decrease quantity
changeCartItemQuantity(
cartItem.key,
enteredQuantity,
true,
false
);
}
// Clamp the displayed quantity to available inventory,
// while still letting the server handle the true availability and notification.
if (maxInventory > 0 && enteredQuantity > maxInventory) {
quantity = maxInventory;
} else {
quantity = enteredQuantity;
}
setTimeout(function(){ button_loading = false}, 2000);
return;
}
// Round entered quantity up to nearest multiple of kolli
let targetQuantity = Math.ceil(enteredQuantity / kolliAmount) * kolliAmount;
// Cap at available inventory
if (targetQuantity > maxInventory) {
targetQuantity = Math.floor(maxInventory / kolliAmount) * kolliAmount;
}
// Ensure minimum of 1 kolli if user entered something
if (enteredQuantity > 0 && targetQuantity < kolliAmount) {
targetQuantity = kolliAmount;
// But still cap at inventory
if (targetQuantity > maxInventory) {
targetQuantity = maxInventory;
}
}
// Calculate how much to add/change
if (targetQuantity > currentQuantity) {
// Adding items
let quantityToAdd = targetQuantity - currentQuantity;
quantity = targetQuantity; // Update the input to show the rounded value
addCartItem(
'49103538159862',
0,
quantityToAdd,
true,
false
);
} else if (targetQuantity < currentQuantity) {
// Decreasing quantity
quantity = targetQuantity; // Update the input to show the rounded value
changeCartItemQuantity(
cartItem.key,
targetQuantity,
true,
false
);
} else {
// No change needed
quantity = targetQuantity; // Update the input to show the rounded value
}
setTimeout(function(){ button_loading = false}, 2000);
"
>