Answers.Body: <p><strong>The Simplest Answer</strong></p>
  
  <p><code>{% set products = craft.commerce.products.search(query).order('score') %}</code></p>
  
  <p>However, I am not sure a search is guaranteed to return ALL the products in quite the same way as using relatedTo, which is how you'd typically get entries/products related to a category - so see below.</p>
  
  <p><strong>A Slightly Fuller Answer</strong></p>
  
  <p>(Using your form)</p>
  
  <p>So in this case I think you're just wanting to get all products <em>related</em> to a category?  As in, you're not actually searching within those right?  </p>
  
  <p>If so you can leave out the search parameter below, as all you're doing is finding the products related to the category.  </p>
  
  <p>(If you want to search <em>within</em> those products for something else, <em>then</em> you need the <code>search: "some value"</code> part).</p>
  
  <p>Anyway, <code>q</code> has your category (title?) in it (would be better to use the slug in your form values really), so you can just:</p>
  
  <pre><code>{% set categoryTitle= craft.request.getParam('q') %}
  {% set category = craft.categories.title(categoryTitle) %}  {# (or better change form values and this to .slug) #}
  {% set products = craft.commerce.products({
                  relatedTo: category,
                  search: "whatever",  
                  order: "title asc",
              }) %}
  {% for product in products %}
      etc...
  </code></pre>
  
  <p>(Obviously a more typical way of doing this is to do it off a url segment or whatever for an index page, rather than by a search)</p>
  
  <hr>
  
  <p><strong>A Considerably Fuller Answer</strong></p>
  
  <p>Absolutely you can search products in the same way.  Even better, since about Craft 2.5 when they added the <code>serachScore</code> to the results, you can simultaneously search multiple element types and combine the results.</p>
  
  <p>Here's some sample code that will get you started:</p>
  
  <pre><code>    {% if query|length %}
  
      {% set product_results = craft.commerce.products.search(query).order('score').limit(limit_for_each_section).with('variants') %}  
      {% set article_results = craft.entries.search(query).order('score').limit(limit_for_each_section) %}
      {% set category_results = craft.categories.search(query).order('score').limit(limit_for_each_section) %}
  
      {% set all_results = [] %}
  
      {% if product_results|length %}
          {% set all_results = all_results|merge(product_results) %}
      {% endif %}
      {% if article_results|length %}
          {% set all_results = all_results|merge(article_results) %}
      {% endif %}
      {% if category_results|length %}
          {% set all_results = all_results|merge(category_results) %}
      {% endif %}
  
      {% if all_results|length %}
  
          &lt;br&gt;&lt;br&gt;
  
          {% set all_results = all_results|sortByField('searchScore', 'desc') %}
  
          {% set items = [] %}
  
              {% for result in all_results %}
  
              {% if result.url|length %}
  
                  {% if result.elementType == 'Commerce_Product' %}
  
                       ... etc
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-11T15:17:39.350Z
Answers.Text: Jeremy, thank you for the help above.  I have been trying to get it to work, but to no avail.  Could you give me something a little more simply that works with just the form.  Thank you in advance.
Answers.UserDisplayName: user1663102
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-11T21:08:49.560Z
Answers.Text: Post where you have got to (form plus results code) and I will take a look.  Do an update to your post above (or come to the commerce slack!)
Answers.UserDisplayName: Jeremy Daalder
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-11T23:35:25.790Z
Answers.Text: See updated answer...
Answers.UserDisplayName: Jeremy Daalder
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-12T21:01:38.590Z
Answers.Text: This did it....
  {% set products = craft.commerce.products.search(query).order('score') %}
Answers.UserDisplayName: user1663102
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-12T23:20:35.310Z
Answers.Text: Yes, that works, but it isn't really how you should get entries/products related to a category I think - it's possible it might not return ALL products in a category the way relatedTo will as it's doing a text style search, so you're probably better off using the approach detailed above (I've expanded it to cover three ways!)
Answers.UserDisplayName: Jeremy Daalder
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-05T23:20:00.813Z
Answers.LastActivityDate: 2016-05-12T23:18:53.550Z
Answers.LastEditDate: 2016-05-12T23:18:53.550Z
Answers.UserDisplayName: Jeremy Daalder
Body: <p>I am using the following form in Craft</p>
  
  <pre><code>&lt;div class="parts-search"&gt;
  
      &lt;form class="parts-search-block" action="{{ url('parts/results') }}" method="get"&gt;
  
          {#-- CATEGORY SEARCH --#}
          &lt;div class="col col-33"&gt;
              &lt;label class="form-top"&gt;Search by Category:&lt;/label&gt;&lt;br /&gt;
              &lt;select name="q"&gt;
                  &lt;option value=""&gt;--Select A Category--&lt;/option&gt;
                  &lt;option value="Compressors"&gt;Compressors&lt;/option&gt;
                  &lt;option value="Coolers"&gt;Coolers&lt;/option&gt;
                  &lt;option value="Doors"&gt;Doors&lt;/option&gt;
                  &lt;option value="Electrical"&gt;Electrical&lt;/option&gt;
                  &lt;option value="Freezers"&gt;Freezers&lt;/option&gt;
                  &lt;option value="Gaskets"&gt;Gaskets&lt;/option&gt;
                  &lt;option value="GFV"&gt;GFV&lt;/option&gt;
                  &lt;option value="Glass"&gt;Glass&lt;/option&gt;
                  &lt;option value="Graphics"&gt;Graphics&lt;/option&gt;
                  &lt;option value="Grills"&gt;Grills&lt;/option&gt;
                  &lt;option value="Harnesses"&gt;Harnesses&lt;/option&gt;
                  &lt;option value="Lighting"&gt;Lighting&lt;/option&gt;
                  &lt;option value="Misc"&gt;Misc&lt;/option&gt;
                  &lt;option value="Motors"&gt;Motors&lt;/option&gt;
                  &lt;option value="Plastic"&gt;Plastic&lt;/option&gt;
                  &lt;option value="Refrigeration"&gt;Refrigeration&lt;/option&gt;
                  &lt;option value="Repair Panels"&gt;Repair Panels&lt;/option&gt;
                  &lt;option value="Shelves"&gt;Shelves&lt;/option&gt;
                  &lt;option value="Skins"&gt;Skins&lt;/option&gt;
                  &lt;option value="Vendor"&gt;Vendor&lt;/option&gt;
              &lt;/select&gt;
          &lt;/div&gt;
          {#-- CATEGORY SEARCH --#}
  
          &lt;div class="col col-34"&gt;
              &lt;button type="submit" class="cat-search"&gt;
                  Begin Search
              &lt;/button&gt;
          &lt;/div&gt;
  
          &lt;div class="clear-fix"&gt;&lt;/div&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>And calling it on the results page with...</p>
  
  <pre><code>    {% set query = craft.request.getParam('q') %}
      {% set entries = craft.entries.section('parts').search(query).order('score') %}
  
      {% for entry in entries %}
  </code></pre>
  
  <p>I am now using Craft Commerce and need to use the form to search my Commerce Products.  Is this possible?  Any suggestions?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-11T10:25:09.167Z
Comments.Text: You should not delete the original question - otherwise the answers have no context.  Stack exchange operates best as a question and answer forum.
Comments.UserDisplayName: Jeremy Daalder
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-11T17:00:19.017Z
Comments.Text: @JeremyDaalder: I've reverted the edit back to the actual question.
Comments.UserDisplayName: Lindsey D
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-08-11T17:01:35.103Z
Comments.Text: To the OP... If you have found a solution on your own, please post it as an **answer**. Don't overwrite the question with your resolved code, that is not useful to others.
Comments.UserDisplayName: Lindsey D
Tags: <plugin-craftcommerce>
Title: Search Form with Craft Commerce
ThreadText: # Search Form with Craft Commerce
  
  (Asked by: username_0 on 2016-05-05)
  
  I am using the following form in Craft
  
  ```
  <div class="parts-search">
  
      <form class="parts-search-block" action="{{ url('parts/results') }}" method="get">
  
          {#-- CATEGORY SEARCH --#}
          <div class="col col-33">
              <label class="form-top">Search by Category:</label><br />
              <select name="q">
                  <option value="">--Select A Category--</option>
                  <option value="Compressors">Compressors</option>
                  <option value="Coolers">Coolers</option>
                  <option value="Doors">Doors</option>
                  <option value="Electrical">Electrical</option>
                  <option value="Freezers">Freezers</option>
                  <option value="Gaskets">Gaskets</option>
                  <option value="GFV">GFV</option>
                  <option value="Glass">Glass</option>
                  <option value="Graphics">Graphics</option>
                  <option value="Grills">Grills</option>
                  <option value="Harnesses">Harnesses</option>
                  <option value="Lighting">Lighting</option>
                  <option value="Misc">Misc</option>
                  <option value="Motors">Motors</option>
                  <option value="Plastic">Plastic</option>
                  <option value="Refrigeration">Refrigeration</option>
                  <option value="Repair Panels">Repair Panels</option>
                  <option value="Shelves">Shelves</option>
                  <option value="Skins">Skins</option>
                  <option value="Vendor">Vendor</option>
              </select>
          </div>
          {#-- CATEGORY SEARCH --#}
  
          <div class="col col-34">
              <button type="submit" class="cat-search">
                  Begin Search
              </button>
          </div>
  
          <div class="clear-fix"></div>
      </form>
  
  ```
  
  And calling it on the results page with...
  
  ```
      {% set query = craft.request.getParam('q') %}
      {% set entries = craft.entries.section('parts').search(query).order('score') %}
  
      {% for entry in entries %}
  
  ```
  
  I am now using Craft Commerce and need to use the form to search my Commerce Products. Is this possible? Any suggestions?
  
  **Tags:** plugin-craftcommerce
  
  > **Comments:**
  > **username_1**: You should not delete the original question - otherwise the answers have no context.  Stack exchange operates best as a question and answer forum.  
  > **username_2**: @username_1: I've reverted the edit back to the actual question.  
  > **username_2**: To the OP... If you have found a solution on your own, please post it as an **answer**. Don't overwrite the question with your resolved code, that is not useful to others.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-05-05. Score: 2
  
  **The Simplest Answer**
  
  `{% set products = craft.commerce.products.search(query).order('score') %}`
  
  However, I am not sure a search is guaranteed to return ALL the products in quite the same way as using relatedTo, which is how you'd typically get entries/products related to a category - so see below.
  
  **A Slightly Fuller Answer**
  
  (Using your form)
  
  So in this case I think you're just wanting to get all products *related* to a category? As in, you're not actually searching within those right?
  
  If so you can leave out the search parameter below, as all you're doing is finding the products related to the category.
  
  (If you want to search *within* those products for something else, *then* you need the `search: "some value"` part).
  
  Anyway, `q` has your category (title?) in it (would be better to use the slug in your form values really), so you can just:
  
  ```
  {% set categoryTitle= craft.request.getParam('q') %}
  {% set category = craft.categories.title(categoryTitle) %}  {# (or better change form values and this to .slug) #}
  {% set products = craft.commerce.products({
                  relatedTo: category,
                  search: "whatever",  
                  order: "title asc",
              }) %}
  {% for product in products %}
      etc...
  
  ```
  
  (Obviously a more typical way of doing this is to do it off a url segment or whatever for an index page, rather than by a search)
  
  ---
  
  **A Considerably Fuller Answer**
  
  Absolutely you can search products in the same way. Even better, since about Craft 2.5 when they added the `serachScore` to the results, you can simultaneously search multiple element types and combine the results.
  
  Here's some sample code that will get you started:
  
  ```
      {% if query|length %}
  
      {% set product_results = craft.commerce.products.search(query).order('score').limit(limit_for_each_section).with('variants') %}  
      {% set article_results = craft.entries.search(query).order('score').limit(limit_for_each_section) %}
      {% set category_results = craft.categories.search(query).order('score').limit(limit_for_each_section) %}
  
      {% set all_results = [] %}
  
      {% if product_results|length %}
          {% set all_results = all_results|merge(product_results) %}
      {% endif %}
      {% if article_results|length %}
          {% set all_results = all_results|merge(article_results) %}
      {% endif %}
      {% if category_results|length %}
          {% set all_results = all_results|merge(category_results) %}
      {% endif %}
  
      {% if all_results|length %}
  
          <br><br>
  
          {% set all_results = all_results|sortByField('searchScore', 'desc') %}
  
          {% set items = [] %}
  
              {% for result in all_results %}
  
              {% if result.url|length %}
  
                  {% if result.elementType == 'Commerce_Product' %}
  
                       ... etc
  
  ```
  
  > **Comments:**
  > **username_0**: username_1, thank you for the help above.  I have been trying to get it to work, but to no avail.  Could you give me something a little more simply that works with just the form.  Thank you in advance.  
  > **username_1**: Post where you have got to (form plus results code) and I will take a look.  Do an update to your post above (or come to the commerce slack!)  
  > **username_1**: See updated answer...  
  > **username_0**: This did it.... {% set products = craft.commerce.products.search(query).order('score') %}  
  > **username_1**: Yes, that works, but it isn't really how you should get entries/products related to a category I think - it's possible it might not return ALL products in a category the way relatedTo will as it's doing a text style search, so you're probably better off using the approach detailed above (I've expanded it to cover three ways!)  
  
  ---
  
  