Skip to content

Commit 095dcc6

Browse files
author
Gabriel Galvao da Gama
committed
Added try to cover case when root category doesnt exists
1 parent 193765d commit 095dcc6

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

app/code/Magento/MediaContentCatalog/Model/ResourceModel/GetAssetIdsByCategoryStore.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Catalog\Api\CategoryRepositoryInterface;
1212
use Magento\Framework\App\ResourceConnection;
1313
use Magento\Framework\Exception\LocalizedException;
14+
use Magento\Framework\Exception\NoSuchEntityException;
1415
use Magento\MediaContentApi\Model\GetAssetIdsByContentFieldInterface;
1516
use Magento\Store\Api\GroupRepositoryInterface;
1617
use Magento\Store\Api\StoreRepositoryInterface;
@@ -70,9 +71,13 @@ public function __construct(
7071
*/
7172
public function execute(string $value): array
7273
{
73-
$storeView = $this->storeRepository->getById($value);
74-
$storeGroup = $this->storeGroupRepository->get($storeView->getStoreGroupId());
75-
$rootCategory = $this->categoryRepository->get($storeGroup->getRootCategoryId());
74+
try {
75+
$storeView = $this->storeRepository->getById($value);
76+
$storeGroup = $this->storeGroupRepository->get($storeView->getStoreGroupId());
77+
$rootCategory = $this->categoryRepository->get($storeGroup->getRootCategoryId());
78+
} catch (NoSuchEntityException $exception) {
79+
return [];
80+
}
7681

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

0 commit comments

Comments
 (0)