/** * Build category URL path * * @param \Magento\Catalog\Api\Data\CategoryInterface|\Magento\Framework\Model\AbstractModel $category * @return string */ public function getUrlPath($category) { if ($category->getParentId() == Category::TREE_ROOT_ID) { return ''; } $path = $category->getUrlPath(); if ($path !== null && !$category->dataHasChangedFor('url_key') && !$category->dataHasChangedFor('parent_id')) { return $path; } $path = $category->getUrlKey(); if ($path === false) { return $category->getUrlPath(); } if ($this->isNeedToGenerateUrlPathForParent($category)) { $parentPath = $this->getUrlPath($this->categoryRepository->get($category->getParentId())); $path = $parentPath === '' ? $path : $parentPath . '/' . $path; } return $path; }