I want to get all products by rating filter. here my code
$getProducts = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection'); $getProducts->addAttributeToSelect('*'); $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.
thanks
Hello @sarvesh21007
You can try the below code for filter product collection by rating percent:
$collection = $_objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection');$collection->addAttributeToSelect('*');$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){ //YOUR CODE }
100 Percent = 5 Star Rating
90 Percent = 4.5 Star Rating
80 Percent = 4 Star Rating
or you use this extension
https://marketplace.magento.com/sunarc-magento2-ratingfilter.html
@theMageComp Yes actually but I want average rating this return for all rating if there are like for price 60, value for 40 and quality for 20 and if I will filter by 20 then it also be in results but It should not be in results.