Skip to content

Commit

Permalink
Added try to cover case when root category doesnt exists
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel Galvao da Gama committed Jul 17, 2020
1 parent 193765d commit 095dcc6
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Magento\Catalog\Api\CategoryRepositoryInterface;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\MediaContentApi\Model\GetAssetIdsByContentFieldInterface;
use Magento\Store\Api\GroupRepositoryInterface;
use Magento\Store\Api\StoreRepositoryInterface;
Expand Down Expand Up @@ -70,9 +71,13 @@ public function __construct(
*/
public function execute(string $value): array
{
$storeView = $this->storeRepository->getById($value);
$storeGroup = $this->storeGroupRepository->get($storeView->getStoreGroupId());
$rootCategory = $this->categoryRepository->get($storeGroup->getRootCategoryId());
try {
$storeView = $this->storeRepository->getById($value);
$storeGroup = $this->storeGroupRepository->get($storeView->getStoreGroupId());
$rootCategory = $this->categoryRepository->get($storeGroup->getRootCategoryId());
} catch (NoSuchEntityException $exception) {
return [];
}

$sql = $this->connection->getConnection()->select()->from(
['asset_content_table' => $this->connection->getTableName(self::TABLE_CONTENT_ASSET)],
Expand Down

0 comments on commit 095dcc6

Please sign in to comment.