From acc10a7ee47de5b441f3e6d9b6c280d71d893c47 Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Tue, 24 Sep 2024 12:55:47 +0200 Subject: [PATCH] fix: show 404 when page is not active for store (#94) fix: show 404 when page is not active for store --- src/Controller/LandingPage/View.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Controller/LandingPage/View.php b/src/Controller/LandingPage/View.php index 9405053..316fe4e 100644 --- a/src/Controller/LandingPage/View.php +++ b/src/Controller/LandingPage/View.php @@ -18,6 +18,7 @@ use Magento\Framework\Exception\NotFoundException; use Magento\Framework\Registry; use Magento\Framework\View\Result\PageFactory; +use Magento\Store\Model\StoreManagerInterface; class View extends Action { @@ -69,7 +70,8 @@ public function __construct( Registry $registry, LandingPageRepositoryInterface $landingPageRepository, CategoryRepositoryInterface $categoryRepository, - FilterApplierInterface $filterApplier + FilterApplierInterface $filterApplier, + private readonly StoreManagerInterface $storeManager ) { $this->resultPageFactory = $resultPageFactory; $this->coreRegistry = $registry; @@ -97,6 +99,13 @@ public function execute(): ResultInterface throw new NotFoundException(__('Page not active')); } + $storeId = $this->storeManager->getStore()->getId(); + $landingPageStoreIds = $landingPage->getStoreIds(); + + if ((!in_array($storeId, $landingPage->getStoreIds())) && (!in_array(0, $landingPage->getStoreIds()))) { + throw new NotFoundException(__('Page not active for this store')); + } + $this->landingPageContext->setLandingPage($landingPage); $this->setCategoryInRegistry($landingPage); $this->filterApplier->applyFilters($landingPage);