I have a catalog of games. Every game has its own price. The price is a numeric field.
At the moment I'm building a game catalog filter, and now I'm stuck on implementing the ability to filter products by price. There are two input in the filter form: maximum and minimum price fields.
<div>
Search by price:<br />
from:<input name="min" type="text" value="">
to:<input name="max" type="text" value="">
</div>
By filling in these two fields, the user needs to show the games within the selected price. A few questions, the answers to which will help me get closer to the solution:
1.How do I find out the price of the most expensive and minimal game?
2.This is how in the twig template I check for the presence of the minprice or maxprice parameter in the url.
{% set games = craft.entries().section('games') %}
{% set minprice = craft.app.request.getQueryParam('min') %}
{% if minprice %}
{% do .................. %}
{% endif %}
{% set maxprice = craft.app.request.getQueryParam('max') %}
{% if maxprice %}
{% do .................. %}
{% endif %}
I do not know what to write in my code instead of dots. Help me please with this))
{% set max = craft.entries().section('games').orderBy('priceBaz DESC').one() %}But I do not know how much it is correct – Dimi Nov 17 '22 at 13:52set max = craft.entries().section('games').getValue('priceField').max()– Dimi Nov 18 '22 at 17:45select()to limit the results to one particular field (see this question and all the answers for details) and execute the query with.scalar()to get the price as a single scalar value. But I wouldn't spend my time worrying about theoretical performance bottlenecks until you actually hit one. – MoritzLost Nov 19 '22 at 18:19