1

I'm trying to use price as a parameter for filtering my Craft Commerce products, but I cannot get it to work. I think the problem is with the way that I'm referring to the product price, but at the same time I'm not sure how to change it so that it will work.

Is it possible to filter by product price as I'm trying to do here ? Does anyone know what exactly I need to change to get my query to work ?

Any pointers in the right direction would be most appreciated.

{% set queryParams = {
    relatedTo: category,
      price: [
       'and',
       '>= ' ~ 200,
       '<= ' ~ 500,
      ]
 } %}

{% set products = craft.commerce.products(queryParams) %}

{% for product in products %}
    ....output product data
{% endfor %}
1

Looks like defaultPrice is the property on the Commerce_ProductElementType class you can use for this:

i.e.

{% set queryParams = {
    relatedTo: category,
        defaultPrice: [
            'and',
            '>= ' ~ 200,
            '<= ' ~ 500,
        ]
    }
%}
| improve this answer | |

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.