diff --git a/app/code/Magento/Review/Controller/Product.php b/app/code/Magento/Review/Controller/Product.php index 4b8fa5fea92dd..1d2d0a78d8b0c 100644 --- a/app/code/Magento/Review/Controller/Product.php +++ b/app/code/Magento/Review/Controller/Product.php @@ -219,6 +219,11 @@ protected function loadProduct($productId) try { $product = $this->productRepository->getById($productId); + + if (!in_array($this->storeManager->getStore()->getWebsiteId(), $product->getWebsiteIds())) { + throw new NoSuchEntityException(); + } + if (!$product->isVisibleInCatalog() || !$product->isVisibleInSiteVisibility()) { throw new NoSuchEntityException(); } diff --git a/app/code/Magento/Review/Test/Unit/Controller/Product/PostTest.php b/app/code/Magento/Review/Test/Unit/Controller/Product/PostTest.php index e85fdb67c77b6..27902a6b40e65 100644 --- a/app/code/Magento/Review/Test/Unit/Controller/Product/PostTest.php +++ b/app/code/Magento/Review/Test/Unit/Controller/Product/PostTest.php @@ -170,7 +170,13 @@ protected function setUp() $ratingFactory->expects($this->once())->method('create')->willReturn($this->rating); $this->messageManager = $this->getMock('\Magento\Framework\Message\ManagerInterface'); - $this->store = $this->getMock('\Magento\Store\Model\Store', ['getId'], [], '', false); + $this->store = $this->getMock( + '\Magento\Store\Model\Store', + ['getId', 'getWebsiteId'], + [], + '', + false + ); $storeManager = $this->getMockForAbstractClass('\Magento\Store\Model\StoreManagerInterface'); $storeManager->expects($this->any())->method('getStore')->willReturn($this->store); @@ -242,7 +248,7 @@ public function testExecute() ->willReturn(1); $product = $this->getMock( 'Magento\Catalog\Model\Product', - ['__wakeup', 'isVisibleInCatalog', 'isVisibleInSiteVisibility', 'getId'], + ['__wakeup', 'isVisibleInCatalog', 'isVisibleInSiteVisibility', 'getId', 'getWebsiteIds'], [], '', false @@ -253,6 +259,10 @@ public function testExecute() $product->expects($this->once()) ->method('isVisibleInSiteVisibility') ->willReturn(true); + $product->expects($this->once()) + ->method('getWebsiteIds') + ->willReturn([1]); + $this->productRepository->expects($this->any())->method('getById') ->with(1) ->willReturn($product); @@ -288,6 +298,8 @@ public function testExecute() $this->review->expects($this->once())->method('setCustomerId')->with($customerId)->willReturnSelf(); $this->store->expects($this->exactly(2))->method('getId') ->willReturn($storeId); + $this->store->expects($this->once())->method('getWebsiteId') + ->willReturn(1); $this->review->expects($this->once())->method('setStoreId') ->with($storeId) ->willReturnSelf();