I just migrated from Magento 1.9 to Magento 2.3.4 and I have an anchor category that should be showing all the subcategories products, but somehow it does not show any of the subcategory products.
Parent Category Display Setting:
in my M1 site , if i go to the category page, it will show all subcategory products:
http://m1-site.local/catalog/category/view/id/1404
in my M2 site, if i go to the category page, it won’t show any products at all:
http://m2-site.local/catalog/category/view/id/1404
I tried to debug it in vendor/magento/module-catalog/Controller/Category/View.php:264
:
private function getPageType(Category $category) : string
{
$hasChildren = $category->hasChildren();
if ($category->getIsAnchor()) {
return $hasChildren ? 'layered' : 'layered_without_children';
}
return $hasChildren ? 'default' : 'default_without_children';
}
it should return layered
but always return layered_without_children
, this means the function does not count the subcategories correctly. When i checked the Store > configuration > Catalog > Storefront > Category Flat
it was enabled, then i disabled it and run indexer and cache flush, but still the same case.
UPDATE
I noticed in M1 the query is inner joining the product table with mage_catalog_category_product_index but in M2 is with mage_catalog_category_product_index_store1
this mage_catalog_category_product_index_store1
table does not have product with category id 1404