No category tree in Magento backend

Perhaps you now the problem shown below. The category tree of the products isn’t rendered correctly. That’s because I don’t set level and children_count during import of categories.

Firefox_Screenshot_2015-05-04T13-59-27.429Z

This little script corrects this for me:

UPDATE 
    catalog_category_entity 
SET 
    level = (SELECT LENGTH(path)-LENGTH(REPLACE(path,'/','')) AS tmpl
FROM 
    (SELECT * FROM catalog_category_entity) AS table1
WHERE 
     catalog_category_entity.entity_id = table1.entity_id);

UPDATE 
    catalog_category_entity SET children_count = (SELECT COUNT(*) 
FROM
    (SELECT * FROM catalog_category_entity) AS table2
WHERE 
    path LIKE CONCAT(catalog_category_entity.path,"/%"));

I Found this solution in this blog post from Nikola Stojiljkovic:

http://inchoo.net/magento/solving-problems-with-category-tree-database-information/

 

Leave a Reply

Your email address will not be published.

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.