Guest User

Untitled

a guest
May 22nd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. www.magento2.com/Category1/Category2/gear/bags.html
  2.  
  3. www.magento2.com/bags.html
  4.  
  5. protected function isNeedToGenerateUrlPathForParent($category)
  6. {
  7. return $category->isObjectNew() || $category->getLevel() >= self::MINIMAL_CATEGORY_LEVEL_FOR_PROCESSING;
  8. }
  9.  
  10. const MINIMAL_CATEGORY_LEVEL_FOR_PROCESSING = 3;
  11.  
  12. class RemoveParentCategoryPathPlugin
  13. {
  14. public function aroundGetUrlPath($subject, $proceed, $category)
  15. {
  16. if (in_array($category->getParentId(), [Category::ROOT_CATEGORY_ID, Category::TREE_ROOT_ID])) {
  17. return '';
  18. }
  19. $path = $category->getUrlPath();
  20. if ($path !== null && !$category->dataHasChangedFor('url_key') && !$category->dataHasChangedFor('parent_id')) {
  21. return $path;
  22. }
  23. $path = $category->getUrlKey();
  24. if ($path === false) {
  25. return $category->getUrlPath();
  26. }
  27. return $path;
  28. }
  29. }
  30.  
  31. $allCategories = $categoryCollectionFactory->create()->load();
  32. foreach ($allCategories as $category) {
  33. $category->setDataChanges(true);
  34. $category->save();
  35. }
  36.  
  37. vendor/magento/module-catalog-url-rewrite/Model/CategoryUrlPathGenerator.php around line 75
  38.  
  39. /* if ($this->isNeedToGenerateUrlPathForParent($category)) {
  40. $parentPath = $this->getUrlPath(
  41. $this->categoryRepository->get($category->getParentId(), $category->getStoreId())
  42. );
  43. $path = $parentPath === '' ? $path : $parentPath . '/' . $path;
  44. $path = '';
  45.  
  46. } */
  47.  
  48. /* if ($this->isNeedToGenerateUrlPathForParent($category)) {
  49. $parentPath = $this->getUrlPath(
  50. $this->categoryRepository->get($category->getParentId(), $category->getStoreId())
  51. );
  52. $path = $parentPath === '' ? $path : $parentPath . '/' . $path;
  53. $path = '';
  54.  
  55. } */
Add Comment
Please, Sign In to add comment