Magento Product Edit Only Shows Default Category

If you are failing to see your product categories while editing a product, but you can see the categories in your category edit menu, odds are your ‘children_count’ for categories isn’t correct on the database. A quick SQL statement fixes this.

The children count isn’t used for anything useful. You can even set it as the wrong number, you just have to make sure it’s greater than 0. In my case my root category and default category were both negative numbers.

Simple fix in Magento 1.6.1:

1
UPDATE catalog_category_entity SET children_count = "1" WHERE children_count < 1;
UPDATE catalog_category_entity SET children_count = "1" WHERE children_count < 1;

Why Does This Work?

The product edit screen uses a Javscript tree widget to show children categories. It’s logical to not show the children if the children_count is 0.

I’m Still Having Problems!

If you are still having problems, it’s also possible that your level is set incorrectly. In my case setting level to the root category for all categories worked great.

1
2
3
4
5
6
7
8
9
10
11
    foreach ($categories as $category) {
        $category = $category->load($category->getId());
 
        $level = $category->getLevel();
 
        if($level > 2) {
            $category->setLevel(2);
            $category->save();
        }
 
    }
    foreach ($categories as $category) {
        $category = $category->load($category->getId());

        $level = $category->getLevel();

        if($level > 2) {
            $category->setLevel(2);
            $category->save();
        }

    }
Discussion
Jake says:

Thank you very much, I was beginning to worry that I would have to import from scratch all over.

This was driving me nuts! This worked for me in 1.7.1. Thank you so much man!

Justin says:

In which file are you editing the category level code?

alex says:

it works on 1.7.1… GREAT thank you !

Shashank says:

It is not working for Enterprise edition 1.12

When any new product is created I am able to see all categories but when I save it only two categories are visible under product category section. please help me on this issue.

The problem with your solution is, that the real count of children isnt set. and that makes more problems when you delete a categorie and the child-count decrease by one and you have the same problem like before.

to do it the right way copy the table ‘catalog_category_entity’ to another one like ‘catalog_category_entity_test’ and run this script:

UPDATE catalog_category_entity w1 SET children_count = (select (SELECT count(*) from catalog_category_entity_test u1 where u1.path REGEXP CONCAT(‘^’,u2.path,’/[[:digit:]]+$’)) from catalog_category_entity_test u2 where u2.path = w1.path)

thats the right way…

Wow, this worked for me also! Since I only have a few categories I was able to find the exact one that should have been greater than zero.

The downside to making all child counts greater than zero is that it appears that all categories have children.

When you click on the + to expand the category, the + disappears. On refresh, the + appears again.

My main concern is what could have caused this in the first place?!

Yannis says:

Hello everyone! Tim Schmidt’s solution (comment above) worked for me too. Thanks Zachary. Thanks Tim.

Leave a Reply