Jump to content
thirty bees forum

Category bug?


Recommended Posts

Hi all. I believe I've come across a bug. I've got a category called CatQ whose parent is CatB. However, each time I open CatQ in the Front Office it comes up as a subcategory of another category (let's call it CatA). So I get:

Home / CatA / CatQ

When it should be:

Home / CatB / CatQ

I checked the DB and parent ID of CatQ is assigned to CatB correctly in the category table. I have totally disabled the cache as well. Any ideas would be appreciated.


Link to comment
Share on other sites

Thank you for the reply. I checked everything very carefully, there are no duplicates or anything like that. I have also noticed that products are showing up on the homefeatured page which are not in the home category (I have homefeatured set to display products from the home category). 

Absolutely nothing seems wrong in the DB. The most likely cause would seem to be cache, but I already disabled the cache. This is too weird. Is there any other kind of cache that needs to be disabled manually? 

Link to comment
Share on other sites

It's possible that the ntree index is broken. Category table contains columns nleft, nright, and level_depth. These columns are useful for quickly obtaining only a part of the category tree (like all subcategories, or all parent categories query). But sometimes the information in these columns is out of sync with id_category / id_parent, and needs to be regenerated.

To regenerate entire category ntree, you can simply create a new category, and then delete it. 

  • Like 1
Link to comment
Share on other sites

@datakick Thank you, that's incredibly helpful and solves 90% of the problem. Indeed, the ntree values were messed up and now the original problem doesn't exist. The remaining problem is the BlockHomeFeatured still shows products that are not associated with the Home category (then they cease to show if I associate them with the home Category). Is there anything else that could be messed up which may be causing this?

My best guess as to why this occurred is because I was using PresTools to update categories. 



Link to comment
Share on other sites

EDIT: This can be ignored. It was an oversight on my part (see next post).

@datakick Thank you for the additional suggestions. It doesn't appear to be any issue with the DB, but I think I found the problem. BlockHomeFeatured makes a call to the getProducts function of Category.php, which traverses not only the given category, but also includes all subcategories, such that the following code (similar to that in BlockFeaturedProducts module) will show all 120 products:


$category = new Category(2, (int) Context::getContext()->language->id);
$res = $category->getProducts((int) Context::getContext()->language->id, 1, 120,'position');

The code of getProducts in Categories.php responsible for including all subcategories is this

        $subcats = $this->getAllSubcategories();
        $catsToSearchIn = [$this->id];
        if($subcats && $this->display_from_sub)
            foreach ($subcats as $scat) {
                $catsToSearchIn[] = $scat['id_category'];

This means that selecting the Home category in the BlockFeaturedProducts module will show every single product, because Home is an ancestor node of all other categories. It's also clear that getProducts doesn't have any parameter to disable traversal of the subcategories. Am I missing something here? My understanding was that BlockFeaturedProducts would show only products which have the "Home" category ticked under associations, but this doesn't seem to be the case. If that's so.. then silly me.

Edited by funnycamel
found proper solution
Link to comment
Share on other sites

I found the answer. There's a setting which was hard to find for the Home category and I needed to set it to "No" for "Display products from subcategories". I uploaded the image of both pages for anyone who is interested. First you need to click the little edit icon, then change the subcategories setting. So two things I learned today.. resetting the ntree and accessing the Home category settings.


  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...