Magento2: Admin category tree move doesn't recreate subcategory URL rewrites

Created on 1 Dec 2017  路  13Comments  路  Source: magento/magento2

Preconditions

Magento version 2.1.6 (clean version with sample data)
PHP version 7.0.25
MySQL 5.7.20

Steps to reproduce

  1. Create Parent, Child and Grandchild categories

parent_child_grandchild

  1. Magento will create correct URL rewrites for all three categories
  2. Move Child category to the same level as Parent category

child_grandchild

Expected result

  1. Magento should create correct URL rewrites for Child category, and all of it's subcategories

Actual result

  1. Magento will recreate correct URL rewrite for Child category, but rewrite for Grandchild stays as it was

new_grandchild

  1. Grandchild rewrite gets corrected only after category save
Cannot Reproduce Clear Description Format is valid Ready for Work Reproduced on 2.1.x Reproduced on 2.2.x Reproduced on 2.3.x

Most helpful comment

Hi Magento Team,
@magento-engcom-team

Maybe I wrote a lot and it's not clear if you have any questions, I'll answer in slack

Problem

In the admin area, if the executable URL does not contain a parameter in the URL request ___store
or the executable code does not specify the store_code ( $this->getStoreManager()->setCurrentStore($store->getCode())).
String $this->storeManager->getStore()->getId() returns store_code from the cookie frontend (code)

The problem for this task

The problem is that when recursively loading the collections of categories, item collection returned wrong store_id ($category->getStoreId()). This causes the value to be stored incorrectly in DB. Example screen
screen_1
:

If category model doesn't contain data store_id, then the value is returned (int)$this->_storeManager->getStore()->getId(); Code

The solution for this problem

In my opinion, the problem is global. The solution must be return value 0 (admin default store id) for code $this->_storeManager->getStore()->getId() in admin area. For example, create a individual store manager admin area.
Like is for url manager https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Backend/etc/adminhtml/di.xml#L12. Or fix the code in an existing class . This change is very sensitive to backward compatibility. I will not create a pull request.

If the problem is solved locally, the solution looks like this:
1) open Magento\Catalog\Controller\Adminhtml\Category\Move::execute(),
2) create copy/past from Magento\Catalog\Controller\Adminhtml\Category\Edit::execute()

$storeId = (int)$this->getRequest()->getParam('store'); $store = $this->getStoreManager()->getStore($storeId); $this->getStoreManager()->setCurrentStore($store->getCode());

to Magento\Catalog\Controller\Adminhtml\Category\Move::execute() similarly and copy past private function getStoreManager()

All 13 comments

Hello @VesnaS. Thanks for reporting. Seems we are not able to reproduce Your issue. Here we have attached the video with how we did it. So please, watch this video and tell us what we've been doing differently.
urlrew.zip

Hello,
I watched your video, and you've repeated all the steps I've listed.
Here is the recording of me doing the same steps, with a different result from yours.
reproduce.zip

And would You @VesnaS be able to repeat all the steps in Your video, but with the system messages (there up on the screen) resolved, so that we can be sure that there are no unresolved issues that cause our issue. Thank You.

Hello,
I finally realized what the difference is between your and mine environment.
You have only one website, and I have multi-website configuration.
In order to be able to reproduce this bug, please:

  • Add one more website, store and store view

test_website

  • Associate Default root category to the newly created store

  • Repeat above mentioned steps and hopefully you will be able to see the problem I am talking about

@VesnaS, thank you for your report.
We've created internal ticket(s) MAGETWO-85022 to track progress on the issue.

mageconf

@novakivskiy thank you for joining. Please accept team invitation here and self-assign the issue.

Hi Is there already a fix for this issue?

Hi Magento Team,
@magento-engcom-team

Maybe I wrote a lot and it's not clear if you have any questions, I'll answer in slack

Problem

In the admin area, if the executable URL does not contain a parameter in the URL request ___store
or the executable code does not specify the store_code ( $this->getStoreManager()->setCurrentStore($store->getCode())).
String $this->storeManager->getStore()->getId() returns store_code from the cookie frontend (code)

The problem for this task

The problem is that when recursively loading the collections of categories, item collection returned wrong store_id ($category->getStoreId()). This causes the value to be stored incorrectly in DB. Example screen
screen_1
:

If category model doesn't contain data store_id, then the value is returned (int)$this->_storeManager->getStore()->getId(); Code

The solution for this problem

In my opinion, the problem is global. The solution must be return value 0 (admin default store id) for code $this->_storeManager->getStore()->getId() in admin area. For example, create a individual store manager admin area.
Like is for url manager https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Backend/etc/adminhtml/di.xml#L12. Or fix the code in an existing class . This change is very sensitive to backward compatibility. I will not create a pull request.

If the problem is solved locally, the solution looks like this:
1) open Magento\Catalog\Controller\Adminhtml\Category\Move::execute(),
2) create copy/past from Magento\Catalog\Controller\Adminhtml\Category\Edit::execute()

$storeId = (int)$this->getRequest()->getParam('store'); $store = $this->getStoreManager()->getStore($storeId); $this->getStoreManager()->setCurrentStore($store->getCode());

to Magento\Catalog\Controller\Adminhtml\Category\Move::execute() similarly and copy past private function getStoreManager()

Can confirm the problem and @novakivskiy suggested modification did cure the problem! Thank you!

I can also confirm @novakivskiy solution worked.

Hi @engcom-Echo. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 5. Add label Issue: Confirmed once verification is complete.

  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

Hello All

I am not able to reproduce this issue on the 2.4-develop branch by provided steps.

Testing scenario:

Steps to reproduce:

  1. Create Parent, Child and Grandchild categories
  2. Magento will create correct URL rewrites for all three categories
  3. Move Child category to the same level as Parent category

Result
Magento creates correct URL rewrites for the Child category and all its subcategories
wwww
Please feel free to comment, reopen or create new ticket according to the Issue reporting guidelines
if you are still facing this issue on the latest 2.4-develop branch. Thank you for collaboration.

Was this page helpful?
0 / 5 - 0 ratings