Skip to content

Issue with getting custom review collection based on product entity ids array with limited records

I am using this class to get review collection.

MagentoReviewModelResourceModelReviewCollectionFactory

I am using following function to get reviews collection based on product entity ids and my requirement is get only 50 reviews from all the available reviews.

public function getReviewsCollection(){
  
  $collection = $this->_reviewFactory->create();

  if (null === $this->_reviewsCollection) {
     $entity_ids = [];
     foreach ($this->getProductCollection() as $product) {
        $entity_ids[] = $product->getId();
     }
           $this->_reviewsCollection =  $collection->addFieldToSelect('*')
              ->addStoreFilter(
                 $this->_storeManager->getStore()->getId()
              )
              ->addStatusFilter(
                 MagentoReviewModelReview::STATUS_APPROVED
              )
              ->addFieldToFilter('main_table.entity_pk_value', ['in' => $entity_ids])
              ->addRateVotes()
              ->setPageSize(50)
              ->setCurPage(1);
  }
  return $this->_reviewsCollection;

}

->setPageSize(50)->setCurPage(1) is not working for my collection.

i also tried following way

$this->_reviewsCollection->getSelect()->limit(50);

and when i printed this query using __toString(); method, the query displays the limitation properly but somehow its not still applying on the collection when i test it on frontend and entire collection shown.