forked from magento/magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDetailed.php
More file actions
71 lines (63 loc) · 1.98 KB
/
Detailed.php
File metadata and controls
71 lines (63 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Review\Block\Rating\Entity;
/**
* Entity rating block
*/
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();
}
}