0

I have implemented a custom sorting of rating by creating a plugin

<type name="Magento\Catalog\Block\Product\ProductList\Toolbar">
        <plugin name="before_set_collection" type="Vendor\ModuleName\Plugin\Catalog\Product\Sorting\Custom" />
    </type>

with below code in custom.php plugin file

$countColumn = new \Zend_Db_Expr("COUNT(*)"); $percentColumn = new \Zend_Db_Expr("SUM(percent)/".$countColumn );

$collection->getSelect()->joinLeft(
                    'rating_option_vote_aggregated',
                    'e.entity_id = rating_option_vote_aggregated.entity_pk_value',
                    array('vote_count' => 'SUM(rating_option_vote_aggregated.vote_count)','average' => $percentColumn))
            ->group('e.entity_id')
            ->order('average ' . 'DESC');

Sorting and everything is working fine but the product count coming in toolbar always comes 1. Any idea why this is happening

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.