Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Detailed.php
Go to the documentation of this file.
1 <?php
7 
14 {
18  protected $_template = 'Magento_Review::detailed.phtml';
19 
23  protected $_ratingFactory;
24 
30  public function __construct(
31  \Magento\Framework\View\Element\Template\Context $context,
32  \Magento\Review\Model\RatingFactory $ratingFactory,
33  array $data = []
34  ) {
35  $this->_ratingFactory = $ratingFactory;
36  parent::__construct($context, $data);
37  }
38 
42  protected function _toHtml()
43  {
44  $entityId = $this->_request->getParam('id');
45  if (intval($entityId) <= 0) {
46  return '';
47  }
48 
49  $reviewsCount = $this->_ratingFactory->create()->getTotalReviews($entityId, true);
50  if ($reviewsCount == 0) {
51  #return __('Be the first to review this product');
52  $this->setTemplate('Magento_Review::empty.phtml');
53  return parent::_toHtml();
54  }
55 
56  $ratingCollection = $this->_ratingFactory->create()->getResourceCollection()->addEntityFilter(
57  'product' # TOFIX
58  )->setPositionOrder()->setStoreFilter(
59  $this->_storeManager->getStore()->getId()
60  )->addRatingPerStoreName(
61  $this->_storeManager->getStore()->getId()
62  )->load();
63 
64  if ($entityId) {
65  $ratingCollection->addEntitySummaryToItem($entityId, $this->_storeManager->getStore()->getId());
66  }
67 
68  $this->assign('collection', $ratingCollection);
69  return parent::_toHtml();
70  }
71 }
__construct(\Magento\Framework\View\Element\Template\Context $context, \Magento\Review\Model\RatingFactory $ratingFactory, array $data=[])
Definition: Detailed.php:30