Skip to content

Commit

Permalink
added page validation
Browse files Browse the repository at this point in the history
  • Loading branch information
matesich committed Jan 11, 2023
1 parent e16fa31 commit 7b5d4bc
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/Controller/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
use Magento\Cms\Model\PageFactory;
use Magento\Catalog\Model\ProductRepository;
use Magento\Catalog\Api\CategoryRepositoryInterface;

use Magento\Catalog\Model\Product\Attribute\Source\Status;
class Router extends BaseRouter
{
const XML_PATH_CMS_HOME_PAGE = 'web/default/cms_home_page';
Expand Down Expand Up @@ -294,6 +294,11 @@ protected function setResponseCmsPage($id, ActionInterface $action)
->setStoreId($this->storeId)
->load($id);

if (!$page->getId() || !$page->isActive()) {
$this->setNotFound($action);
return;
}

$action->setId($page->getId() ?? '');
$action->setIdentifier($page->getIdentifier() ?? '');
}
Expand All @@ -311,6 +316,11 @@ protected function setResponseProduct($id, ActionInterface $action)
try {
$product = $this->productRepository->getById($id, false, $this->storeId);

if (!$product->getId() || $product->getStatus() != Status::STATUS_ENABLED) {
$this->setNotFound($action);
return;
}

$action->setId($product->getId() ?? '');
$action->setSku($product->getSku() ?? '');
$action->setName($product->getName() ?? '');
Expand All @@ -332,6 +342,11 @@ protected function setResponseCategory($id, ActionInterface $action)
try {
$category = $this->categoryRepository->get($id, $this->storeId);

if (!$category->getIsActive()) {
$this->setNotFound($action);
return;
}

$action->setId($category->getId() ?? '');
$action->setName($category->getName() ?? '');
$action->setDescription($category->getDescription() ?? '');
Expand Down

0 comments on commit 7b5d4bc

Please sign in to comment.