Create new file in local or override Layer model in local module
app/code/local/Mage/CatalogSearch/Model/Layer.php file and Change prepareProductCollection function
public function prepareProductCollection($collection)
{
if(Mage::helper('catalogsearch')->getQuery()->getQueryText())
{
$collection->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addSearchFilter(Mage::helper('catalogsearch')->getQuery()->getQueryText())
->setStore(Mage::app()->getStore())
->addMinimalPrice()
->addFinalPrice()
->addTaxPercents()
->addStoreFilter()
->addUrlRewrite();
}
else
{
$collection->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes());
$attributes = Mage::getSingleton('catalog/product')->getAttributes();
foreach($attributes as $attribute)
{
$attribute_code = $attribute->getAttributeCode();
if($attribute_code == "price")
continue;
if (empty($_REQUEST[$attribute_code])){continue;}
if(!empty($_REQUEST[$attribute_code]) && is_array($_REQUEST[$attribute_code]))
$collection->addAttributeToFilter($attribute_code, array('in' => $_REQUEST[$attribute_code]));
else
if(!empty($_REQUEST[$attribute_code]))
$collection->addAttributeToFilter($attribute_code, array('like' => "%" . $_REQUEST[$attribute_code] . "%"));
}
$collection->setStore(Mage::app()->getStore())
->addMinimalPrice()
->addFinalPrice()
->addTaxPercents()
->addStoreFilter()
->addUrlRewrite();
Mage::getSingleton('catalogsearch/advanced')->prepareProductCollection($collection);
}
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($collection);
return $this;
}
After that do same with app/code/local/Mage/CatalogSearch/Model/Advanced.php and change getProductCollection and getSearchCriterias functions
public function getProductCollection()
{
if (is_null($this->_productCollection)) {
$this->_productCollection = Mage::getResourceModel('catalogsearch/advanced_collection')
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addMinimalPrice()
->addStoreFilter();
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($this->_productCollection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($this->_productCollection);
if(isset($_GET['cat']) && is_numeric($_GET['cat']))
$this->_productCollection->addCategoryFilter(Mage::getModel('catalog/category')->load($_GET['cat']),true);
}
return $this->_productCollection;
}
public function getSearchCriterias()
{
$search = $this->_searchCriterias;
if(isset($_GET['cat']) && is_numeric($_GET['cat'])){
$category = Mage::getModel('catalog/category')->load($_GET['cat']);
$search[] = array('name'=>'Category','value'=>$category->getName());
}
return $search;
}
Here in below layer navigation is prepared for advance search product collection now must display that layer navigation using theme xml file so edit your theme's catalogsearch.xml file and add below code in tag.
<reference name="left">
<block type="catalogsearch/layer" name="catalogsearch.leftnav" after="currency" template="catalog/layer/view.phtml"/>
</reference>
For More information
visit this link
The steps to resolve this issue after migrating is first to open the attribute and save it again, this will set the type from text to varchar. After this run the SQL below to copy all data from the text to the varchar table.
INSERT INTO catalog_product_entity_varchar
(store_id, attribute_id, entity_id, value)
SELECT store_id, attribute_id, entity_id, value
FROM catalog_product_entity_text
WHERE catalog_product_entity_text.attribute_id = {your attribute id}
AND catalog_product_entity_text.value is not null;
Now delete the data from the text table
DELETE FROM `catalog_product_entity_text`
WHERE `attribute_id` = {your attribute id}
Run in terminal
- php magento2/bin/magento indexer:reindex
- php magento2/bin/magento cache:flush
If the reindex is giving a duplication error, search for the entity_id in the catalog_product_entity_varchar table and check if there is a duplicate value for the attribute id in the field.
Best Answer
There are 2 methods to achieve this
First one
Filter.php (api model)
Sample out put of this code will be:
Second method