Retrieve a list of all is_visible_in_advanced_search filter product attribute list in Magento 2.
This article returns all those product attributes which are used in the advanced search result page.
To get a list of attributes, We need to use CollectionFactory Object from the Catalog Module.
Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory
<?php
namespace Jesadiya\AdvancedSearch\Model;
use Magento\Framework\DataObject;
use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory;
class AdvancedSearchAttribute
{
/**
* @var CollectionFactory
*/
private $collectionFactory;
public function __construct(
CollectionFactory $collectionFactory
) {
$this->collectionFactory = $collectionFactory;
}
/**
* advanced search attribute
* @return DataObject[]
*/
public function getAdvancedSearchAttribute()
{
$searchableAttributes = $this->collectionFactory
->create()
->addDisplayInAdvancedSearchFilter()
->getItems();
return $searchableAttributes;
}
}
Call method to fetch a list of attributes object, iterate a loop over it, and get all the attribute code,
$searchableAttributes = $this->getAdvancedSearchAttribute();
foreach ($searchableAttributes as $attribute) {
echo $attribute->getAttributeCode();
echo "<br>";
}
The Output will be an attribute of name, SKU, description, and price and you have enabled all the advanced search to enable from the Product attribute.
