tag filter

anoush
Tourist
7 0 1

Hi, 

a while ago i've found this code to iterate products variants and adapted to my need to show all variant images within a catalog page.

https://durgastore.com/collections/colori

My question is about how to let user filter available tags

Thank you

Anoush

{% for tag in collection.all_tags %}
{% capture current_tag %}/{{ tag }}/{% endcapture %}

	{% for product in collection.products %}
		{% for product_tag in product.tags %}
		{% capture current_tag2 %}/{{ product_tag }}/{% endcapture %}
			{% if current_tag contains current_tag2 %}
					{% assign seen_variants ='' %}
				
					{% for variant in product.variants %}
						{% assign variant_options = '' %}
						{% unless product.options[0] == 'Formato' %}
							{% assign variant_options = variant_options | append: ",," | append: variant.option1 %}
						{% endunless %}
						{% unless product.options[1] == 'Formato' %}
							{% assign variant_options = variant_options | append: ",," | append: variant.option2 %}
						{% endunless %}
						{% unless product.options[2] == 'Formato' %}
							{% assign variant_options = variant_options | append: ",," | append: variant.option3 %}
						{% endunless %}
				
						{% assign variant_options = variant_options | replace: ",,", " " | strip %}
				
						{% unless seen_variants contains variant_options and seen_variants != '' %}
							{% assign seen_variants = seen_variants | append: ",," | append: variant_options %}
		{% if tag == 'Colori' %}
        <div class="card critical-clear has-animated card--reveal" style="min-height:200px;">
          <a class="shop-now" href="{{ product.url }}"><strong>{{ product.title | escape  }}</strong> <br /> {{ variant.option2 | escape  }}<br />
      <img src="{{ variant.image | img_url: 'large' }}" alt="{{ product.title | escape  }}" style="max-height:117px;width:100%;"/></a>  
                                    
    </div> 
        				{% endif %}
        			{% endunless %}
					{% endfor %}
			{% else %}
			{% endif %}
		{% endfor %}
	{% endfor %}
{% endfor %}

 

0 Likes