I have a product with a variant matrix field(productVariants
). Inside each variant is the option to supply a sale price (salePrice
).
On the front end, I'm trying to show a product grid of only products that are on sale. Sounds simple, but I can't for the life of me figure out the syntax.
Here's where I'm at so far using matrixBlock queries. A few things I am not clear on:
- owner - what is the owner? Docs only say
myEntry
and I'm not on a page or in a loop to get the entry that the matrix field is a part of fieldId
- is this the matrix field ID or the ID of the text field with the value I'm searching for?- How do I target
salePrice
in the search syntax since it's one of the fields inside the Matrix field?
{% set myMatrixBlockQuery = craft.matrixBlocks.owner(myEntry).fieldId(33).type('text').search('salePrice:*') %}
{% set saleEntries = myMatrixBlockQuery.all() %}
{% for product in saleEntries %}
{{ product.title }}, etc...
{% endfor %}
I've spent a couple of hours in StackExchange and in the Craft docs and still can't wrap my head around the syntax for this situation so I appreciate your help!