Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No children data for \Magento\Catalog\Model\CategoryManagement::getTree($categoryId) after first call. #17297

Closed
j0um opened this issue Jul 31, 2018 · 6 comments
Assignees
Labels
Component: Catalog Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release

Comments

@j0um
Copy link

j0um commented Jul 31, 2018

The Magento implementation of the CategoryManagementInterface::getTree($rootCategoryId) does not provide a tree with children data after the first function usage.

Preconditions

  1. Magento 2.2.5
  2. Php 7.1.15, Percona Mysql 5.7.22-22

Steps to reproduce

In a console script making use of \Magento\Catalog\Model\CategoryManagement, do the following :
$categoryId = 1; // Any valid category id.
$hasChildren = $categoryManagement->getTree($categoryId)->getChildrenData();
$noChildren = $categoryManagement->getTree($categoryId)->getChildrenData();

if (count($hasChildren) != count($noChildren)) {
// Well this is unexpected.
}

Expected result

I expect $noChildren to be populated with children.

Actual result

$noChildren's children_data is an empty array.

@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Jul 31, 2018
@magento-engcom-team
Copy link
Contributor

Hi @j0um. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento-engcom-team give me {$VERSION} instance

where {$VERSION} is version tags (starting from 2.2.0+) or develop branches (2.2-develop +).
For more details, please, review the Magento Contributor Assistant documentation.

@j0um do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • yes
  • no

@j0um
Copy link
Author

j0um commented Jul 31, 2018

@magento-engcom-team give me {2.2.5} instance

@ghost ghost self-assigned this Aug 1, 2018
@ghost ghost added Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Component: Catalog labels Aug 1, 2018
@ghost
Copy link

ghost commented Aug 1, 2018

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

@ghost ghost added the Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release label Aug 1, 2018
@ghost ghost removed their assignment Aug 1, 2018
@pmclain pmclain self-assigned this Oct 19, 2018
@magento-engcom-team
Copy link
Contributor

magento-engcom-team commented Oct 19, 2018

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

  • 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 2. Verify that the issue is reproducible on 2.3-develop branch

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

  • 3. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • 4. If the issue is not relevant or is not reproducible any more, feel free to close it.

pmclain added a commit to pmclain/magento2 that referenced this issue Oct 19, 2018
…tTree

Tree::getNode currently loads nodes using a resource singleton. The tree
resource's parent class contains the property _loaded and only loads child
nodes when _loaded is false. This behavior means only the first call to
CategoryManagement::getTree in a request returns child nodes.

Fixes magento#17297
@magento-engcom-team
Copy link
Contributor

Hi @j0um. Thank you for your report.
The issue has been fixed in #18705 by @pmclain in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.2 release.

@magento-engcom-team magento-engcom-team added the Fixed in 2.3.x The issue has been fixed in 2.3 release line label Mar 8, 2019
@themystery404
Copy link

Hello @pmclain , this issue still reproduced for me, if I need to get several trees of different Root Categories.
Example

        foreach ($rootCategoryIds as $rootCategoryId) {
            $categoryManagement = $this->categoryManagementFactory->create();
            $tree = $categoryManagement->getTree($rootCategoryId, 5);
        }

Only first tree has children

It caused shared $categoryCollection property in Magento/Catalog/Model/Category/Tree.php
I fixed this issue by adding to my di.xml next code

    <type name="Magento\Catalog\Model\Category\Tree">
        <arguments>
            <argument name="categoryCollection" shared="false" xsi:type="object">Magento\Catalog\Model\ResourceModel\Category\Collection</argument>
        </arguments>
    </type>
    <type name="Magento\Catalog\Model\CategoryManagement">
        <arguments>
            <argument name="categoryTree" shared="false" xsi:type="object">Magento\Catalog\Model\Category\Tree</argument>
        </arguments>
    </type>

But, would be better to fix this using by using factory for collection in __construct in Magento core code

What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Catalog Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

No branches or pull requests

4 participants