I want to get all products by rating filter. here my code

$getProducts = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection');
$getProducts->addAttributeToFilter('visibility', 4);

So, how can I add here filter for rating so I need not to first get all product and then check all product with that rating issue.



You can try the below code for filter product collection by rating percent:

$collection = $_objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection');

$collection->getSelect()->joinLeft(array('rova'=> 'rating_option_vote_aggregated'),'e.entity_id =rova.entity_pk_value', array("percent" => 'percent'))->group('e.entity_id');

$collection->getSelect()->where("rova.percent = 80");

foreach($collection as $product){

100 Percent = 5 Star Rating

90 Percent = 4.5 Star Rating

80 Percent = 4 Star Rating

and so on...

  • can you give me average counting percentage? Dec 27 '19 at 9:34
  • You need to customise the query for that. Dec 27 '19 at 9:37
  • Yes but for average how can I write query can you tell me sir. Dec 27 '19 at 9:42

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.