How can I filter Craft Commerce products by the current price Building on from this question How can I filter Craft Commerce products by price

I have a price filter in the store

Using this code works fine for the normal price

{% set queryParams = {
        relatedTo: category,
        defaultPrice: [
            'and',
            '&gt;= ' ~ 0,
            '&lt;= ' ~ 90,
        ]
    }
%}


but defaultPrice does not consider sale prices.

So if a product is normally $99 but it is reduced to $89, it won't be returned

I would have expected defaultPrice to store the current price being charged. So the sale price if it was on sale.

Is it possible to filter by price and include sale prices?

I've spent hours now on something I thought would be simple. It seems the only way to get this information is to get the products and loop through them. Checking for sale prices.

Do I have to create a plugin to make a usable price filter?
https://craftcommerce.com/docs/variant-model#saleprice

The comment on the documentation leads me to believe you can just use salePrice for your filtering as it will be equal to the defaultPrice if there is no sale.

So:

{% set queryParams = {
        relatedTo: category,
        salePrice: [
            'and',
            '&gt;= ' ~ 0,
            '&lt;= ' ~ 90,
        ]
    }
%}