Get all the attributes which are used in layered navigation in category & search page.
You can get all the filterable attribute list from MagentoCatalogModelResourceModelProductAttributeCollectionFactory class.
As a result, you will get that,
all those attributes which have been used in Layered Navigation status are Filterable (with results) or Filterable (no results).
So, you need to create __construct( ) function for define dependency of Class.
<?php
private $checkoutSession;
public function __construct(
MagentoCatalogModelResourceModelProductAttributeCollectionFactory $productAttributeCollectionFactory
) {
$this->productAttributeCollectionFactory = $productAttributeCollectionFactory;
}
public function getFilterableAttributes()
{
/** @var MagentoCatalogModelResourceModelProductAttributeCollection $productAttributes */
$productAttributes = $this->productAttributeCollectionFactory->create();
$productAttributes->addFieldToFilter(
['is_filterable', 'is_filterable_in_search'],
[[1, 2], 1]
);
return $productAttributes;
}
Now call a function in template file by iterating over a loop to fetch each attribute code,
$getAttributes = $block->getFilterableAttributes();
foreach ($getAttributes as $attribute) {
echo $attribute->getAttributeCode();echo "<br>";
}
You can get all the filterable attribute used for your store.
The Result
price
manufacturer
color
activity
style_bags
material
strap_bags
features_bags
gender
category_gear
size
eco_collection
performance_fabric
erin_recommends
new
sale
format
style_bottom
style_general
sleeve
collar
pattern
climate

