답변:
제품 ID를 사용하여이 새 메소드를 작성하고 호출하십시오. 또한 관리자에서 등급 옵션을 1 개만 활성화해야합니다.
public function getAllStart($pid) {
$review = $this->_objectReview->getCollection() //\Magento\Review\Model\Review $reviewFactory (_objectReview)
->addFieldToFilter('main_table.status_id', 1)
->addEntityFilter('product', $pid) //$pid = > your current product ID
->addStoreFilter($this->_storeManager->getStore()->getId())
->addFieldToSelect('review_id')
;
$review->getSelect()->columns('detail.detail_id')->joinInner(
['vote' => $review->getTable('rating_option_vote')], 'main_table.review_id = vote.review_id', array('review_value' => 'vote.value')
);
$review->getSelect()->order('review_value DESC');
$review->getSelect()->columns('count(vote.vote_id) as total_vote')->group('review_value');
for ($i = 5; $i >= 1; $i--) {
$arrRatings[$i]['value'] = 0;
}
foreach ($review as $_result) {
$arrRatings[$_result['review_value']]['value'] = $_result['total_vote'];
}
return $arrRatings;
}