Skip to content

Instantly share code, notes, and snippets.

@smaege
Created April 18, 2024 04:43
Show Gist options
  • Save smaege/b8e8d789b9a53ea7f74ded23e20fbf07 to your computer and use it in GitHub Desktop.
Save smaege/b8e8d789b9a53ea7f74ded23e20fbf07 to your computer and use it in GitHub Desktop.
Variaatioiden käyttöönotto - Cora
{% 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