-
-
Save smaege/b8e8d789b9a53ea7f74ded23e20fbf07 to your computer and use it in GitHub Desktop.
Variaatioiden käyttöönotto - Cora
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% if product.variants.size > 0 %} | |
{% for option in product.options_with_values %} | |
<div class="form-group"> | |
<label>{{ option.title }}</label> | |
<select class="form-control" name="variant-select"> | |
{% for value in option.values %} | |
{% if value.variant %} | |
<option value="{{ value.variant.url }}"{% if value.selected %} selected{% endif %}>{{ value.title }}</option> | |
{% endif %} | |
{% endfor %} | |
</select> | |
</div> | |
{% endfor %} | |
<script> | |
const selectElement = document.querySelectorAll('[name="variant-select"]').forEach(el => { | |
el.addEventListener('change', () => { | |
if (el.value) { | |
window.location.href = el.value; | |
} | |
}) | |
}); | |
</script> | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment