<p>I never used Craft Commerce but you usually store relations (no matter which) with the id - not the title. So I expect the Commerce plugin will only recognize your category with this html</p>

<pre class="lang-twig prettyprint-override"><code> &lt;select id="chocOptions" name="fields[chocolateOptions][]" class="options"&gt;
      &lt;option title="selectOption"&gt;Select Option&lt;/option&gt;
      {% for category in craft.categories.group('chocolate') %}
           &lt;option value="{{ category.id }}"&gt;{{ category.title }}&lt;/option&gt;
      {% endfor %} 
 &lt;/select&gt; 
</code></pre>

<p>And you have to name your field correctly like statet <a href="https://craftcms.stackexchange.com/a/13105/5557">here</a></p>

<p><strong>Edit</strong><br>
The easiest way to get to know how you have to build your html is the following</p>

<ol>
<li>open the form in your Craft CP</li>
<li>Right click on the field</li>
<li>Click on "inspect" or "inspect element" or something like this</li>
<li>Search for the input or a hidden input. When I inspect a normal relation field it looks like this</li>
</ol>

<pre class="lang-html prettyprint-override"><code>&lt;div class="element small removable hasstatus" data-id="13" data-locale="de" data-status="live"
     data-label="" data-url="" data-editable=""&gt;
    &lt;!-- this is the important part --&gt;
    &lt;input type="hidden" name="fields[relation][]" value="13"&gt;
   &lt;!-- end --&gt;
    &lt;a class="delete icon" title="Entfernen"&gt;&lt;/a&gt;
    &lt;span class="status live"&gt;&lt;/span&gt;
    &lt;div class="label"&gt;
        &lt;span class="title"&gt;Some Name&lt;/span&gt;
    &lt;/div&gt;
&lt;/div&gt;
</code></pre>

CC BY-SA 3.0
2017-12-29T14:34:24.903Z
It's a normal relation field. You'll display it like every other relation in Craft. There are plenty threads how to display related entries and the docs https://craftcms.com/docs/relations#getting-target-elements-via-the-source-element
Robin Schambach
CC BY-SA 3.0
2017-12-29T14:40:42.467Z
Thank you Robin. I added the code you suggested to the product entry page...After selecting an option in the dropdown, adding the product to the cart and then viewing that cart, the customer should be able to view the selected dropdown option attributed to that product. Instead, my current code (for the cart) displays every option that could have been selected and not the particular option selected by the customer. Here is my code on the cart page:
`{% for category in craft.categories.group('chocolate') %}
        <p>{{ category.title }}</p>
 {% endfor %}`
Have any suggestions?
Chris Dougherty
CC BY-SA 3.0
2017-12-29T14:41:44.580Z
I already answered your question before you deleted it
Robin Schambach
CC BY-SA 3.0
2017-12-28T18:53:47.913Z
2017-12-28T19:04:46.163Z
2017-12-28T19:04:46.163Z
Robin Schambach
<p>I've created a form in which to specify a category for a product on the product entry page. I can't seem to add the category that the customer selects to the order model. I've checked the orders in the control panel and they do not seem to be storing the category. Does anybody know how to add a selected category to the order model?</p>

<pre class="lang-html prettyprint-override"><code>&lt;form id="values" method="POST"&gt; 
     &lt;input type="hidden" name="action" value="commerce/cart/updateCart"&gt;
     &lt;input type="hidden" name="redirect" value="cart"&gt;
     ...
     &lt;select id="chocOptions" name="chocolateOptions" class="options"&gt;
          &lt;option title="selectOption"&gt;Select Option&lt;/option&gt;
          {% for category in craft.categories.group('chocolate') %}
               &lt;option value="{{ category.title }}"&gt;{{ category.title }}&lt;/option&gt;
          {% endfor %} 
     &lt;/select&gt; 
     ...
&lt;/form&gt;
</code></pre>

<plugin-craftcommerce><form><order>
Product category not being added to the order model. Craft Commerce
# Product category not being added to the order model. Craft Commerce

(Asked by: username_0 on 2017-12-28)

I've created a form in which to specify a category for a product on the product entry page. I can't seem to add the category that the customer selects to the order model. I've checked the orders in the control panel and they do not seem to be storing the category. Does anybody know how to add a selected category to the order model?
 
     
     
     ...
     
          Select Option
          {% for category in craft.categories.group('chocolate') %}
               {{ category.title }}
          {% endfor %} 
      
     ...

**Tags:** plugin-craftcommerce, form, order

---

## 1 answers

### Answer by username_1 on 2017-12-28. Score: 1

I never used Craft Commerce but you usually store relations (no matter which) with the id - not the title. So I expect the Commerce plugin will only recognize your category with this html
 
      Select Option
      {% for category in craft.categories.group('chocolate') %}
           {{ category.title }}
      {% endfor %} 
  

And you have to name your field correctly like statet here
Edit
The easiest way to get to know how you have to build your html is the following

open the form in your Craft CP
Right click on the field
Click on "inspect" or "inspect element" or something like this
Search for the input or a hidden input. When I inspect a normal relation field it looks like this


    
    
   
    
    
    
        Some Name

> **Comments:**
> **username_1**: It's a normal relation field. You'll display it like every other relation in Craft. There are plenty threads how to display related entries and the docs https://craftcms.com/docs/relations#getting-target-elements-via-the-source-element  
> **username_0**: Thank you Robin. I added the code you suggested to the product entry page...After selecting an option in the dropdown, adding the product to the cart and then viewing that cart, the customer should be able to view the selected dropdown option attributed to that product. Instead, my current code (for the cart) displays every option that could have been selected and not the particular option selected by the customer. Here is my code on the cart page: `{% for category in craft.categories.group('chocolate') %}         <p>{{ category.title }}</p>  {% endfor %}` Have any suggestions?  
> **username_1**: I already answered your question before you deleted it  

---

