/** * Get or create root category. * @return null|Category */ protected function getRoot() { if (!$this->rootCategory) { $this->rootCategory = $this->createCategory(['name' => '0_ROOT', 'enabled' => 1]); $this->rootCategory->refresh(); $this->rootCategory->parent = 0; $this->rootCategory->save(); } return $this->rootCategory; }