Affected File : app/code/core/Mage/CatalogSearch/Model/Layer.php
Below function is changed.
public function prepareProductCollection($collection)
{
$collection
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addSearchFilter(Mage::helper('catalogsearch')->getQuery()->getQueryText())
->setStore(Mage::app()->getStore())
->addMinimalPrice()
->addFinalPrice()
->addTaxPercents()
->addStoreFilter()
->addUrlRewrite();
/*================== condition added ==========================*/
$product = Mage::getModel('catalog/product')
->loadByAttribute('name', Mage::helper('catalogsearch')->getQuery()->getQueryText());
if($product && ($product->getStoreId() == Mage::app()->getStore()->getStoreId()))
{
//Below 3 lines of code redirects to the product details page
$url = $product->getProductUrl();
Mage::app()->getFrontController()->getResponse()->setRedirect($url);
return;
//Comment above 3 lines of code to stop redirects to the product details page
//And uncomment below line to filter collection by product name exactly
//$collection->addAttributeToFilter('name', array('eq' => Mage::helper('catalogsearch')->getQuery()->getQueryText()));
}
/*=============================================================*/
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($collection);
return $this;
}
Below function is changed.
public function prepareProductCollection($collection)
{
$collection
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addSearchFilter(Mage::helper('catalogsearch')->getQuery()->getQueryText())
->setStore(Mage::app()->getStore())
->addMinimalPrice()
->addFinalPrice()
->addTaxPercents()
->addStoreFilter()
->addUrlRewrite();
/*================== condition added ==========================*/
$product = Mage::getModel('catalog/product')
->loadByAttribute('name', Mage::helper('catalogsearch')->getQuery()->getQueryText());
if($product && ($product->getStoreId() == Mage::app()->getStore()->getStoreId()))
{
//Below 3 lines of code redirects to the product details page
$url = $product->getProductUrl();
Mage::app()->getFrontController()->getResponse()->setRedirect($url);
return;
//Comment above 3 lines of code to stop redirects to the product details page
//And uncomment below line to filter collection by product name exactly
//$collection->addAttributeToFilter('name', array('eq' => Mage::helper('catalogsearch')->getQuery()->getQueryText()));
}
/*=============================================================*/
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($collection);
return $this;
}
Magento 2 One step checkout is the best Magento 2 extension
ReplyDeleteIdeas for B2B marketing and free retail trade publications uk are now available in Omnichannelgal blog
ReplyDeleteKeep track of inventory are now available in Lamar blog
Inventory Turnover Rate for Retail is in Omnichannelly blog
Read What can i sell online in australia in Magentdev blog
https://blog.magestore.com/magento-download/
ReplyDeletehttps://blog.magestore.com/aheadworks-partnership/