Hi,
I am trying to edit the Dawn theme such that the product listing has the first option selector as a pill and the second option selector as dropdown as I have many variants under the second option and the pill layout doesn’t look good with so many pills.
I have edited the main-product.liquid variant picker code as follows and while it looks right when rendered, as soon as I choose any option on the product page it says that the product is unavailable which is not correct. I think it is trying to verify the selection against the variants in the json file and failing, but this is a hunch. Can anyone help.
{%- when 'variant_picker' -%}
{%- unless product.has_only_default_variant -%}
<variant-radios class="no-js-hidden" data-section="{{ section.id }}" data-url="{{ product.url }}" {{ block.shopify_attributes }}>
{%- for option in product.options_with_values -%}
{% if forloop.first %}
<fieldset class="js product-form__input">
<legend class="form__label">{{ option.name }}</legend>
{%- for value in option.values -%}
<input type="radio" id="{{ section.id }}-{{ option.position }}-{{ forloop.index0 }}"
name="{{ option.name }}"
value="{{ value | escape }}"
form="{{ product_form_id }}"
{% if option.selected_value == value %}checked{% endif %}
{%- for variant in product.variants -%}
{% if value == variant.title %}
{% if variant.available == false %}class="outofstock"
{% endif %}
{% endif %}
{%- endfor -%}
>
<label for="{{ section.id }}-{{ option.position }}-{{ forloop.index0 }}"
{%- for variant in product.variants -%}
{% if value == variant.title %}
{% if variant.available == false %}class="outofstock"
{% endif %}
{% endif %}
{%- endfor -%}
>
{{ value }}
</label>
{%- endfor -%}
</fieldset>
{%- else -%}
<div class="product-form__input product-form__input--dropdown">
<label class="form__label" for="Option-{{ section.id }}-{{ forloop.index0 }}">
{{ option.name }}
</label>
<div class="select">
<select id="Option-{{ section.id }}-{{ forloop.index0 }}"
class="select__select"
name="options[{{ option.name | escape }}]"
form="{{ product_form_id }}"
>
{%- for value in option.values -%}
<option value="{{ value | escape }}" {% if option.selected_value == value %}selected="selected"{% endif %}>
{{ value }}
</option>
{%- endfor -%}
</select>
{% render 'icon-caret' %}
</div>
</div>
{%- endif -%}
{%- endfor -%}
<script type="application/json">
{{ product.variants | json }}
</script>
</variant-radios>
{%- endunless -%}
<noscript class="product-form__noscript-wrapper-{{ section.id }}">
<div class="product-form__input{% if product.has_only_default_variant %} hidden{% endif %}">
<label class="form__label" for="Variants-{{ section.id }}">{{ 'products.product.product_variants' | t }}</label>
<div class="select">
<select name="id" id="Variants-{{ section.id }}" class="select__select" form="{{ product_form_id }}">
{%- for variant in product.variants -%}
<option
{% if variant == product.selected_or_first_available_variant %}selected="selected"{% endif %}
{% if variant.available == false %}disabled{% endif %}
value="{{ variant.id }}"
>
{{ variant.title }}
{%- if variant.available == false %} - {{ 'products.product.sold_out' | t }}{% endif %}
- {{ variant.price | money | strip_html }}
</option>
{%- endfor -%}
</select>
{% render 'icon-caret' %}
</div>
</div>
</noscript>
Thanks,
Online_Seller