Skip to content

Commit 11fb821

Browse files
committed
Fix issue magento#13010. Check if product is assigned to current website.
1 parent 85ee370 commit 11fb821

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-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: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,13 @@ protected function setUp()
170170
$ratingFactory->expects($this->once())->method('create')->willReturn($this->rating);
171171
$this->messageManager = $this->getMock('\Magento\Framework\Message\ManagerInterface');
172172

173-
$this->store = $this->getMock('\Magento\Store\Model\Store', ['getId'], [], '', false);
173+
$this->store = $this->getMock(
174+
'\Magento\Store\Model\Store',
175+
['getId', 'getWebsiteId'],
176+
[],
177+
'',
178+
false
179+
);
174180
$storeManager = $this->getMockForAbstractClass('\Magento\Store\Model\StoreManagerInterface');
175181
$storeManager->expects($this->any())->method('getStore')->willReturn($this->store);
176182

@@ -242,7 +248,7 @@ public function testExecute()
242248
->willReturn(1);
243249
$product = $this->getMock(
244250
'Magento\Catalog\Model\Product',
245-
['__wakeup', 'isVisibleInCatalog', 'isVisibleInSiteVisibility', 'getId'],
251+
['__wakeup', 'isVisibleInCatalog', 'isVisibleInSiteVisibility', 'getId', 'getWebsiteIds'],
246252
[],
247253
'',
248254
false
@@ -253,6 +259,10 @@ public function testExecute()
253259
$product->expects($this->once())
254260
->method('isVisibleInSiteVisibility')
255261
->willReturn(true);
262+
$product->expects($this->once())
263+
->method('getWebsiteIds')
264+
->willReturn([1]);
265+
256266
$this->productRepository->expects($this->any())->method('getById')
257267
->with(1)
258268
->willReturn($product);
@@ -288,6 +298,8 @@ public function testExecute()
288298
$this->review->expects($this->once())->method('setCustomerId')->with($customerId)->willReturnSelf();
289299
$this->store->expects($this->exactly(2))->method('getId')
290300
->willReturn($storeId);
301+
$this->store->expects($this->once())->method('getWebsiteId')
302+
->willReturn(1);
291303
$this->review->expects($this->once())->method('setStoreId')
292304
->with($storeId)
293305
->willReturnSelf();

0 commit comments

Comments
 (0)