When you search for something, using sample data for example, a 'bag' no category filters are displayed. That happens because category filters are only rendered if Category in $categories
has no children categories. In Magento\CatalogSearch\Model\Layer\Filter\Category
in ::_getItemsData()
$category
is _Default Category_ and $categories
is a collection of it's direct children categories.
But $optionsFacetedData
is an array of Categories which are children of the $categories
When you check
...
foreach ($categories as $category) {
if ($category->getIsActive()
-> && isset($optionsFacetedData[$category->getId()]) <-
&& $this->isOptionReducesResults($optionsFacetedData[$category->getId()]['count'], $collectionSize)
) {
...
There is no match and filters aren't rendered.
why not using isotope filtering?
The GitHub issue tracker is intended for technical issues only. Please refer to the Community Forums or Magento Stack Exchange site for technical questions. In your case, the programming questions forum is likely the most appropriate. Feel free to reopen this issue if you think you have encountered a bug in Magento 2.
I think it is a technical issue (bug) with M2.
Categories in layered are only rendered if Category in has no children.
Layered category filter only shows non-anchored sub-categories, all is_anchor ones are not displayed.
Same with search results layered category.
This happen with the demo sample data as well as our migrated store from 1.9.01 (2000 categories in 4 levels). in our 1.9.0.1 all categories and sub-categories are displayed fine in layered left nav.
I have same kind of issue available for category with subcategory have product then its not display inside layered navigation.
I have checked category with subcategory all have is_anchor equal yes.
Any update for this issue?
Here's a patch that fixes the issue:
diff --git a/www/vendor/magento/module-catalog-search/Model/Adapter/Mysql/Plugin/Aggregation/Category/DataProvider.php b/www/vendor/magento/module-catalog-search/Model/Adapter/Mysql/Plugin/Aggregation/Category/DataProvider.php
index f54a60f..678226b 100644
--- a/www/vendor/magento/module-catalog-search/Model/Adapter/Mysql/Plugin/Aggregation/Category/DataProvider.php
+++ b/www/vendor/magento/module-catalog-search/Model/Adapter/Mysql/Plugin/Aggregation/Category/DataProvider.php
@@ -74,8 +74,8 @@ class DataProvider
$derivedTable->from(
['main_table' => $this->resource->getTableName('catalog_category_product_index')],
[
- 'entity_id' => 'product_id',
'value' => 'category_id',
+ 'entity_id' => 'product_id',
]
)->where('main_table.store_id = ?', $currentScopeId);
$derivedTable->joinInner(
The problem is the following. In Magento\CatalogSearch\Model\Adapter\Mysql\Aggregation\DataProvider
in the execute
-method the fetchAssoc
method is used to convert the query result into an associative array. The fetchAssoc
method however uses the first column for the keys of the associated array. For all attribute aggregations the first column is always the value
column, as it should be. However for the category aggregation the first column for some reason is the entity_id
column, which is not unique. The fix consists thus in making the value
column the first column to be returned by the select.
Right on ktruehl. Problem fixed. Thks.
Hi @ktruehl Thanks for the patch! I've created a bug for internal tracking purposes - MAGETWO-52436 .
Closing the other github issue as a dup.
Thanks @ktruehl, your fix works perfectly.
Current issue has been fixed and delivered in the scope of 2.0.3 patch release.
So, it's now available on github
The fix is the same as @ktruehl provided above
https://github.com/magento/magento2/blob/develop/app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Plugin/Aggregation/Category/DataProvider.php
This fix isn't in the 2.0.3 patch, it's not even in 2.0.5, but I can still see the fix in the dev branch - any reason it's not been included yet?
It didn't get to 2.0.3. Now it's going to be delivered in the scope of 2.0.7 Patch release
I am having a similar issue. Not all the categories that appear in the navigation menu dropdown are appearing in the category section in the layered navigation. There doesn't seem to be anything related with what shows up and what doesn't show up. All categories are set as anchors. Some categories have sub categories and some don't. It doesn't seem to make a difference as to them showing up or not. There are enabled products in all categories/sub categories.
I have tried deleting and re-adding one of the categories that wasn't showing up in the layered navigation and it did show up but then went away again after adding some sub categories to it.
This is with Magento 2.0.7 CE.
Here is a screenshot showing what I mean.
Thanks for the fix @ktruehl
I'm experiencing crtsl's issue as well... getting Categories to show in the Category Layered Navigation seems very buggy... deleting-readding categories seems to fix it temporarily... but then as I work in a category adding sub cats or products it seems to get removed... sometimes... I'm trying to narrow down the behavior exactly...
Mage 2.0.7
Yeah, when I create a New Category and add products to it via the Category Products tab then the layered navigation renders on the front end for that Category.
If I then add 1 Subcategory, assign it some products in the same manner... everything is fine.
As soon as I add a second subcategory, assign it some products, and save then the parent Category disappears from Layered Navigation all together.
I feel like this is perhaps offtopic here though as the OP was posting about Search... I'll open a new Issue
Internal issue created - MAGETWO-54383
Hello @kost08, this issue has been fixed in the 2.1.0 Release, that's why I'm closing it. If you any questions or additional information regarding the issue feel free to reopen it or create a new one.
Thank you all, its helped me lot.
@kost08 thanks for the post.
I'm experiencing the exact same issue on Magento 2.1.2 on blank theme. Category filter disappear as soon as I add products on subcategory.
this is still present in 2.1.6
Also having same issue in 2.1.3 Enterprise
Having similar issues in 2.1.7
Valid subcategories are not appearing in layered navigation "Category" section of a parent category page
Still present in 2.2.0
I have the same issue in Magento 2.1.7. Any fix on this issue..?
I'm having the same issue in Magento 2.1.5 :/
Same issue on Magento 2.1.10.
Most helpful comment
Here's a patch that fixes the issue:
The problem is the following. In
Magento\CatalogSearch\Model\Adapter\Mysql\Aggregation\DataProvider
in theexecute
-method thefetchAssoc
method is used to convert the query result into an associative array. ThefetchAssoc
method however uses the first column for the keys of the associated array. For all attribute aggregations the first column is always thevalue
column, as it should be. However for the category aggregation the first column for some reason is theentity_id
column, which is not unique. The fix consists thus in making thevalue
column the first column to be returned by the select.