infrangible / m2-catalog-attribute-filter-hidden
Adds a "Filterable (hidden)" option for product attributes: products can be filtered by the attribute through links, while the filter stays invisible in layered navigation.
Package info
github.com/infrangible-dev/m2-catalog-attribute-filter-hidden
Type:magento2-module
pkg:composer/infrangible/m2-catalog-attribute-filter-hidden
Requires
- php: >=8.1
- fewedev/base: ~2.4.3
- infrangible/m2-foundation: ~3.0.2
- magento/framework: ~103.0.6
- magento/module-backend: ~102.0.6
- magento/module-catalog: ~104.0.6
- magento/module-catalog-search: ~102.0.6
- magento/module-eav: ~102.1.6
- magento/module-layered-navigation: ~100.4.6
Requires (Dev)
- infrangible/phpstan-magento: ~1.2.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Adds the option "Filterable (hidden)" to "Use in Layered Navigation" of product attributes: products can be filtered by the attribute through links, while the filter stays invisible in layered navigation.
Behavior
In Magento, an attribute is either shown in layered navigation or cannot be used to filter the product list. Links to pre-filtered product lists (campaigns, menu entries, landing pages) need the filter without offering it to the shoppers.
- Stores > Attributes > Product, tab "Storefront Properties": the field "Use in Layered Navigation" gets the option "Filterable (hidden)", next to "No", "Filterable (with results)" and "Filterable (no results)". The column of the attribute grid shows it and can be filtered by it.
- On category pages, an attribute with this option filters the products like a visible filter when its value is in the
address, for example
/gear/bags.html?brand=12(the option ID of the value) or?price=30-40for a hidden price filter. - Layered navigation does not show the filter. If no other filter is left, Magento hides the block.
- "Now Shopping by" does not show the active hidden filter, and "Clear All" keeps it, so shoppers cannot remove it by accident.
- Search result pages use the attributes with "Use in Search Results Layered Navigation" set to "Yes". A hidden attribute filters there too if that field is "Yes"; its filter stays invisible in both cases.
Magento builds the search request of the category pages only with the attributes that are shown in layered navigation. The module adds the hidden attributes to it (filter and aggregation), so their links filter the products and Magento does not log "The bucket doesn't exist".
The filters are hidden in the layered navigation of Luma and of themes that use Magento's layered navigation block (Hyvä as well). The GraphQL API is not changed: it returns hidden attributes in the aggregations like other filterable attributes.
Requirements
- Magento Open Source or Adobe Commerce 2.4.6 or newer
- PHP 8.1 or newer
Installation
composer require infrangible/m2-catalog-attribute-filter-hidden bin/magento module:enable Infrangible_CatalogAttributeFilterHidden bin/magento setup:upgrade
In production mode, also run bin/magento setup:di:compile.
After changing "Use in Layered Navigation" of an attribute, reindex as usual and flush the cache: Magento keeps the search requests in the configuration cache.
License
Infrangible Catalog Attribute Filter Hidden is licensed under the MIT License - see the LICENSE file for details.