I’m setting up a custom Shopify theme for a client. Their products come in different colours and sizes. I need to display each colour variant separately on the collection page, but without showing all size variants as separate items.
Then, still on the collection page, within each product item, I need to display the range of sizes that variant is available in.
So something like:
T-shirt (Red)
Sizes: XS S M L XL XXL
T-shirt (Blue)
Sizes: XS S M L XL XXL
I’ve been using the solution from this post: Shopify show color variants in collection but not size variant, which has got me part of the way there - I am able to display the colour variants individually, but now I’m not sure how to then output the size variants along with the product.
Here’s a simplified version of the code I’m using:
{% for product in collection.products %}
{% for option in product.options %}
{% if option == "Color" or option == "Colour" %}
{% assign index = forloop.index0 %}
{% assign colorlist = '' %}
{% assign color = '' %}
{% for variant in product.variants %}
{% capture color %}
{{ variant.options[index] }}
{% endcapture %}
{% unless colorlist contains color %}
{% assign product = variant %}
<a class="product" href="{{ product.url | within: collection }}">
<img src="{{ product.featured_image.src | img_url: '480x480' }}">
{{ product.title }}
<ul class="product__sizes">
<!-- Need to output sizes here -->
</ul>
</a>
{% capture tempList %}
{{colorlist | append: color | append: ' '}}
{% endcapture %}
{% assign colorlist = tempList %}
{% endunless %}
{% endfor %}
{% endif %}
{% endfor %}
{% endfor %}
Any help at all is much appreciated!