Load the root category used for a virtual category.

@param CategoryInterface $category Virtual category.

@return CategoryInterface
330283
private function getVirtualRootCategory(CategoryInterface $category)
    {
        $storeId      = $this->getStoreId();
        $rootCategory = $this->categoryFactory->create()->setStoreId($storeId);

        if ($category->getVirtualCategoryRoot() !== null && !empty($category->getVirtualCategoryRoot())) {
            $rootCategoryId = $category->getVirtualCategoryRoot();
            $rootCategory->load($rootCategoryId);
        }

        if ($rootCategory && $rootCategory->getId()
            && ($rootCategory->getLevel() < 1 || (int) $rootCategory->getId() === (int) $this->getRootCategoryId($storeId))
        ) {
            $rootCategory = null;
        }

        return $rootCategory;
    }
1369526
public function category($category = null)
  {
    if (null === $category)
    {
      return isset($this->requestConfig['category']) ? $this->requestConfig['category'] : null;
    }

    $this->requestConfig['category'] = $category;

    return $this;
  }
621989
private function getNewParentTree($category)
    {
        $pathIds = array_reverse(explode(',', $category->getPathInStore()));
        $pathIds[] = $category->getId();

        /** @var \Magento\Catalog\Model\ResourceModel\Category\Collection $categories */
        $categories = $this->categoryCollectionFactory->create();

        return $categories->setStore($this->storeManager->getStore())
            ->addAttributeToSelect(['name', 'is_virtual_category', 'virtual_category_root'])
            ->addFieldToFilter('entity_id', ['in' => $pathIds]);
    }
903189
public function addCategory(\Hexmedia\ContentBundle\Entity\Category $category)
    {
        $this->categories[] = $category;

        return $this;
    }
1140395
public function setCategory(\Amulen\ClassificationBundle\Entity\Category $category = null)
    {
        $this->category = $category;

        return $this;
    }
129405
protected function getCategoryProductsQueryBuilder(CategoryInterface $category = null)
    {
        $queryBuilder = $this->getRepository()->createQueryBuilder('p')
            ->leftJoin('p.image', 'i')
            ->leftJoin('p.gallery', 'g');

        if ($category) {
            $queryBuilder
                ->leftJoin('p.productCategories', 'pc')
                ->andWhere('pc.category = :categoryId')
                ->setParameter('categoryId', $category->getId());
        }

        return $queryBuilder;
    }
1083592
public function getModules(string $category) {
        if (isset($this->modules[$category])) {
            return $this->modules[$category];
        }

        return null;
    }
559057
public function load(ICategory $category)
    {
        $this->template->set('title', $category->getTitle());
        $this->template->set('meta_title', $category->metaTitle());
        $this->template->set('meta_keywords', $category->metaKeywords());
        $this->template->set('meta_description', $category->metaDescription());
    }
1061974
public static function getInstance($category = self::CATEGORY_DEFAULT)
    {
        if (!isset(self::$instances[$category])) {
            self::$instances[$category] = new static($category);
        }
        return self::$instances[$category];
    }
1028665
public function getCategory($category)
    {
        $ds = DIRECTORY_SEPARATOR;
        $categoryPath = str_replace('/', $ds, $category);

        $path = app_path().$ds.'lablog'.$ds.$categoryPath;

        if (!$this->exists($category)) {
            return (object) array();
        }

        $categoryExplode = explode('/', $category);
        $categoryName = end($categoryExplode);

        $linkPrefix = \Config::get('lablog::prefix') == '/' ? '' : \Config::get('lablog::prefix');

        $baseCategory = $category;
        $categoryLink = $linkPrefix.'/category/'.$category;
        $fullCategory = $category;

        $category = new Category;
        $category->name = $categoryName;
        $category->link = $baseCategory;
        $category->url = \URL::to($categoryLink);

        return $category;
    }
1337260
private function getCategorySearchQuery(CategoryInterface $category)
    {
        $virtualRule = $category->getVirtualRule();
        if (!($virtualRule instanceof VirtualRuleInterface)) {
            return $this->loadVirtualRule($category)->getCategorySearchQuery($category);
        }

        return $this->helper->loadUsingCache($category, 'getCategorySearchQuery');
    }
87340
public function setCategory(\HarvestCloud\CoreBundle\Entity\Category $category)
    {
        $this->category = $category;

        return $this;
    }
1081080
public function withCategory($category)
    {
        Assertion::string($category);
        Assertion::maxLength($category, VideoInterface::CATEGORY_MAX_LENGTH);

        $instance = clone $this;

        $instance->category = $category;

        return $instance;
    }
509715
public function setCategory(\Magento\Catalog\Api\Data\CategoryInterface $category)
    {
        $this->category = $category;

        return $this;
    }
40371
public function addCategory(BlogCategory $category)
    {
        $category->setBlog($this);
        $this->categories->add($category);

        return $this;
    }
588097
public function root()
    {
        $category = $this->createModel();

        $category = $category->whereExists(function($query)
        {
            $query->select(\DB::raw(1))
                  ->from('category_hierarchy')
                  ->whereRaw(DB::getTablePrefix().'categories.id = '.DB::getTablePrefix().'category_hierarchy.category_id')
                  ->where('category_hierarchy.category_parent_id', 0);
        });

        return $category;
    }
1329085
protected function loadCategories(ContextInterface $context)
    {
        if (\array_key_exists($context->getId(), $this->categories)) {
            return;
        }

        $class = $this->getClass();

        $categories = $this->getObjectManager()->createQuery(sprintf('SELECT c FROM %s c WHERE c.context = :context ORDER BY c.parent ASC', $class))
            ->setParameter('context', $context->getId())
            ->execute();

        if (0 === \count($categories)) {
            // no category, create one for the provided context
            $category = $this->create();
            $category->setName($context->getName());
            $category->setEnabled(true);
            $category->setContext($context);
            $category->setDescription($context->getName());

            $this->save($category);

            $categories = [$category];
        }

        $rootCategories = [];
        foreach ($categories as $pos => $category) {
            if (null === $category->getParent()) {
                $rootCategories[] = $category;
            }

            $this->categories[$context->getId()][$category->getId()] = $category;

            $parent = $category->getParent();

            $category->disableChildrenLazyLoading();

            if ($parent) {
                $parent->addChild($category);
            }
        }

        $this->categories[$context->getId()] = $rootCategories;
    }