I'm working for the first time with Craft Commerce and trying to create product types. So far so good, now I have three product types: "Inspiration", "Gift" and "New". I need the URL of these three product types and don't know how to create it... actually the URL is shop/products with all products.

I need shop/inspiration with the inspiration products, shop/gift with the gift products and shop/new with the new products.

With {{ productType.name }} I can show all my product types, but how can I show the URL of product types?

{% for productType in craft.commerce.productTypes %}
  {{ productType.name }}<br>
    {% for product in craft.commerce.products.type(productType.handle).find() %}
      {{ product.url }}<br>
    {% endfor %}
{% endfor %}

Or do I need to create these product types as categories?

Hope you guys can help me!

1 Answer 1


Probably the most Craft-y way would be to use categories for classification and set your categories to have URLs.

Alternatively, you could do this with a route that points shop/* (ie. shop/{some token} - at a template, say shop/product_type and in that template use the second segment of the url in retrieving products of the appropriate type (or, of course, create 3 routes and 3 templates if they way you're handling those index pages differs a lot).

In general how Craft deals with routes/urls is documented here: https://craftcms.com/docs/routing And some more info on routes is here: https://straightupcraft.com/events/routes-and-patterns

Then to create your menu/list or whatever, something like:

{% for productType in craft.commerce.productTypes %}
  <a href="/shop/{{ productType.handle }}"{{ productType.name }}</a><br>
{% endfor %}

(on phone so excuse any syntax errors)

  • 2
    I'm seriously impressed you typed all of that on a phone.
    – Brad Bell
    May 4, 2017 at 2:43
  • I've learned swipe (swype?) typing lately which is great for a lot of things, but all the formatting stuff is a major PITA still. But I like to do a little helping over brekky and I can get away with it as long as I don't go sit at my pc ;) May 4, 2017 at 2:46
  • Thank you Jeremy, this is working great! I have decided to add categories - the only issue at this point is how I filter the products. For example shop/gift - I want only the gift products there. do you have any idea?
    – Özlem
    May 8, 2017 at 11:38
  • Really that's a separate question almost, but basically something like this - if the second url segment is the product type handle: {% set products = craft.commerce.products.type(craft.request.getSegment(2)).find() or if it is a categories slug in there for example: {% set category = craft.categories.slug(craft.request.getSegment(2)) %} {% set products = craft.commerce.products.relatedTo(category) %} May 8, 2017 at 23:35
  • See documentation here: craftcommerce.com/docs/craft-commerce-products May 8, 2017 at 23:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.