Skip to content

Latest commit

 

History

History
32 lines (20 loc) · 1.32 KB

add_custom_sorts.md

File metadata and controls

32 lines (20 loc) · 1.32 KB

Add custom sorts

Create your own sorter service

You can create your own sorter service by implementing the SorterInterface interface.
For example, in your test application, we have a short description sorter.

Add the tag monsieurbiz.search.request.product_sorter to your service.

Replace existing sorter

In your services.yaml file, you can replace the existing sorter by your own service.

services:
    MonsieurBiz\SyliusSearchPlugin\Search\Request\Sorting\Product\PriceSorter:
        class: App\Search\Request\Sorting\Product\PriceSorter
        tags:
            - { name: monsieurbiz.search.request.product_sorter }

Don't forget to create your class!

If you want to keep the logic but add code before and/or after, you can also decorate the service.

Display the sorter in the front

Override the sorting.html.twig template to add your sort.

Tips

A text field can't be used for sorting. In this case, you can create a "keyword" subfield.