*/ class Detailed extends \Magento\Framework\View\Element\Template { /** * @var string */ protected $_template = 'Magento_Review::detailed.phtml'; /** * @var \Magento\Review\Model\RatingFactory */ protected $_ratingFactory; /** * @param \Magento\Framework\View\Element\Template\Context $context * @param \Magento\Review\Model\RatingFactory $ratingFactory * @param array $data */ public function __construct( \Magento\Framework\View\Element\Template\Context $context, \Magento\Review\Model\RatingFactory $ratingFactory, array $data = [] ) { $this->_ratingFactory = $ratingFactory; parent::__construct($context, $data); } /** * Returns block html * * @return string */ protected function _toHtml() { $entityId = $this->_request->getParam('id'); if ((int)$entityId <= 0) { return ''; } $reviewsCount = $this->_ratingFactory->create()->getTotalReviews($entityId, true); if ($reviewsCount == 0) { #return __('Be the first to review this product'); $this->setTemplate('Magento_Review::empty.phtml'); return parent::_toHtml(); } $ratingCollection = $this->_ratingFactory->create()->getResourceCollection()->addEntityFilter( 'product' # TOFIX )->setPositionOrder()->setStoreFilter( $this->_storeManager->getStore()->getId() )->addRatingPerStoreName( $this->_storeManager->getStore()->getId() )->load(); if ($entityId) { $ratingCollection->addEntitySummaryToItem($entityId, $this->_storeManager->getStore()->getId()); } $this->assign('collection', $ratingCollection); return parent::_toHtml(); } }