0

I've created a 2.2.4 magento website a few month ago. My client wanted to clone this website, in order to have 2 different databases but keep all the fonctionnalities.

So I've cloned this website, updated the catalog etc...

Everything works fine, except the catalog research. I'm having a blank page each time I do the search.

I saw nothing in the php, apache, mysql or magento log (system or debug)...

This is the source code that I have :

enter image description here

EDIT : after digging into my log, those error are thrown but not on the search page (so, I guess it's stopping before). This is similar to another issue, I tried removing some block in my Magento_Theme::default.xml file, but I still have the white screen...

enter image description here

4
  • if you don't see anything in log, it's time to start debugging, like when you hit enter to search, what route/controller handles the search for you.
    – Jimmy
    Apr 23 at 1:40
  • where do I see that ? by the CLI ? Apr 23 at 6:36
  • so you are not Magento developer then, this is a technical issue, you should have someone checked it for you
    – Jimmy
    Apr 23 at 6:40
  • I'm alone to check thoses issues. I've never have any issues like that, don't know where to look at Apr 23 at 6:50
0

Found the solution ! I had to overwrite the initial controller that does the search. Indeed, after cloning my projet, some of the initial code from the controller made only white page. I never thought that the core could be so affected. This is the code I'm talking about

  $this->_view->loadLayout();
  $this->_view->renderLayout();

And this is how I fixed it. i had to to replace it by a page factory. I have no idea why it stopped working, but page factory fixed it.

in vendor/module/etc/di.xml

<preference for="Magento\CatalogSearch\Controller\Result\Index" type="Vendor\Module\Controller\SearchResult\Index"/>

And the controller in vendor/module/Controller/SearchResult/Index.php

class Index extends \Magento\Framework\App\Action\Action
{
    /**
     * Catalog session
     *
     * @var Session
     */
    protected $_catalogSession;

    /**
     * @var StoreManagerInterface
     */
    protected $_storeManager;

    /**
     * @var QueryFactory
     */
    private $_queryFactory;

    /**
     * Catalog Layer Resolver
     *
     * @var Resolver
     */
    private $layerResolver;

    /**
     * @var PageFactory
     */
    protected $pageFactory;

    /**
     * @param Context $context
     * @param Session $catalogSession
     * @param StoreManagerInterface $storeManager
     * @param QueryFactory $queryFactory
     * @param Resolver $layerResolver
     */
    public function __construct(
        Context $context,
        Session $catalogSession,
        StoreManagerInterface $storeManager,
        QueryFactory $queryFactory,
        Resolver $layerResolver,
        PageFactory $pageFactory
    ) {
        parent::__construct($context);
        $this->_storeManager = $storeManager;
        $this->_catalogSession = $catalogSession;
        $this->_queryFactory = $queryFactory;
        $this->layerResolver = $layerResolver;
        $this->pageFactory = $pageFactory;
    }

    /**
     * Display search result
     *
     * @return void
     *
     * @throws \Magento\Framework\Exception\LocalizedException
     */
    public function execute()
    {
        $this->layerResolver->create(Resolver::CATALOG_LAYER_SEARCH);

        /* @var $query \Magento\Search\Model\Query */
        $query = $this->_queryFactory->get();

        $storeId = $this->_storeManager->getStore()->getId();
        $query->setStoreId($storeId);

        $queryText = $query->getQueryText();

        if ($queryText != '') {
            $catalogSearchHelper = $this->_objectManager->get(\Magento\CatalogSearch\Helper\Data::class);

            $getAdditionalRequestParameters = $this->getRequest()->getParams();
            unset($getAdditionalRequestParameters[QueryFactory::QUERY_VAR_NAME]);

            if (empty($getAdditionalRequestParameters) &&
                $this->_objectManager->get(PopularSearchTerms::class)->isCacheable($queryText, $storeId)
            ) {
                $this->getCacheableResult($catalogSearchHelper, $query);
            } else {
                $this->getNotCacheableResult($catalogSearchHelper, $query);
            }
        } else {
            $this->getResponse()->setRedirect($this->_redirect->getRedirectUrl());
        }
        return $this->pageFactory->create();
    }

    /**
     * Return cacheable result
     *
     * @param \Magento\CatalogSearch\Helper\Data $catalogSearchHelper
     * @param \Magento\Search\Model\Query $query
     * @return void
     */
    private function getCacheableResult($catalogSearchHelper, $query)
    {
        if (!$catalogSearchHelper->isMinQueryLength()) {
            $redirect = $query->getRedirect();
            if ($redirect && $this->_url->getCurrentUrl() !== $redirect) {
                $this->getResponse()->setRedirect($redirect);
                return;
            }
        }

        $catalogSearchHelper->checkNotes();

        return $this->pageFactory->create();
    }

    /**
     * Return not cacheable result
     *
     * @param \Magento\CatalogSearch\Helper\Data $catalogSearchHelper
     * @param \Magento\Search\Model\Query $query
     * @return void
     *
     * @throws \Magento\Framework\Exception\LocalizedException
     */
    private function getNotCacheableResult($catalogSearchHelper, $query)
    {
        if ($catalogSearchHelper->isMinQueryLength()) {
            $query->setId(0)->setIsActive(1)->setIsProcessed(1);
        } else {
            $query->saveIncrementalPopularity();
            $redirect = $query->getRedirect();
            if ($redirect && $this->_url->getCurrentUrl() !== $redirect) {
                $this->getResponse()->setRedirect($redirect);
                return;
            }
        }

        $catalogSearchHelper->checkNotes();

        return $this->pageFactory->create();
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.