2

What are all the available options that products can be ordered by?

craft.commerce.products({ order: '???' })

I have found this reference https://craftcommerce.com/docs/products-fields#templating but it does not list the available options.

Bonus points if it includes the key that sorts by sales (aka popularity).

2

When you call craft.commerce.products you're asking Craft for an Commerce_ProductModel.

So you could sort by:

  • title (alpha)
  • defaultPrice
  • type
  • promotable (sale products on top)
  • postDate (newest products)
  • .. etc.

To sort by sales (popularity), you might consider something like BonFire's Popular Products plugin which keeps track of how many purchases were made and how many times the product was viewed, very similar to Ben Croker's EntryCount plugin.

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.