Get review details data by review id Magento 2 using ReviewFactory.
Product Review has given by the Customer in the Product details page and wants to retrieve specific review details by the id using Magento\Review\Model\ReviewFactory.
The output is the review data like review id, create date, store id, title, detail, nickname and customer id.
<?php namespace Jesadiya\Review\Model; use Magento\Review\Model\Review; use Magento\Review\Model\ReviewFactory; use Magento\Framework\Exception\LocalizedException; class Review { /** * @var ReviewFactory */ private $reviewFactory; public function __construct( ReviewFactory $reviewFactory ) { $this->reviewFactory = $reviewFactory; } /** * Review Data * * @return Review */ public function getReviewData() { $reviewId = 1; try { $review = $this->reviewFactory->create()->load($reviewId); } catch (LocalizedException $exception) { throw new LocalizedException(__($exception->getMessage())); } return $review; } }
Call from the template or PHP class,
echo $reviewData = $this->getReviewData();
Output:
Magento\Review\Model\Review
Array ( [review_id] => 1 [created_at] => 2019-10-17 09:34:24 [entity_id] => 1 [entity_pk_value] => 1 [status_id] => 1 [detail_id] => 1 [store_id] => 1 [title] => I prefer more compartments [detail] => I prefer more compartments. If you don't mind putting everything in one space, it's fine. Good for the gym. [nickname] => Chi [customer_id] => [stores] => Array ( [0] => 0 [1] => 1 ) )