Answers.Body: <p>It's a bit confusing, but since this product type has variants, using this should work:</p>
  
  <pre><code>shop/{object.categories.first().slug}/{object.slug}
  </code></pre>
  
  <p>If it didn't have variants, you wouldn't need the <code>object</code> reference in front of it.  The same thing applies if you're referencing a field inside of Matrix as well.</p>
  
  <p>This has been made easier in the upcoming Commerce 2 so you don't have to worry about the differences.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-26T00:14:11.123Z
Answers.LastActivityDate: 2017-10-26T00:14:11.123Z
Answers.UserDisplayName: Brad Bell
Body: <p>I'm in the middle of learning Craft Commerce.  When I go to an individual product my URL says <code>/shop/wella-shampoo/</code>.  I'd like it to say <code>/shop/**hair-care**/wella-shampoo/</code> because this is the category this product falls into.</p>
  <p>I've tried adding <code>shop/{categories.first().slug}/{slug}</code> to the URL Format but I get the following error:</p>
  <blockquote>
  <p>Internal Server Error</p>
  <p>Craft\Commerce_ProductModel and its behaviors do not have a method or closure named &quot;categories&quot;.</p>
  </blockquote>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-10-20T23:14:16.167Z
Comments.Text: Is `categories` the name of a Category Field Type on your Product Type's Field Layout?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-10-21T09:24:09.693Z
Comments.Text: Hi, no the field is called 'assignToCategory'?
Comments.UserDisplayName: Martin
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-10-21T15:22:19.020Z
Comments.Text: And does this particular product have variants or no?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-10-23T13:38:38.057Z
Comments.Text: Yes, the product has variants
Comments.UserDisplayName: Martin
Tags: <plugin-craftcommerce><categories><url>
Title: Get the category into the url of the product page
ThreadText: # Get the category into the url of the product page
  
  (Asked by: username_0 on 2017-10-20)
  
  I'm in the middle of learning Craft Commerce. When I go to an individual product my URL says `/shop/wella-shampoo/`. I'd like it to say `/shop/**hair-care**/wella-shampoo/` because this is the category this product falls into.
  
  I've tried adding `shop/{categories.first().slug}/{slug}` to the URL Format but I get the following error:
  
  > Internal Server Error
  >
  > Craft\Commerce\_ProductModel and its behaviors do not have a method or closure named "categories".
  
  **Tags:** plugin-craftcommerce, categories, url
  
  > **Comments:**
  > **username_1**: Is `categories` the name of a Category Field Type on your Product Type's Field Layout?  
  > **username_0**: Hi, no the field is called 'assignToCategory'?  
  > **username_1**: And does this particular product have variants or no?  
  > **username_0**: Yes, the product has variants  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-10-26. Score: 1
  
  It's a bit confusing, but since this product type has variants, using this should work:
  
  ```
  shop/{object.categories.first().slug}/{object.slug}
  
  ```
  
  If it didn't have variants, you wouldn't need the `object` reference in front of it. The same thing applies if you're referencing a field inside of Matrix as well.
  
  This has been made easier in the upcoming Commerce 2 so you don't have to worry about the differences.
  
  
  ---
  
  