Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 8ab8fa0

Browse files
author
Stanislav Idolov
authored
ENGCOM-1234: [Forwardport] Fix issue #13010. Check if product is assigned to current website. #14528
2 parents 580d650 + cf29f43 commit 8ab8fa0

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,11 @@ protected function loadProduct($productId)
219219

220220
try {
221221
$product = $this->productRepository->getById($productId);
222+
223+
if (!in_array($this->storeManager->getStore()->getWebsiteId(), $product->getWebsiteIds())) {
224+
throw new NoSuchEntityException();
225+
}
226+
222227
if (!$product->isVisibleInCatalog() || !$product->isVisibleInSiteVisibility()) {
223228
throw new NoSuchEntityException();
224229
}

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,11 @@ protected function setUp()
147147
$ratingFactory->expects($this->once())->method('create')->willReturn($this->rating);
148148
$this->messageManager = $this->createMock(\Magento\Framework\Message\ManagerInterface::class);
149149

150-
$this->store = $this->createPartialMock(\Magento\Store\Model\Store::class, ['getId']);
150+
$this->store = $this->createPartialMock(
151+
\Magento\Store\Model\Store::class,
152+
['getId', 'getWebsiteId']
153+
);
154+
151155
$storeManager = $this->getMockForAbstractClass(\Magento\Store\Model\StoreManagerInterface::class);
152156
$storeManager->expects($this->any())->method('getStore')->willReturn($this->store);
153157

@@ -219,14 +223,23 @@ public function testExecute()
219223
->willReturn(1);
220224
$product = $this->createPartialMock(
221225
\Magento\Catalog\Model\Product::class,
222-
['__wakeup', 'isVisibleInCatalog', 'isVisibleInSiteVisibility', 'getId']
226+
['__wakeup', 'isVisibleInCatalog', 'isVisibleInSiteVisibility', 'getId', 'getWebsiteIds']
223227
);
224228
$product->expects($this->once())
225229
->method('isVisibleInCatalog')
226230
->willReturn(true);
227231
$product->expects($this->once())
228232
->method('isVisibleInSiteVisibility')
229233
->willReturn(true);
234+
235+
$product->expects($this->once())
236+
->method('getWebsiteIds')
237+
->willReturn([1]);
238+
239+
$this->store->expects($this->once())
240+
->method('getWebsiteId')
241+
->willReturn(1);
242+
230243
$this->productRepository->expects($this->any())->method('getById')
231244
->with(1)
232245
->willReturn($product);

0 commit comments

Comments
 (0)