Get all the attributes which are used in layered navigation in category & search page.
You can get all the filterable attribute list from Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory 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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<?php private $checkoutSession; public function __construct( \Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory $productAttributeCollectionFactory ) { $this->productAttributeCollectionFactory = $productAttributeCollectionFactory; } public function getFilterableAttributes() { /** @var \Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection $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,
1 2 3 4 5 |
$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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
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 |
Please follow the below methods to get the attribute options...
Update product attribute value programmatically in Magento 2 . [crayon-62877793a166c698356640/]...
If you want restrict customer to checkout based on your...
Sometime we need to set html data without load or...
If you want get query string params in controller file,...