Hello everyone!
I’m trying to control the order of products in Shopware 6’s search and suggest functionality based on a custom database field. The goal is for products with a higher value in this field to appear at the top.
Here’s what I’ve tried so far, without success. According to my logs, my subscriber is definitely being triggered, but I must be missing something — if it’s even possible at all.
FieldSorting / Criteria Events (ProductSearchCriteriaEvent, ProductSuggestCriteriaEvent)
-
Idea: Use
FieldSortingon the custom field. -
Problem: The custom field is not officially registered in Shopware.
-
Result: Criteria events ignore the field; the sorting doesn’t work.
Direct query access via Criteria (getQuery())
-
Attempt: Manually add
ORDER BY msx_custom_rankingviagetQuery(). -
Problem:
getQuery()does not exist onProductSearchCriteriaEventorProductSuggestCriteriaEvent.
Events ProductSearchResultEvent / ProductSuggestResultEvent
-
Idea: Sort the products after loading using a repository (
getSortedIdsForProducts()) and then replace the elements via$products->setElements(). -
Problem: Even with the subscriber correctly triggered, the products were not sorted properly. Debug logs show the events fire, but the list remains unchanged.
Repository
-
Idea: Use a combination of a repository and a modified subscriber.
-
Problem: I haven’t found a working approach yet; apart from that, it’s tricky to write a proper search completely bypassing the DAL.
Unfortunately, none of this works. Does anyone have ideas or tips?
Thanks in advance!