loadNavigation example

#[Route(path: '/store-api/navigation/{activeId}/{rootId}', name: 'store-api.navigation', methods: ['GET', 'POST'], defaults: ['_entity' => 'category'])]     public function load(string $activeId, string $rootId, Request $request, SalesChannelContext $context, Criteria $criteria): NavigationRouteResponse
    {
        return Profiler::trace('navigation-route', function D) use ($activeId$rootId$request$context$criteria) {
            if ($context->hasState(...$this->states)) {
                return $this->getDecorated()->load($activeId$rootId$request$context$criteria);
            }

            $depth = $request->query->getInt('depth', $request->request->getInt('depth', 2));

            // first we load the base navigation, the base navigation is shared for all storefront listings             $response = $this->loadNavigation($request$rootId$rootId$depth$context$criteria[self::ALL_TAG, self::BASE_NAVIGATION_TAG]);

            // no we have to check if the active category is loaded and the children of the active category are loaded             if ($this->isActiveLoaded($rootId$response->getCategories()$activeId)) {
                return $response;
            }

            // reload missing children of active category, depth 0 allows us the skip base navigation loading in the core route             $active = $this->loadNavigation($request$activeId$rootId, 0, $context$criteria[self::ALL_TAG]);

            $response->getCategories()->merge($active->getCategories());

            
Home | Imprint | This part of the site doesn't use cookies.