Hey everyone, I’m a bit stuck and could use your help. Up until now, my shop (Dawn theme) only had simple, single-variant products,but now we have introduced products with different variants. Previously, for simple products, I easily set up a true/false type metafield (product.metafields.custom.specialsettings), flipped it to True for products where I wanted a minimum order quantity, and popped this code into the main-product.liquid
<script>
document.addEventListener('DOMContentLoaded', function() {
var specialSettings = {{ product.metafields.custom.specialsettings | json }};
var quantityInputId = "Quantity-{{ section.id }}";
var quantityInput = document.getElementById(quantityInputId);
// minimum mennyiség és lépésköz beállítása
if (specialSettings) {
quantityInput.setAttribute('min', 50); // Minimum mennyiség beállítása
quantityInput.value = Math.max(50, parseInt(quantityInput.value, 10)); // Biztosítjuk, hogy az érték ne legyen kisebb, mint 50
quantityInput.setAttribute('step', 10); // Lépésköz beállítása
} else {
quantityInput.setAttribute('min', 1); // Alapértelmezett minimum mennyiség
quantityInput.setAttribute('step', 1); // Alapértelmezett lépésköz
}
// input változások figyelése, hogy a minimum mennyiség betartásáért
quantityInput.addEventListener('change', function() {
var currentValue = parseInt(quantityInput.value, 10);
var minValue = parseInt(quantityInput.getAttribute('min'), 10);
if (currentValue < minValue) {
quantityInput.value = minValue; // Ha a jelenlegi érték kisebb, mint a minimum, akkor minimum
}
});
});
</script>
But now, trying to apply the same logic to variants, it just doesn’t seem to work. I tried setting up a variant-level true/false metafield (variant.metafields.custom.specialsettings), setting it to True where needed, but no dice. Could anyone point me in the right direction on what I might be missing?