0

What is the equivalent function in magento 2.

  public function execute()   //method name changed to execute() as per core
{
   //echo 'result controller';die;
    //Custom Change
     $params = $this->getRequest()->getParams();   
    $response = array(); 
    //Custom Change End

    //$query = Mage::helper('catalogsearch')->getQuery();
    $this->_objectManager->get('Magento\CatalogSearch\Helper\Data')->checkNotes();

    $this->layerResolver->create(Resolver::CATALOG_LAYER_SEARCH);
    $query = $this->_queryFactory->get();    


    /* @var $query Mage_CatalogSearch_Model_Query */

    //$query->setStoreId(Mage::app()->getStore()->getId());
    $query->setStoreId($this->_storeManager->getStore()->getId());  

    if ($query->getQueryText() != '')
    {
        //if (Mage::helper('catalogsearch')->isMinQueryLength()) {
        if ($this->_objectManager->get('Magento\Search\Helper\Data')->isMinQueryLength())
        {
              $query->setId(0)
                ->setIsActive(1)
                ->setIsProcessed(1); 
        }
        else {
            if ($query->getId()) { 
                $query->setPopularity($query->getPopularity()+1);
            }
            else {
                $query->setPopularity(1);
            }

            if ($query->getRedirect()){
                $query->save();
                $this->getResponse()->setRedirect($query->getRedirect());
                return;
            }
            else {
                $query->prepare();
            }
        }

        //Mage::helper('catalogsearch')->checkNotes();
        $this->_objectManager->get('Magento\Search\Helper\Data')->checkNotes();

        //$this->loadLayout();
        $this->_view->loadLayout();
        $this->_view->renderLayout(); 
        //Custom change

        if(false && $this->getRequest()->isXmlHttpRequest())
        {   //Check if it was an AJAX request
            $viewpanel = $this->getLayout()->getBlock('catalogsearch.leftnav')->toHtml();  //Get the new Layered Menu  
            $productlist = $this->getLayout()->getBlock('product_searchlist_toolbar')->toHtml(); //New product List
            $response['status'] = 'SUCCESS'; //Send Success
            $response['viewpanel']=$viewpanel;
            $response['productlist'] = $productlist;
            $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));
            return;
        }//End custom search
        //$this->_initLayoutMessages('catalog/session');
        //$this->_initLayoutMessages('checkout/session');
        //$this->renderLayout();

        /* if (!Mage::helper('catalogsearch')->isMinQueryLength()) {
            $query->save();
        } */            
        if (!$this->_objectManager->get('Magento\Search\Helper\Data')->isMinQueryLength()) {
            $query->save();  
        }
    }
    else {
        //$this->_redirectReferer();
       $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl());
    }
}

Like for eg: there is no getQuery() in magento 2 catalog search helper. i want the equivalent functions for the same in magento2

6
  • TL;DR: Inject \Magento\Search\Model\QueryFactory and get query with $this->queryFactory->get()->getQueryText(); Jun 27, 2016 at 8:05
  • Can yu please tell for other locs... i get Call to a member function $query->setStoreId($this->_storeManager->getStore()->getId()); on string
    – Sushivam
    Jun 27, 2016 at 8:13
  • I get a blank screen after searching..could you please help.. im using custom search engine..no products rendering...
    – Sushivam
    Jun 27, 2016 at 8:15
  • I don't understand the problem. In your code above, it seems impossible to me that $query contains a string. Please update your question with your actual code that produces the error, and the full error message. Jun 27, 2016 at 8:32
  • could you please help on this link :
    – Sushivam
    Jun 27, 2016 at 8:52

0

Browse other questions tagged or ask your own question.