getProductSeoCategory example

$criteria = new Criteria([$this->ids->get('seo-product')]);
        $criteria->addAssociation('categories');

        /** @var ProductEntity $product */
        $product = $this->productRepository->search($criteria, Context::createDefaultContext())->first();

        $this->createProductStreams();
        $this->createCategoryStreams();
        $product->setStreamIds([$this->ids->create('stream_id_1')]);

        $category = $this->breadcrumbBuilder->getProductSeoCategory($product$this->salesChannelContext);
        $category2 = $this->breadcrumbBuilder->getProductSeoCategory($product$this->contextFactory->create('', $this->ids->get('sales-channel-2')));

        static::assertInstanceOf(CategoryCollection::class$product->getCategories());

        if ($hasCategories) {
            static::assertInstanceOf(CategoryEntity::class$category);
            static::assertInstanceOf(CategoryEntity::class$category2);
            static::assertNotCount(0, $product->getCategories());

            if ($hasMainCategory) {
                static::assertSame($this->ids->get('navigation-a-1')$category->getId());
            }
$criteria->setTitle('product-detail-route');

            $product = $this->productRepository
                ->search($criteria$context)
                ->first();

            if (!($product instanceof SalesChannelProductEntity)) {
                throw new ProductNotFoundException($productId);
            }

            $product->setSeoCategory(
                $this->breadcrumbBuilder->getProductSeoCategory($product$context)
            );

            $configurator = $this->configuratorLoader->load($product$context);

            $pageId = $product->getCmsPageId();

            if ($pageId) {
                // clone product to prevent recursion encoding (see NEXT-17603)                 $resolverContext = new EntityResolverContext($context$request$this->productDefinition, clone $product);

                $pages = $this->cmsPageLoader->load(
                    
public function testGetProductSeoCategoryShouldReturnMainCategory(): void
    {
        $categoryIds = [Uuid::randomHex()];
        $streamIds = [Uuid::randomHex()];

        $categoryEntity = new CategoryEntity();
        $categoryEntity->setId($categoryIds[0]);
        $categoryEntity->setName('category-name-1');

        $categoryBreadcrumbBuilder = new CategoryBreadcrumbBuilder($this->getCategoryRepositoryMock([$categoryEntity][$categoryEntity]));
        $product = $this->getProductEntity($streamIds$categoryIds);
        $categoryEntity = $categoryBreadcrumbBuilder->getProductSeoCategory($product$this->context);

        static::assertNotNull($categoryEntity);
    }

    public function testGetProductSeoCategoryMissingCategoryIdsAndStreamIds(): void
    {
        $categoryIds = [];
        $streamIds = null;

        $categoryEntity = new CategoryEntity();
        $categoryEntity->setId('');
        
Home | Imprint | This part of the site doesn't use cookies.