Skip to content

Commit dbf52ee

Browse files
committed
AC-13672: Product reviews modification
1 parent 3459ebf commit dbf52ee

File tree

3 files changed

+29
-21
lines changed

3 files changed

+29
-21
lines changed

app/code/Magento/Review/Controller/Product.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<?php
2-
3-
declare(strict_types=1);
4-
52
/**
6-
* Copyright © Magento, Inc. All rights reserved.
7-
* See COPYING.txt for license details.
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
85
*/
6+
declare(strict_types=1);
7+
98
namespace Magento\Review\Controller;
109

1110
use Magento\Catalog\Api\CategoryRepositoryInterface;
@@ -245,16 +244,13 @@ protected function loadProduct($productId)
245244
if (!$productId) {
246245
return false;
247246
}
248-
249247
try {
250248
$product = $this->productRepository->getById($productId);
251249

252-
if (!in_array($this->storeManager->getStore()->getWebsiteId(), $product->getWebsiteIds())) {
253-
throw new NoSuchEntityException();
254-
}
255-
256-
if (!$product->isVisibleInCatalog() || !$product->isVisibleInSiteVisibility()) {
257-
throw new NoSuchEntityException();
250+
if ((!in_array($this->storeManager->getStore()->getWebsiteId(), $product->getWebsiteIds()))
251+
|| (!$product->isVisibleInCatalog() || !$product->isVisibleInSiteVisibility())
252+
) {
253+
return false;
258254
}
259255
} catch (NoSuchEntityException $noEntityException) {
260256
return false;

app/code/Magento/Review/Controller/Product/Post.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<?php
2-
3-
declare(strict_types=1);
4-
52
/**
6-
* Copyright © Magento, Inc. All rights reserved.
7-
* See COPYING.txt for license details.
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
85
*/
6+
declare(strict_types=1);
7+
98
namespace Magento\Review\Controller\Product;
109

1110
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
@@ -29,7 +28,7 @@ public function execute()
2928
{
3029
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
3130
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
32-
if (false === $this->reviewsConfig->isEnabled() || !$this->formKeyValidator->validate($this->getRequest())) {
31+
if (!$this->formKeyValidator->validate($this->getRequest()) || false === $this->reviewsConfig->isEnabled()) {
3332
$resultRedirect->setUrl($this->_redirect->getRefererUrl());
3433
return $resultRedirect;
3534
}

app/code/Magento/Review/Test/Unit/Controller/Product/PostTest.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -25,6 +25,7 @@
2525
use Magento\Review\Model\RatingFactory;
2626
use Magento\Review\Model\Review;
2727
use Magento\Review\Model\ReviewFactory;
28+
use Magento\Review\Model\Review\Config;
2829
use Magento\Store\Model\Store;
2930
use Magento\Store\Model\StoreManagerInterface;
3031
use PHPUnit\Framework\MockObject\MockObject;
@@ -121,6 +122,11 @@ class PostTest extends TestCase
121122
*/
122123
protected $resultRedirectMock;
123124

125+
/**
126+
* @var Config|MockObject
127+
*/
128+
protected $reviewsConfig;
129+
124130
/**
125131
* @inheritDoc
126132
*
@@ -135,6 +141,10 @@ protected function setUp(): void
135141
Validator::class,
136142
['validate']
137143
);
144+
$this->reviewsConfig = $this->createPartialMock(
145+
Config::class,
146+
['isEnabled']
147+
);
138148
$this->reviewSession = $this->getMockBuilder(Generic::class)
139149
->addMethods(['getFormData', 'getRedirectUrl'])
140150
->disableOriginalConstructor()
@@ -211,7 +221,8 @@ protected function setUp(): void
211221
'customerSession' => $this->customerSession,
212222
'ratingFactory' => $ratingFactory,
213223
'storeManager' => $storeManager,
214-
'context' => $this->context
224+
'context' => $this->context,
225+
'reviewsConfig' => $this->reviewsConfig
215226
]
216227
);
217228
}
@@ -234,6 +245,8 @@ public function testExecute(): void
234245
$this->formKeyValidator->expects($this->any())->method('validate')
235246
->with($this->request)
236247
->willReturn(true);
248+
$this->reviewsConfig->expects($this->any())->method('isEnabled')
249+
->willReturn(true);
237250
$this->reviewSession->expects($this->any())->method('getFormData')
238251
->with(true)
239252
->willReturn($reviewData);

0 commit comments

Comments
 (0)