magento2: Filtering catalog by non-anchor category throws "Bucket does not exist" exception
Preconditions
- Magento Open Source 2.2.2 with sample data installed
- One of the catalog sub-categories (e.g. Women > Tops > Hoodies & Sweatshirts) is configured to not be anchored (“Anchor” set to “No”)
Steps to reproduce
- Navigate to a parent category of the configured sub-category (e.g. Women > Tops) on the frontend
- In the layered navigation filters, filter by the configured sub-category (e.g. Hoodies & Sweatshirts)
Expected result
- The category page refreshes, with the sub-category filter applied
Actual result
(Magento\Framework\Exception\StateException): Bucket does not exist exception is thrown.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 4
- Comments: 27 (6 by maintainers)
@tgerulaitis, thank you for your report. We’ve acknowledged the issue and added to our backlog.
You have to set the Root category to Anchored -> ‘Yes’. If it is set already as ‘Yes’, you have set it again to ‘No’ and ‘Save’ and then again into ‘Yes’ -> ‘Save’. This should resolve your problem.
This is a known issue in Magento2.
Hmm, I’ve also tried a few different environments and so far was only able to replicate it in Docker, so it’s not out of the question. However, from the debugging I’ve done so far I don’t see how the environment could affect this. Looking at the code:
\Magento\Framework\Api\Search\SearchCriteriaBuilderreturns two separate filters for categories - one from the category page collection, and one from the layered navigation filter.\Magento\Framework\Search\Search:65the filters are added to the search request builder, but since the two category filters have the same field (category_ids), only the latter one is added to the builder.\Magento\Framework\Search\Adapter\Mysql\Adaptercreates aggregations in line 84, an empty array is returned because\Magento\CatalogSearch\Model\Adapter\Aggregation\Checker\Query\CatalogView::isApplicablemethod only returns aggregations for categories that are anchored and it only checks the category added by the filter (not the category page collection).\Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection::getFacetedDatalooks for category aggregations in the search result, but none were returned, so an exception is thrown.None of this code seems to be dependent on any environment settings, so I’m still not sure how to fix it (other than making all categories anchored as suggested somebody else’s stackexchange question).
I’ll try and get another environment set up locally that doesn’t experience this bug so I can debug and see what’s different.