private function getCurrentCategory()
    {
        $category = $this->context->getCurrentCategory();

        if (null === $category) {
            $category = $this->categoryRepository->get(
                $this->storeManager->getStore()->getRootCategoryId(),
                $this->storeManager->getStore()->getId()
            );
        }

        return $category;
    }
private function getCurrentCategory()
    {
        $category = $this->context->getCurrentCategory();

        if (null === $category) {
            $category = $this->categoryRepository->get(
                $this->storeManager->getStore()->getRootCategoryId(),
                $this->storeManager->getStore()->getId()
            );
        }

        return $category;
    }
private function getCurrentCategory ( ) { $ category = $ this -> context -> getCurrentCategory ( ) ; if ( null === $ category ) { $ category = $ this -> categoryRepository -> get ( $ this -> storeManager -> getStore ( ) -> getRootCategoryId ( ) , $ this -> storeManager -> getStore ( ) -> getId ( ) ) ; } return $ category ; }
Retrieve current category from search context or instantiate the default root of current store.

@return \Magento\Catalog\Api\Data\CategoryInterface
Retrieve current category from search context or instantiate the default root of current store .