1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2025 Adobe
4
+ * All Rights Reserved .
5
5
*/
6
+ declare (strict_types=1 );
7
+
6
8
namespace Magento \Review \Controller ;
7
9
10
+ use Magento \Catalog \Api \CategoryRepositoryInterface ;
11
+ use Magento \Catalog \Api \ProductRepositoryInterface ;
12
+ use Magento \Catalog \Model \Design ;
8
13
use Magento \Catalog \Model \Product as CatalogProduct ;
14
+ use Magento \Customer \Model \Session ;
15
+ use Magento \Customer \Model \Url ;
16
+ use Magento \Framework \App \Action \Action ;
17
+ use Magento \Framework \App \Action \Context ;
18
+ use Magento \Framework \App \ObjectManager ;
19
+ use Magento \Framework \Registry ;
9
20
use Magento \Framework \App \RequestInterface ;
21
+ use Magento \Framework \Data \Form \FormKey \Validator ;
22
+ use Magento \Framework \Exception \LocalizedException ;
10
23
use Magento \Framework \Exception \NoSuchEntityException ;
24
+ use Magento \Framework \Session \Generic ;
25
+ use Magento \Review \Helper \Data ;
26
+ use Magento \Review \Model \RatingFactory ;
11
27
use Magento \Review \Model \Review ;
28
+ use Magento \Review \Model \Review \Config as ReviewsConfig ;
29
+ use Magento \Review \Model \ReviewFactory ;
30
+ use Magento \Store \Model \StoreManagerInterface ;
31
+ use Psr \Log \LoggerInterface ;
12
32
13
33
/**
14
34
* Review controller
15
35
*
16
36
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
17
37
*/
18
- abstract class Product extends \ Magento \ Framework \ App \ Action \ Action
38
+ abstract class Product extends Action
19
39
{
20
40
/**
21
- * Core registry
41
+ * Core Registry class
22
42
*
23
- * @var \Magento\Framework\ Registry
43
+ * @var Registry
24
44
*/
25
45
protected $ coreRegistry = null ;
26
46
27
47
/**
28
48
* Customer session model
29
49
*
30
- * @var \Magento\Customer\Model\ Session
50
+ * @var Session
31
51
*/
32
52
protected $ customerSession ;
33
53
34
54
/**
35
55
* Generic session
36
56
*
37
- * @var \Magento\Framework\Session\ Generic
57
+ * @var Generic
38
58
*/
39
59
protected $ reviewSession ;
40
60
41
61
/**
42
62
* Catalog category model
43
63
*
44
- * @var \Magento\Catalog\Api\ CategoryRepositoryInterface
64
+ * @var CategoryRepositoryInterface
45
65
*/
46
66
protected $ categoryRepository ;
47
67
48
68
/**
49
- * Logger
69
+ * Logger for adding logs
50
70
*
51
- * @var \Psr\Log\ LoggerInterface
71
+ * @var LoggerInterface
52
72
*/
53
73
protected $ logger ;
54
74
55
75
/**
56
76
* Catalog product model
57
77
*
58
- * @var \Magento\Catalog\Api\ ProductRepositoryInterface
78
+ * @var ProductRepositoryInterface
59
79
*/
60
80
protected $ productRepository ;
61
81
62
82
/**
63
83
* Review model
64
84
*
65
- * @var \Magento\Review\Model\ ReviewFactory
85
+ * @var ReviewFactory
66
86
*/
67
87
protected $ reviewFactory ;
68
88
69
89
/**
70
90
* Rating model
71
91
*
72
- * @var \Magento\Review\Model\ RatingFactory
92
+ * @var RatingFactory
73
93
*/
74
94
protected $ ratingFactory ;
75
95
76
96
/**
77
97
* Catalog design model
78
98
*
79
- * @var \Magento\Catalog\Model\ Design
99
+ * @var Design
80
100
*/
81
101
protected $ catalogDesign ;
82
102
83
103
/**
84
104
* Core model store manager interface
85
105
*
86
- * @var \Magento\Store\Model\ StoreManagerInterface
106
+ * @var StoreManagerInterface
87
107
*/
88
108
protected $ storeManager ;
89
109
90
110
/**
91
111
* Core form key validator
92
112
*
93
- * @var \Magento\Framework\Data\Form\FormKey\ Validator
113
+ * @var Validator
94
114
*/
95
115
protected $ formKeyValidator ;
96
116
97
117
/**
98
- * @param \Magento\Framework\App\Action\Context $context
99
- * @param \Magento\Framework\Registry $coreRegistry
100
- * @param \Magento\Customer\Model\Session $customerSession
101
- * @param \Magento\Catalog\Api\CategoryRepositoryInterface $categoryRepository
102
- * @param \Psr\Log\LoggerInterface $logger
103
- * @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
104
- * @param \Magento\Review\Model\ReviewFactory $reviewFactory
105
- * @param \Magento\Review\Model\RatingFactory $ratingFactory
106
- * @param \Magento\Catalog\Model\Design $catalogDesign
107
- * @param \Magento\Framework\Session\Generic $reviewSession
108
- * @param \Magento\Store\Model\StoreManagerInterface $storeManager
109
- * @param \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator
118
+ * Review config
119
+ *
120
+ * @var ReviewsConfig
121
+ */
122
+ protected $ reviewsConfig ;
123
+
124
+ /**
125
+ * @param Context $context
126
+ * @param Registry $coreRegistry
127
+ * @param Session $customerSession
128
+ * @param CategoryRepositoryInterface $categoryRepository
129
+ * @param LoggerInterface $logger
130
+ * @param ProductRepositoryInterface $productRepository
131
+ * @param ReviewFactory $reviewFactory
132
+ * @param RatingFactory $ratingFactory
133
+ * @param Design $catalogDesign
134
+ * @param Generic $reviewSession
135
+ * @param StoreManagerInterface $storeManager
136
+ * @param Validator $formKeyValidator
137
+ * @param ReviewsConfig $reviewsConfig
110
138
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
111
139
*/
112
140
public function __construct (
113
- \Magento \Framework \App \Action \Context $ context ,
114
- \Magento \Framework \Registry $ coreRegistry ,
115
- \Magento \Customer \Model \Session $ customerSession ,
116
- \Magento \Catalog \Api \CategoryRepositoryInterface $ categoryRepository ,
117
- \Psr \Log \LoggerInterface $ logger ,
118
- \Magento \Catalog \Api \ProductRepositoryInterface $ productRepository ,
119
- \Magento \Review \Model \ReviewFactory $ reviewFactory ,
120
- \Magento \Review \Model \RatingFactory $ ratingFactory ,
121
- \Magento \Catalog \Model \Design $ catalogDesign ,
122
- \Magento \Framework \Session \Generic $ reviewSession ,
123
- \Magento \Store \Model \StoreManagerInterface $ storeManager ,
124
- \Magento \Framework \Data \Form \FormKey \Validator $ formKeyValidator
141
+ Context $ context ,
142
+ Registry $ coreRegistry ,
143
+ Session $ customerSession ,
144
+ CategoryRepositoryInterface $ categoryRepository ,
145
+ LoggerInterface $ logger ,
146
+ ProductRepositoryInterface $ productRepository ,
147
+ ReviewFactory $ reviewFactory ,
148
+ RatingFactory $ ratingFactory ,
149
+ Design $ catalogDesign ,
150
+ Generic $ reviewSession ,
151
+ StoreManagerInterface $ storeManager ,
152
+ Validator $ formKeyValidator ,
153
+ ?ReviewsConfig $ reviewsConfig = null
125
154
) {
126
155
$ this ->storeManager = $ storeManager ;
127
156
$ this ->coreRegistry = $ coreRegistry ;
@@ -134,7 +163,7 @@ public function __construct(
134
163
$ this ->ratingFactory = $ ratingFactory ;
135
164
$ this ->catalogDesign = $ catalogDesign ;
136
165
$ this ->formKeyValidator = $ formKeyValidator ;
137
-
166
+ $ this -> reviewsConfig = $ reviewsConfig ?: ObjectManager:: getInstance ()-> get (ReviewsConfig::class);
138
167
parent ::__construct ($ context );
139
168
}
140
169
@@ -146,7 +175,7 @@ public function __construct(
146
175
*/
147
176
public function dispatch (RequestInterface $ request )
148
177
{
149
- $ allowGuest = $ this ->_objectManager ->get (\ Magento \ Review \ Helper \ Data::class)->getIsGuestAllowToWrite ();
178
+ $ allowGuest = $ this ->_objectManager ->get (Data::class)->getIsGuestAllowToWrite ();
150
179
if (!$ request ->isDispatched ()) {
151
180
return parent ::dispatch ($ request );
152
181
}
@@ -161,7 +190,7 @@ public function dispatch(RequestInterface $request)
161
190
$ this ->_redirect ->getRefererUrl ()
162
191
);
163
192
$ this ->getResponse ()->setRedirect (
164
- $ this ->_objectManager ->get (\ Magento \ Customer \ Model \ Url::class)->getLoginUrl ()
193
+ $ this ->_objectManager ->get (Url::class)->getLoginUrl ()
165
194
);
166
195
}
167
196
}
@@ -196,7 +225,7 @@ protected function initProduct()
196
225
'review_controller_product_init_after ' ,
197
226
['product ' => $ product , 'controller_action ' => $ this ]
198
227
);
199
- } catch (\ Magento \ Framework \ Exception \ LocalizedException $ e ) {
228
+ } catch (LocalizedException $ e ) {
200
229
$ this ->logger ->critical ($ e );
201
230
return false ;
202
231
}
@@ -205,8 +234,7 @@ protected function initProduct()
205
234
}
206
235
207
236
/**
208
- * Load product model with data by passed id.
209
- * Return false if product was not loaded or has incorrect status.
237
+ * Load product model with data by passed id. Return false if product was not loaded or has incorrect status.
210
238
*
211
239
* @param int $productId
212
240
* @return bool|CatalogProduct
@@ -216,16 +244,13 @@ protected function loadProduct($productId)
216
244
if (!$ productId ) {
217
245
return false ;
218
246
}
219
-
220
247
try {
221
248
$ product = $ this ->productRepository ->getById ($ productId );
222
249
223
- if (!in_array ($ this ->storeManager ->getStore ()->getWebsiteId (), $ product ->getWebsiteIds ())) {
224
- throw new NoSuchEntityException ();
225
- }
226
-
227
- if (!$ product ->isVisibleInCatalog () || !$ product ->isVisibleInSiteVisibility ()) {
228
- throw new NoSuchEntityException ();
250
+ if ((!in_array ($ this ->storeManager ->getStore ()->getWebsiteId (), $ product ->getWebsiteIds ()))
251
+ || (!$ product ->isVisibleInCatalog () || !$ product ->isVisibleInSiteVisibility ())
252
+ ) {
253
+ return false ;
229
254
}
230
255
} catch (NoSuchEntityException $ noEntityException ) {
231
256
return false ;
0 commit comments