diff --git a/app/code/Magento/Review/Controller/Product.php b/app/code/Magento/Review/Controller/Product.php index b90ad29aa49e7..a88fcb4193df0 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 3186c0fcc3c57..1526e80f8190a 100644 --- a/app/code/Magento/Review/Test/Unit/Controller/Product/PostTest.php +++ b/app/code/Magento/Review/Test/Unit/Controller/Product/PostTest.php @@ -147,7 +147,11 @@ protected function setUp() $ratingFactory->expects($this->once())->method('create')->willReturn($this->rating); $this->messageManager = $this->createMock(\Magento\Framework\Message\ManagerInterface::class); - $this->store = $this->createPartialMock(\Magento\Store\Model\Store::class, ['getId']); + $this->store = $this->createPartialMock( + \Magento\Store\Model\Store::class, + ['getId', 'getWebsiteId'] + ); + $storeManager = $this->getMockForAbstractClass(\Magento\Store\Model\StoreManagerInterface::class); $storeManager->expects($this->any())->method('getStore')->willReturn($this->store); @@ -219,7 +223,7 @@ public function testExecute() ->willReturn(1); $product = $this->createPartialMock( \Magento\Catalog\Model\Product::class, - ['__wakeup', 'isVisibleInCatalog', 'isVisibleInSiteVisibility', 'getId'] + ['__wakeup', 'isVisibleInCatalog', 'isVisibleInSiteVisibility', 'getId', 'getWebsiteIds'] ); $product->expects($this->once()) ->method('isVisibleInCatalog') @@ -227,6 +231,15 @@ public function testExecute() $product->expects($this->once()) ->method('isVisibleInSiteVisibility') ->willReturn(true); + + $product->expects($this->once()) + ->method('getWebsiteIds') + ->willReturn([1]); + + $this->store->expects($this->once()) + ->method('getWebsiteId') + ->willReturn(1); + $this->productRepository->expects($this->any())->method('getById') ->with(1) ->willReturn($product);