magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.51k stars 9.31k forks source link

Category URL rewrite generation does not set nested categories reliably #14202

Closed allisonlawrencels closed 5 years ago

allisonlawrencels commented 6 years ago

Preconditions

  1. Magento version 2.2.3

Steps to reproduce

  1. Create a category structure with categories to at least 3 levels (Root > Cat level 1 > Cat level 2 > Cat level 3). Create the level 2 AFTER the level 3, so its database ID is higher.
  2. Change the URL of the Level 1 category, uncheck "Create Permanent Redirect for old URL" (it is easier to see the results this way)
  3. See resulting URL rewrites. Some contain the original Level 1 category path, and some contain the new path.

Expected result

  1. All children categories should be updated with the new URL path.

Actual Result

  1. Cat level 3 URL path not updated.

Solution

The Magento\CatalogUrlRewrite\Model\Category\ChildrenCategoriesProvider::getChildren() function should be updated to include a sort by level:

    public function getChildren(Category $category, $recursive = false)
    {
        return $category->isObjectNew() ? [] : $category->getResourceCollection()
            ->addAttributeToSelect('url_path')
            ->addAttributeToSelect('url_key')
            ->addAttributeToSelect('name')
+            ->setOrder('level', 'asc')
            ->addIdFilter($this->getChildrenIds($category, $recursive));
    }
ghost commented 6 years ago

@allisonlawrencels, thank you for your report. We've acknowledged the issue and added to our backlog.

m2-assistant[bot] commented 5 years ago

Hi @madbounce. Thank you for working on this issue. Looks like this issue is already verified and confirmed. But if you want to validate it one more time, please, go though the following instruction:


madbounce commented 5 years ago

Hey @allisonlawrencels, basically not clear how we can create Level 3 before Level 2 and get needed structure that you provided. Currently I checked current flow on Magento branch 2.3-develop and issue not reproduced (all url rewrites was regenerated according to url that was set for Cat Level 1).

Closed for now.