Skip to content

Commit

Permalink
Return null if category is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandrsKondratjevs committed Jan 4, 2021
1 parent 3cb9f1a commit 0f01392
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/Model/Resolver/EntityUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Magento\UrlRewrite\Model\UrlFinderInterface;
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite;
use Magento\UrlRewriteGraphQl\Model\Resolver\UrlRewrite\CustomUrlLocatorInterface;
use Magento\Catalog\Api\CategoryRepositoryInterface;

/**
* UrlRewrite field resolver, used for GraphQL request processing.
Expand All @@ -47,22 +48,30 @@ class EntityUrl implements ResolverInterface
*/
private $productCollectionFactory;

/**
* @var CategoryRepositoryInterface
*/
private $categoryRepository;

/**
* @param UrlFinderInterface $urlFinder
* @param StoreManagerInterface $storeManager
* @param CustomUrlLocatorInterface $customUrlLocator
* @param CollectionFactory $productCollectionFactory
* @param CategoryRepositoryInterface $categoryRepository
*/
public function __construct(
UrlFinderInterface $urlFinder,
StoreManagerInterface $storeManager,
CustomUrlLocatorInterface $customUrlLocator,
CollectionFactory $productCollectionFactory
CollectionFactory $productCollectionFactory,
CategoryRepositoryInterface $categoryRepository
) {
$this->urlFinder = $urlFinder;
$this->storeManager = $storeManager;
$this->customUrlLocator = $customUrlLocator;
$this->productCollectionFactory = $productCollectionFactory;
$this->categoryRepository = $categoryRepository;
}

/**
Expand Down Expand Up @@ -110,6 +119,13 @@ public function resolve(
}

$result['sku'] = $product->getSku();
} elseif ($type === 'CATEGORY') {
$storeId = $this->storeManager->getStore()->getId();
$category = $this->categoryRepository->get($id, $storeId);

if (!$category->getIsActive()) {
return null;
}
}
}

Expand Down

0 comments on commit 0f01392

Please sign in to comment.