Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Category Layered Filter Issue #2121

Closed
kost08 opened this issue Oct 15, 2015 · 28 comments
Closed

Category Layered Filter Issue #2121

kost08 opened this issue Oct 15, 2015 · 28 comments
Assignees
Labels
bug report Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development

Comments

@kost08
Copy link

kost08 commented Oct 15, 2015

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.
1
But $optionsFacetedData is an array of Categories which are children of the $categories
2
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.

@kost08 kost08 changed the title Category Layred Filyer Category Layered Filter Issue Oct 15, 2015
@magebay99
Copy link

why not using isotope filtering?

@davidalger
Copy link
Member

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.

@psol7
Copy link

psol7 commented Feb 7, 2016

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.

@kandy kandy added the MX label Feb 7, 2016
@kandy kandy self-assigned this Feb 7, 2016
@kandy kandy reopened this Feb 7, 2016
@RakeshJesadiya
Copy link
Contributor

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?

@ktruehl
Copy link

ktruehl commented Apr 29, 2016

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.

@psol7
Copy link

psol7 commented Apr 29, 2016

Right on ktruehl. Problem fixed. Thks.

@choukalos
Copy link

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.

@Krapulat
Copy link

Krapulat commented May 2, 2016

Thanks @ktruehl, your fix works perfectly.

@maghamed
Copy link
Contributor

maghamed commented May 4, 2016

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

@mwsanders0
Copy link

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?

@maghamed
Copy link
Contributor

It didn't get to 2.0.3. Now it's going to be delivered in the scope of 2.0.7 Patch release

@ghost
Copy link

ghost commented Jun 7, 2016

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.

mage2categorybug

@w3prodigy
Copy link

Thanks for the fix @ktruehl

@blizam
Copy link

blizam commented Jun 13, 2016

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

@blizam
Copy link

blizam commented Jun 14, 2016

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

@blizam
Copy link

blizam commented Jun 14, 2016

#5009

@maghamed
Copy link
Contributor

Internal issue created - MAGETWO-54383

@rgoncharuk rgoncharuk added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Jun 22, 2016
@KrystynaKabannyk
Copy link

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.

@vivek-ted
Copy link

Thank you all, its helped me lot.

@kost08 thanks for the post.

@pitangaweb
Copy link

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.

@jpcsguru
Copy link

jpcsguru commented Jun 4, 2017

this is still present in 2.1.6

@jamiejackson1183
Copy link

Also having same issue in 2.1.3 Enterprise

@btwq
Copy link

btwq commented Jul 26, 2017

Having similar issues in 2.1.7

Valid subcategories are not appearing in layered navigation "Category" section of a parent category page

@ci2014
Copy link

ci2014 commented Oct 26, 2017

Still present in 2.2.0

@magento-engcom-team magento-engcom-team added the Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed label Oct 26, 2017
@allyreflections
Copy link

I have the same issue in Magento 2.1.7. Any fix on this issue..?

@rnkings
Copy link

rnkings commented Jan 2, 2018

I'm having the same issue in Magento 2.1.5 :/

@SilvanLaroo
Copy link

Same issue on Magento 2.1.10.

magento-engcom-team pushed a commit that referenced this issue Feb 26, 2018
@alexvais
Copy link

alexvais commented Sep 22, 2021

i think that this issue is related to "isOptionReducesResults" method.

I had the same issue when you have a parent category, for example "furniture" and inside "chairs" and "tables"

If all searched items are inside "furniture", this option is not showed because for Magento 2 have no sense show an option to filter where all the products are inside.

BUT this also do not allow the customer to filter on the subcategories.

If you want show it anyways you have to delete "isOptionReducesResults" check from here "vendor/magento/module-catalog-search/Model/Layer/Filter/Category.php"

` protected function _getItemsData()
    {
        $productCollection = $this->getLayer()->getProductCollection();
        $optionsFacetedData = $productCollection->getFacetedData('category');
        $category = $this->dataProvider->getCategory();
        $categories = $category->getChildrenCategories();

        $collectionSize = $productCollection->getSize();

        if ($category->getIsActive()) {
            foreach ($categories as $category) {
                if ($category->getIsActive()
                    && isset($optionsFacetedData[$category->getId()])
                    && $this->isOptionReducesResults($optionsFacetedData[$category->getId()]['count'], $collectionSize)
                ) {
                    $this->itemDataBuilder->addItemData(
                        $this->escaper->escapeHtml($category->getName()),
                        $category->getId(),
                        $optionsFacetedData[$category->getId()]['count']
                    );
                }
            }
        }
        return $this->itemDataBuilder->build();
    }`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development
Projects
None yet
Development

No branches or pull requests