Answers.Body: <p>Personally I would use categories for a 'facetted search' filter you describe, as categories are less likely to get out of control. e.g. If tags are seldom re-used then a search for a tag may only produce a single result.</p>
  
  <p>This plugin may help you: <a href="https://github.com/iainurquhart/FacetedNav_CraftPlugin" rel="nofollow">https://github.com/iainurquhart/FacetedNav_CraftPlugin</a></p>
  
  <p>If you're going to use tags then I suggest making use of Craft's search functionality as this will allow you to submit the tag as a search term and <strong>also display any entries which contain the word/tag in ANY field</strong> of the entries within Craft.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-28T17:20:40.650Z
Answers.LastActivityDate: 2016-06-28T17:20:40.650Z
Answers.UserDisplayName: Matt P
Body: <p>I want to set up a product filter system based on variants' tags. I encounter two difficulties. </p>
  
  <p><strong>1. Outputting all variants' tags from a group of products.</strong></p>
  
  <pre><code>&lt;!-- Relation does not work --&gt;
  {% set products = craft.commerce.products.type('Custom').find() %}
  {% set variants = craft.commerce.variants.relatedTo(products) %} 
  
  {% for pattern in craft.tags.group('patternSwatch').relatedTo(variants) %}
      &lt;a href="?pattern={{ pattern.name | url_encode }}"&gt;{{ pattern.name }}&lt;/a&gt;
  {% endfor %}
  
  &lt;!-- This works but returns tags from ALL products' variants --&gt;
  {% for pattern in craft.tags.group('patternSwatch').relatedTo(craft.commerce.variants) %}
      &lt;a href="?pattern={{ pattern.name | url_encode }}"&gt;{{ pattern.name }}&lt;/a&gt;
  {% endfor %}
  </code></pre>
  
  <p><strong>2. Filter product based on the multiple variants' tags</strong></p>
  
  <pre><code>&lt;!-- This works, but what about filtering by multiple tags? --&gt;
  {% set pattern = craft.request.getParam('pattern') %}
  {% set tag = craft.tags.group('patternSwatch').title(pattern).first() %}
  {% set variants = craft.commerce.variants.relatedTo(tag) %}
  
  {% for v in variants %}
      {{ v.product.slug }}
  {% endfor %}
  </code></pre>
  
Tags: <plugin-craftcommerce><filter>
Title: Filter products by variants' tags
ThreadText: # Filter products by variants' tags
  
  (Asked by: username_0 on 2016-06-22)
  
  I want to set up a product filter system based on variants' tags. I encounter two difficulties.
  
  **1. Outputting all variants' tags from a group of products.**
  
  ```
  <!-- Relation does not work -->
  {% set products = craft.commerce.products.type('Custom').find() %}
  {% set variants = craft.commerce.variants.relatedTo(products) %} 
  
  {% for pattern in craft.tags.group('patternSwatch').relatedTo(variants) %}
      <a href="?pattern={{ pattern.name | url_encode }}">{{ pattern.name }}</a>
  {% endfor %}
  
  <!-- This works but returns tags from ALL products' variants -->
  {% for pattern in craft.tags.group('patternSwatch').relatedTo(craft.commerce.variants) %}
      <a href="?pattern={{ pattern.name | url_encode }}">{{ pattern.name }}</a>
  {% endfor %}
  
  ```
  
  **2. Filter product based on the multiple variants' tags**
  
  ```
  <!-- This works, but what about filtering by multiple tags? -->
  {% set pattern = craft.request.getParam('pattern') %}
  {% set tag = craft.tags.group('patternSwatch').title(pattern).first() %}
  {% set variants = craft.commerce.variants.relatedTo(tag) %}
  
  {% for v in variants %}
      {{ v.product.slug }}
  {% endfor %}
  
  ```
  
  **Tags:** plugin-craftcommerce, filter
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-06-28. Score: 2
  
  Personally I would use categories for a 'facetted search' filter you describe, as categories are less likely to get out of control. e.g. If tags are seldom re-used then a search for a tag may only produce a single result.
  
  This plugin may help you: <https://github.com/iainurquhart/FacetedNav_CraftPlugin>
  
  If you're going to use tags then I suggest making use of Craft's search functionality as this will allow you to submit the tag as a search term and **also display any entries which contain the word/tag in ANY field** of the entries within Craft.
  
  
  ---
  
  