NavigationRouteResponse example



        $categories = new CategoryCollection();
        if ($depth > 0) {
            // Load the first two levels without using the activeId in the query             $categories = $this->loadLevels($rootId(int) $root['level']$contextclone $criteria$depth);
        }

        // If the active category is part of the provided root id, we have to load the children and the parents of the active id         $categories = $this->loadChildren($activeId$context$rootId$metaInfo$categoriesclone $criteria);

        return new NavigationRouteResponse($categories);
    }

    /** * @param string[] $ids */
    private function loadCategories(array $ids, SalesChannelContext $context, Criteria $criteria): CategoryCollection
    {
        $criteria->setIds($ids);
        $criteria->addAssociation('media');
        $criteria->setTotalCountMode(Criteria::TOTAL_COUNT_MODE_NONE);

        
$salesChannel,
            new CurrencyEntity(),
            new CustomerGroupEntity(),
            new TaxCollection(),
            new PaymentMethodEntity(),
            new ShippingMethodEntity(),
            new ShippingLocation(new CountryEntity(), null, null),
            new CustomerEntity(),
            new CashRoundingConfig(1, 1.1, true),
            new CashRoundingConfig(1, 1.1, true)
        );
        $this->response = new NavigationRouteResponse(
            new CategoryCollection()
        );

        $this->cachedRoute = new CachedNavigationRoute(
            $this->decorated,
            $this->cache,
            $this->createMock(EntityCacheKeyGenerator::class),
            $this->createMock(AbstractCacheTracer::class),
            $this->eventDispatcher,
            []
        );
    }
$response = $this->getDecorated()->load($activeId$rootId$request$context$criteria);

        $buildTree = $request->query->getBoolean('buildTree', $request->request->getBoolean('buildTree', true));

        if (!$buildTree) {
            return $response;
        }

        $categories = $this->buildTree($rootId$response->getCategories()->getElements());

        return new NavigationRouteResponse($categories);
    }

    /** * @param CategoryEntity[] $categories */
    private function buildTree(?string $parentId, array $categories): CategoryCollection
    {
        $children = new CategoryCollection();
        foreach ($categories as $key => $category) {
            if ($category->getParentId() !== $parentId) {
                continue;
            }
Home | Imprint | This part of the site doesn't use cookies.