categoryNotFound example



    public function setCategory(CategoryEntity $category): void
    {
        $this->category = $category;
        $this->afterId = $category->getAfterCategoryId();
    }

    public function getCategory(): CategoryEntity
    {
        if (!$this->category) {
            throw CategoryException::categoryNotFound('treeItem');
        }

        return $this->category;
    }

    /** * @return TreeItem[] */
    public function getChildren(): array
    {
        return $this->children;
    }

    }

    /** * @return array<string, string> */
    private function buildBreadcrumb(string $id, CategoryCollection $categories): array
    {
        $category = $categories->get($id);

        if (!$category) {
            throw CategoryException::categoryNotFound($id);
        }

        $breadcrumb = [];
        if ($category->getParentId()) {
            $breadcrumb = $this->buildBreadcrumb($category->getParentId()$categories);
        }

        $breadcrumb[$category->getId()] = $category->getTranslation('name');

        return $breadcrumb;
    }
}

        $criteria->setTitle('product-listing-route::loading');

        $categoryCriteria = new Criteria([$categoryId]);
        $categoryCriteria->setTitle('product-listing-route::category-loading');
        $categoryCriteria->addFields(['productAssignmentType', 'productStreamId']);
        $categoryCriteria->setLimit(1);

        /** @var PartialEntity|null $category */
        $category = $this->categoryRepository->search($categoryCriteria$context->getContext())->first();
        if (!$category) {
            throw ProductException::categoryNotFound($categoryId);
        }

        $this->extendCriteria($context$criteria$category);

        $entities = $this->listingLoader->load($criteria$context);

        $result = ProductListingResult::createFrom($entities);
        $result->addState(...$entities->getStates());

        $result->setStreamId($category->get('productStreamId'));

        
/** * @internal * * @covers \Shopware\Core\Content\Category\CategoryException */
class CategoryExceptionTest extends TestCase
{
    public function testCategoryNotFound(): void
    {
        $categoryId = 'category-id';

        $exception = CategoryException::categoryNotFound($categoryId);

        static::assertInstanceOf(CategoryNotFoundException::class$exception);
        static::assertEquals(Response::HTTP_NOT_FOUND, $exception->getStatusCode());
    }

    public function testServiceCategoryNotFoundForSalesChannel(): void
    {
        $salesChannelName = 'sales-channel-name';

        $exception = CategoryException::serviceCategoryNotFoundForSalesChannel($salesChannelName);

        

    private function getCategoryMetaInfo(string $activeId, string $rootId): array
    {
        $result = $this->connection->fetchAllAssociative(' # navigation-route::meta-information SELECT LOWER(HEX(`id`)), `path`, `level` FROM `category` WHERE `id` = :activeId OR `parent_id` = :activeId OR `id` = :rootId ', ['activeId' => Uuid::fromHexToBytes($activeId), 'rootId' => Uuid::fromHexToBytes($rootId)]);

        if (!$result) {
            throw CategoryException::categoryNotFound($activeId);
        }

        return FetchModeHelper::groupUnique($result);
    }

    /** * @param array<string, CategoryMetaInformation> $metaInfo * * @return CategoryMetaInformation */
    private function getMetaInfoById(string $id, array $metaInfo): array
    {
$routeParams = $request->attributes->get('_route_params', []);
            $routeParams['navigationId'] = $navigationId;
            $request->attributes->set('_route_params', $routeParams);
        }

        $category = $this->loadCategory($navigationId$context);

        if (($category->getType() === CategoryDefinition::TYPE_FOLDER
                || $category->getType() === CategoryDefinition::TYPE_LINK)
            && $context->getSalesChannel()->getNavigationCategoryId() !== $navigationId
        ) {
            throw CategoryException::categoryNotFound($navigationId);
        }

        $pageId = $category->getCmsPageId();
        $slotConfig = $category->getTranslation('slotConfig');

        $salesChannel = $context->getSalesChannel();
        if ($category->getId() === $salesChannel->getNavigationCategoryId() && $salesChannel->getHomeCmsPageId()) {
            $pageId = $salesChannel->getHomeCmsPageId();
            $slotConfig = $salesChannel->getTranslation('homeSlotConfig');
        }

        

            Level::Alert,
        ];

        $logRecord = new LogRecord(new \DateTimeImmutable(), 'foo', Level::Alert, 'some message', ['exception' => new \RuntimeException('')]);
        yield 'log level stays same without shopware exception' => [
            $logRecord,
            [],
            Level::Alert,
        ];

        $logRecord = new LogRecord(new \DateTimeImmutable(), 'foo', Level::Alert, 'some message', ['exception' => ProductException::categoryNotFound(Uuid::randomHex())]);
        yield 'log level stays same without error code mapping' => [
            $logRecord,
            [],
            Level::Alert,
        ];

        yield 'log level stays same without matching error code mapping' => [
            $logRecord,
            [
                ProductException::PRODUCT_INVALID_CHEAPEST_PRICE_FACADE => 'notice',
            ],
            
Home | Imprint | This part of the site doesn't use cookies.