Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- www.magento2.com/Category1/Category2/gear/bags.html
- www.magento2.com/bags.html
- protected function isNeedToGenerateUrlPathForParent($category)
- {
- return $category->isObjectNew() || $category->getLevel() >= self::MINIMAL_CATEGORY_LEVEL_FOR_PROCESSING;
- }
- const MINIMAL_CATEGORY_LEVEL_FOR_PROCESSING = 3;
- class RemoveParentCategoryPathPlugin
- {
- public function aroundGetUrlPath($subject, $proceed, $category)
- {
- if (in_array($category->getParentId(), [Category::ROOT_CATEGORY_ID, 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();
- }
- return $path;
- }
- }
- $allCategories = $categoryCollectionFactory->create()->load();
- foreach ($allCategories as $category) {
- $category->setDataChanges(true);
- $category->save();
- }
- vendor/magento/module-catalog-url-rewrite/Model/CategoryUrlPathGenerator.php around line 75
- /* if ($this->isNeedToGenerateUrlPathForParent($category)) {
- $parentPath = $this->getUrlPath(
- $this->categoryRepository->get($category->getParentId(), $category->getStoreId())
- );
- $path = $parentPath === '' ? $path : $parentPath . '/' . $path;
- $path = '';
- } */
- /* if ($this->isNeedToGenerateUrlPathForParent($category)) {
- $parentPath = $this->getUrlPath(
- $this->categoryRepository->get($category->getParentId(), $category->getStoreId())
- );
- $path = $parentPath === '' ? $path : $parentPath . '/' . $path;
- $path = '';
- } */
Add Comment
Please, Sign In to add comment