2

Trying to sort products by price.

Since the price of a product in Commerce isn't a textual custom field it's attached to a variant, I'm having trouble working out the syntax to make this happen.

{% set products = craft.commerce.products({
     relatedTo: (category), 
     order: defaultPrice,
}) %}

This seems close but delivers "Variable "defaultPrice" does not exist"

Appreciate any direction.

5

Close! This should do it:

{% set products = craft.commerce.products({
    relatedTo: (category), 
    order: 'defaultPrice',
}) %}

With the quotes it's a string. Without the quotes, Twig is expecting a variable you've defined called defaultPrice that doesn't exist.

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.