2

I have staging server with Magento 2 installed in it's subfolder ( xxx.xxx.xxx.xxx/magento/ ) and I have enabled "Add Store Code to Urls" option. When I open my site on staging - http://xxx.xxx.xxx.xxx/magento/, I get error:

1 exception(s):
Exception #0 (Magento\Framework\Exception\NoSuchEntityException): Requested store is not found

Exception #0 (Magento\Framework\Exception\NoSuchEntityException): Requested store is not found
#0 /var/www/html/magento/vendor/magento/module-store/Model/StoreManager.php(168): Magento\Store\Model\StoreRepository->get('')
#1 /var/www/html/magento/generated/code/Magento/Store/Model/StoreManagerInterface/Proxy.php(119): Magento\Store\Model\StoreManager->getStore('')
#2 /var/www/html/magento/vendor/magento/module-store/Model/Resolver/Store.php(29): Magento\Store\Model\StoreManagerInterface\Proxy->getStore(NULL)
#3 /var/www/html/magento/vendor/magento/framework/App/Config/ScopeCodeResolver.php(49): Magento\Store\Model\Resolver\Store->getScope(NULL)
#4 /var/www/html/magento/vendor/magento/framework/App/Config.php(69): Magento\Framework\App\Config\ScopeCodeResolver->resolve('stores', NULL)
#5 /var/www/html/magento/vendor/magento/framework/View/DesignExceptions.php(76): Magento\Framework\App\Config->getValue('design/theme/ua...', 'stores')
#6 /var/www/html/magento/vendor/magento/module-page-cache/Model/App/CacheIdentifierPlugin.php(43): Magento\Framework\View\DesignExceptions->getThemeByRequest(Object(Magento\Framework\App\Request\Http))
#7 /var/www/html/magento/vendor/magento/framework/Interception/Interceptor.php(146): Magento\PageCache\Model\App\CacheIdentifierPlugin->afterGetValue(Object(Magento\Framework\App\PageCache\Identifier\Interceptor), 'ec6287a9f53f52f...')
#8 /var/www/html/magento/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\App\PageCache\Identifier\Interceptor->Magento\Framework\Interception\{closure}()
#9 /var/www/html/magento/generated/code/Magento/Framework/App/PageCache/Identifier/Interceptor.php(26): Magento\Framework\App\PageCache\Identifier\Interceptor->___callPlugins('getValue', Array, Array)
#10 /var/www/html/magento/vendor/magento/framework/App/PageCache/Kernel.php(115): Magento\Framework\App\PageCache\Identifier\Interceptor->getValue()
#11 /var/www/html/magento/vendor/magento/module-page-cache/Model/App/FrontController/BuiltinPlugin.php(71): Magento\Framework\App\PageCache\Kernel->load()
#12 /var/www/html/magento/vendor/magento/framework/Interception/Interceptor.php(135): Magento\PageCache\Model\App\FrontController\BuiltinPlugin->aroundDispatch(Object(Magento\Framework\App\FrontController\Interceptor), Object(Closure), Object(Magento\Framework\App\Request\Http))
#13 /var/www/html/magento/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}(Object(Magento\Framework\App\Request\Http))
#14 /var/www/html/magento/generated/code/Magento/Framework/App/FrontController/Interceptor.php(26): Magento\Framework\App\FrontController\Interceptor->___callPlugins('dispatch', Array, Array)
#15 /var/www/html/magento/vendor/magento/framework/App/Http.php(135): Magento\Framework\App\FrontController\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#16 /var/www/html/magento/generated/code/Magento/Framework/App/Http/Interceptor.php(24): Magento\Framework\App\Http->launch()
#17 /var/www/html/magento/vendor/magento/framework/App/Bootstrap.php(256): Magento\Framework\App\Http\Interceptor->launch()
#18 /var/www/html/magento/index.php(39): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http\Interceptor))
#19 {main}

So I have to manually specify store view code in URL to get the site working: http://xxx.xxx.xxx.xxx/magento/en/

If I disable "Add Store Code to Urls", everything works ok. On live server , where magento is in root of the domain, everything works in both cases (if option is disabled or enabled).

Why is it so? How to get Magento 2 working while it is in server's subfolder?

Magento 2.2.2

1 Answer 1

2

To Solve this error ,you have to modify StoreManager.php (/vendor/magento/module-store/Model/StoreManager.php)

If $storeId is not defined: It retrive data from COOKIE first, otherwise return the default store code. Arround line 154 replace with the below patch:

if (!isset($storeId) || '' === $storeId || $storeId === true) {
            if (null === $this->currentStoreId) {
                \Magento\Framework\Profiler::start('store.resolve');
                $this->currentStoreId = $this->storeResolver->getCurrentStoreId();
                \Magento\Framework\Profiler::stop('store.resolve');
            }
            $storeId = $this->currentStoreId;
        }

TO

 if(!$storeId){
            if(isset($_COOKIE['store']) && $_COOKIE['store'] !== ''){
                $storeId = $_COOKIE['store'];
            } else {
                $storeId = $this->getDefaultStoreView()->getCode();
            }           
        } 
1
  • It's not even working. PHP Fatal error: Uncaught Error: Call to a member function getCode() on null in /opt/lampp/htdocs/mm_dev/vendor/magento/module-store/Model/StoreManager.php:160 Jul 29, 2019 at 13:00

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.