1
1
<?php
2
2
/**
3
- * Review renderer
4
- *
5
3
* Copyright © Magento, Inc. All rights reserved.
6
4
* See COPYING.txt for license details.
7
5
*/
11
9
use Magento \Catalog \Block \Product \ReviewRendererInterface ;
12
10
use Magento \Catalog \Model \Product ;
13
11
use Magento \Framework \App \ObjectManager ;
12
+ use Magento \Framework \Exception \LocalizedException ;
13
+ use Magento \Framework \Exception \NoSuchEntityException ;
14
+ use Magento \Framework \View \Element \Template ;
15
+ use Magento \Framework \View \Element \Template \Context ;
16
+ use Magento \Review \Model \AppendSummaryDataToObjectByEntityCodeFactory ;
17
+ use Magento \Review \Model \Review ;
18
+ use Magento \Review \Model \ReviewFactory ;
14
19
use Magento \Review \Model \ReviewSummaryFactory ;
15
20
use Magento \Review \Observer \PredispatchReviewObserver ;
21
+ use Magento \Store \Model \ScopeInterface ;
16
22
17
23
/**
18
- * Class ReviewRenderer
24
+ * Review renderer
19
25
*/
20
- class ReviewRenderer extends \ Magento \ Framework \ View \ Element \ Template implements ReviewRendererInterface
26
+ class ReviewRenderer extends Template implements ReviewRendererInterface
21
27
{
22
28
/**
23
29
* Array of available template name
@@ -32,7 +38,7 @@ class ReviewRenderer extends \Magento\Framework\View\Element\Template implements
32
38
/**
33
39
* Review model factory
34
40
*
35
- * @var \Magento\Review\Model\ ReviewFactory
41
+ * @var ReviewFactory
36
42
*/
37
43
protected $ _reviewFactory ;
38
44
@@ -42,20 +48,29 @@ class ReviewRenderer extends \Magento\Framework\View\Element\Template implements
42
48
private $ reviewSummaryFactory ;
43
49
44
50
/**
45
- * @param \Magento\Framework\View\Element\Template\Context $context
46
- * @param \Magento\Review\Model\ReviewFactory $reviewFactory
51
+ * @var AppendSummaryDataToObjectByEntityCodeFactory
52
+ */
53
+ private $ appendSummaryDataToObjectByEntityCodeFactory ;
54
+
55
+ /**
56
+ * @param Context $context
57
+ * @param ReviewFactory $reviewFactory
47
58
* @param array $data
48
- * @param ReviewSummaryFactory $reviewSummaryFactory
59
+ * @param ReviewSummaryFactory|null $reviewSummaryFactory
60
+ * @param AppendSummaryDataToObjectByEntityCodeFactory|null $appendSummaryDataToObjectByEntityCodeFactory
49
61
*/
50
62
public function __construct (
51
- \ Magento \ Framework \ View \ Element \ Template \ Context $ context ,
52
- \ Magento \ Review \ Model \ ReviewFactory $ reviewFactory ,
63
+ Context $ context ,
64
+ ReviewFactory $ reviewFactory ,
53
65
array $ data = [],
54
- ReviewSummaryFactory $ reviewSummaryFactory = null
66
+ ReviewSummaryFactory $ reviewSummaryFactory = null ,
67
+ AppendSummaryDataToObjectByEntityCodeFactory $ appendSummaryDataToObjectByEntityCodeFactory = null
55
68
) {
56
69
$ this ->_reviewFactory = $ reviewFactory ;
57
70
$ this ->reviewSummaryFactory = $ reviewSummaryFactory ??
58
71
ObjectManager::getInstance ()->get (ReviewSummaryFactory::class);
72
+ $ this ->appendSummaryDataToObjectByEntityCodeFactory = $ appendSummaryDataToObjectByEntityCodeFactory ??
73
+ ObjectManager::getInstance ()->get (AppendSummaryDataToObjectByEntityCodeFactory::class);
59
74
parent ::__construct ($ context , $ data );
60
75
}
61
76
@@ -68,7 +83,7 @@ public function isReviewEnabled(): string
68
83
{
69
84
return $ this ->_scopeConfig ->getValue (
70
85
PredispatchReviewObserver::XML_PATH_REVIEW_ACTIVE ,
71
- \ Magento \ Store \ Model \ ScopeInterface::SCOPE_STORE
86
+ ScopeInterface::SCOPE_STORE
72
87
);
73
88
}
74
89
@@ -80,19 +95,21 @@ public function isReviewEnabled(): string
80
95
* @param bool $displayIfNoReviews
81
96
*
82
97
* @return string
83
- * @throws \Magento\Framework\Exception\ LocalizedException
84
- * @throws \Magento\Framework\Exception\ NoSuchEntityException
98
+ * @throws LocalizedException
99
+ * @throws NoSuchEntityException
85
100
*/
86
101
public function getReviewsSummaryHtml (
87
- \ Magento \ Catalog \ Model \ Product $ product ,
102
+ Product $ product ,
88
103
$ templateType = self ::DEFAULT_VIEW ,
89
104
$ displayIfNoReviews = false
90
105
) {
91
106
if ($ product ->getRatingSummary () === null ) {
92
- $ this ->reviewSummaryFactory ->create ()->appendSummaryDataToObject (
93
- $ product ,
94
- $ this ->_storeManager ->getStore ()->getId ()
95
- );
107
+ $ this ->appendSummaryDataToObjectByEntityCodeFactory ->create ()
108
+ ->execute (
109
+ $ product ,
110
+ $ this ->_storeManager ->getStore ()->getId (),
111
+ Review::ENTITY_PRODUCT_CODE
112
+ );
96
113
}
97
114
98
115
if (null === $ product ->getRatingSummary () && !$ displayIfNoReviews ) {
0 commit comments