collection – Custom Sorting on category page not working in Magento 2.4.2

I have Magento 2.4.2.

I have written a custom code to add A-Z & Z-A filters on category page.

I have added dependency injection using below code

<preference for="MagentoCatalogBlockProductProductListToolbar" type="VendorModuleNamePluginProductProductListToolbar" />

In below file, I have overridden setCollection function


public function setCollection($collection)
        $this->_collection = $collection;

        $limit = (int)$this->getLimit();
        if ($limit) {

        if ($this->getCurrentOrder()) {
            switch ($this->getCurrentOrder()) {
            case 'az':
                    $this->_collection->setOrder('name', 'asc');
                case 'za':
                    $this->_collection->setOrder('name', 'desc');


The issue is that this function is called twice, the first time it returns proper result (used X-debug to debug query of collection).
And the second time it is called, it messes up the query of the collection by adding some entity_id filter and sorters.

Due to which the collection expected isn’t coming.

What could be the reason of above function getting called twice.