Skip to content

Commit

Permalink
Merge pull request #24 from matesich/master
Browse files Browse the repository at this point in the history
added page validation
  • Loading branch information
AleksandrsKondratjevs authored Jan 11, 2023
2 parents 51308e4 + 7b5d4bc commit c764fad
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 c764fad

Please sign in to comment.