I want to add sorting in Review Listing. What is the logic to add Sort by ratings?

enter image description here

I have override method getReviewsCollection() of Magento/Review/Block/Product/View.php So I have $this->_reviewsCollection on my hand.

Anyone has Idea how to apply sort on base of rating?


I found the Solution as below:

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

   ['sum' => 'SUM(percent)', 'count' => $countColumn, 'average' => $percentColumn]);


$this->_reviewsCollection->getSelect()->order('average desc');

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.