0

I am experiencing a very strange issue on Magento (version 2.4).

Due to a mistake, we imported some incorrect products. To rectify this, we reimported the correct ones.

Now, all the products are correct, and the ecommerce works fine but the search function no longer works. When attempting to search for something, an error page is displayed.

enter image description here

I have attempted various solutions, including clearing the cache, reindexing, and so on.

It appears that something is broken, but I am unable to pinpoint the exact issue.

The code has not been modified, and the search function was working before this problem arose.

Here the logs about the issue:

 main.ERROR: Catalog Layer has been already created [] []
main.CRITICAL: RuntimeException: Catalog Layer has been already created in /var/www/magento/vendor/magento/module-catalog/Model/Layer/Resolver.php:54
Stack trace:
#0 /var/www/magento/vendor/magento/module-catalog-search/Controller/Result/Index.php(82): Magento\Catalog\Model\Layer\Resolver->create()
#1 /var/www/magento/vendor/magento/framework/Interception/Interceptor.php(58): Magento\CatalogSearch\Controller\Result\Index->execute()
#2 /var/www/magento/vendor/magento/framework/Interception/Interceptor.php(138): Magento\CatalogSearch\Controller\Result\Index\Interceptor->___callParent()
#3 /var/www/magento/vendor/magento/framework/Interception/Interceptor.php(153): Magento\CatalogSearch\Controller\Result\Index\Interceptor->Magento\Framework\Interception\{closure}()
#4 /var/www/magento/generated/code/Magento/CatalogSearch/Controller/Result/Index/Interceptor.php(23): Magento\CatalogSearch\Controller\Result\Index\Interceptor->___callPlugins()
#5 /var/www/magento/vendor/magento/framework/App/Action/Action.php(111): Magento\CatalogSearch\Controller\Result\Index\Interceptor->execute()
#6 /var/www/magento/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\App\Action\Action->dispatch()
#7 /var/www/magento/vendor/magento/framework/Interception/Interceptor.php(138): Magento\CatalogSearch\Controller\Result\Index\Interceptor->___callParent()
#8 /var/www/magento/vendor/magento/framework/Interception/Interceptor.php(153): Magento\CatalogSearch\Controller\Result\Index\Interceptor->Magento\Framework\Interception\{closure}()
#9 /var/www/magento/generated/code/Magento/CatalogSearch/Controller/Result/Index/Interceptor.php(32): Magento\CatalogSearch\Controller\Result\Index\Interceptor->___callPlugins()
#10 /var/www/magento/vendor/magento/framework/App/FrontController.php(245): Magento\CatalogSearch\Controller\Result\Index\Interceptor->dispatch()
#11 /var/www/magento/vendor/magento/framework/App/FrontController.php(212): Magento\Framework\App\FrontController->getActionResponse()
#12 /var/www/magento/vendor/magento/framework/App/FrontController.php(147): Magento\Framework\App\FrontController->processRequest()
#13 /var/www/magento/vendor/magento/framework/Interception/Interceptor.php(58): Magento\Framework\App\FrontController->dispatch()
#14 /var/www/magento/vendor/magento/framework/Interception/Interceptor.php(138): Magento\Framework\App\FrontController\Interceptor->___callParent()
#15 /var/www/magento/vendor/magento/module-store/App/FrontController/Plugin/RequestPreprocessor.php(99): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}()
#16 /var/www/magento/vendor/magento/framework/Interception/Interceptor.php(135): Magento\Store\App\FrontController\Plugin\RequestPreprocessor->aroundDispatch()
#17 /var/www/magento/vendor/amasty/aminvisiblecaptcha/Plugin/Framework/App/FrontControllerInterface/ValidateCaptcha.php(124): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}()
#18 /var/www/magento/vendor/magento/framework/Interception/Interceptor.php(135): Amasty\InvisibleCaptcha\Plugin\Framework\App\FrontControllerInterface\ValidateCaptcha->aroundDispatch()
#19 /var/www/magento/vendor/magento/module-page-cache/Model/App/FrontController/BuiltinPlugin.php(71): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}()
#20 /var/www/magento/vendor/magento/framework/Interception/Interceptor.php(135): Magento\PageCache\Model\App\FrontController\BuiltinPlugin->aroundDispatch()
#21 /var/www/magento/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}()
#22 /var/www/magento/generated/code/Magento/Framework/App/FrontController/Interceptor.php(23): Magento\Framework\App\FrontController\Interceptor->___callPlugins()
#23 /var/www/magento/vendor/magento/framework/App/Http.php(116): Magento\Framework\App\FrontController\Interceptor->dispatch()
#24 /var/www/magento/vendor/magento/framework/App/Bootstrap.php(264): Magento\Framework\App\Http->launch()
#25 /var/www/magento/pub/index.php(30): Magento\Framework\App\Bootstrap->run()

Could it be that something in the database has become corrupted?

Any idea?

1 Answer 1

0

For us it was Amasty_Finder (possibly when used together with Chessio_Matomo?), but it took way too much time to debug as it was hard to trigger this issue (never happened when I wanted to).

The major problem is that in the logs we seen only the core functionality trying to create the layer the second time, but no information about how it was created at first.

Therefore here is some help to find out what is the first call:

Temporary edit vendor\magento\module-catalog\Model\Layer\Resolver.php (added 4 code blocks):

public function create($layerType)
{

    // DEBUG: Add this line:
    $registry = \Magento\Framework\App\ObjectManager::getInstance()->get(\Magento\Framework\Registry::class);
    //

    if (isset($this->layer)) {

        // DEBUG: Add this line:
        \Magento\Framework\App\ObjectManager::getInstance()->get(\Psr\Log\LoggerInterface::class)->warning("\n1st run:\n".$registry->registry('layer_debug_backtrace')."\n2nd run:\n".((new \Exception)->getTraceAsString()));
        //
        throw new \RuntimeException('Catalog Layer has been already created');
    }
    if (!isset($this->layersPool[$layerType])) {
        throw new \InvalidArgumentException($layerType . ' does not belong to any registered layer');
    }
    $this->layer = $this->objectManager->create($this->layersPool[$layerType]);

    // DEBUG: Add this 2 lines:
    $layer_debug_backtrace = (new \Exception)->getTraceAsString();
    $registry->register('layer_debug_backtrace', "CREATE type: ".$layerType."\n".$layer_debug_backtrace);
    //
}

/**
 * Get current Catalog Layer
 *
 * @return \Magento\Catalog\Model\Layer
 */
public function get()
{
    if (!isset($this->layer)) {
        $this->layer = $this->objectManager->create($this->layersPool[self::CATALOG_LAYER_CATEGORY]);

        // DEBUG: Add this 3 lines:
        $registry = \Magento\Framework\App\ObjectManager::getInstance()->get(\Magento\Framework\Registry::class);
        $layer_debug_backtrace = (new \Exception)->getTraceAsString();
        $registry->register('layer_debug_backtrace', "GET\n".$layer_debug_backtrace);
        //
    }
    return $this->layer;
}

The output will be in /var/log/system.log once triggered.

For us, actually it was first created by the get() call in Amasty/Finder/Observer/LayoutRender.php.
I have checked that file many times, but I thought get call cannot be harmful... unless Magento logic creates the layer if not exist...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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