2

Two sections:

1) Products

2) Authors

The "Products" section pulls the author name from the "Authors" section through an entries type field.

I'd like to order the products first by authors (alphabetically), then by title.

Craft does not accept the author field handle in the

.order('authors','title').

Here is the "Products" template code:

{% set entries = craft.commerce.products.type('Products').relatedTo(category) %}
{% for entry in entries.order('author','title').limit(0) %}

What is missing?

2

Try something slightly different in concept...

On your Products template - /products/index.html - start with your Authors first and then look for the Products which are related to them.

Hopefully this will help you make sense of it...

{# find all author entries #}
{% set authors = craft.entries.section('authors').order('title') %}

<ul>
    {# loop through all author entries #}
    {% for author in authors %}
        <li>{{ author.title }}</li>

        {# find any products which may be related to the author #}
        {% set products = craft.entries.section('products').relatedTo(author) %}

        <ul>
            {# Loop through related products by this author #}
            {% for relatedProduct in products %}
                <li>{{ relatedProduct.title }}</li>
            {% endfor %}
        </ul>
    {% endfor %}
</ul>

Also, if your Authors will ever need to log in to Craft, then consider adding them as CMS Users instead of entries. I know this has licence fee implications, but it's just a thought.

Craft's relatedTo parameter is the key concept to understand. More info here: https://craftcms.com/docs/relations

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.