1

I have a Products Section and a Product Category Structure Section In Products there is an Entries Field where the Category is selected from the Product Category section.

Is it possible to sort the products per category manually?

I see with the ManytoMany Plugin - https://github.com/page-8/craft-manytomany You can display the products which appear in each Category and the Custom Ordering of the second Relationship is in the pipeline which would probably work but not available yet.

Is there any other option?

  • So do you want to display the products per category or sort/order the products manually within their categories? – Luke Pearce May 19 '16 at 9:14
  • Both - when I click on the Category on the front end I want to load the products in that category - but I also want to be able to manually sort the order they are displayed. – mmc501 May 19 '16 at 9:16
  • To order the products you'd make that section into a structure and display the category you were sorting by in the listing and then re-order all products to be in category order - then re-order each product for each category. I'll test how to then output by category and provide a detailed answer - but it'll be something like loop through each category - set products to products related to current category - loop through those products – Luke Pearce May 19 '16 at 9:23
  • Ah - ding - you have it spot on - I was thinking of trying to sort within the categories entry. That will all work. I can Output them no problem. Thanks for the help - do you want to add that as the answer. – mmc501 May 19 '16 at 9:27
2

To order the products you'd make the Products section into a structure and display the category you were sorting by in the listing as a table column.

You can then re-order all products to be in category order (using the table column), then re-order each product for each category.

You can then output each product grouped by category with something along the lines of:

{% for cat in categories %}

  {% set products = products.relatedTo( cat ) %}

  {% for product in products %}

    {{ product.title }}

  {% endfor %}

{% endfor %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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