Skip to content

Magento 2.2 fix Home Page error if store view is not defined #11453

@selusi

Description

@selusi

Preconditions

  1. PHP 7.0.2
  2. Ubuntu 17.4
  3. Apache 2.4
  4. MySql 5.7

Steps to reproduce

  1. Create and enable at least 2 store views in Stores->All Stores.
  2. In Stores->Configuration->General->Web set Add Store Code to Urls = Yes
  3. Delete all cookie from browser
  4. Go to Home Page of your store

Expected result

  1. View the home page of default store view

Actual result

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

To fix the issue

Must change the method getStore() in Magento\Store\Model\StoreManager.
To avoid home page error in frontend. If $storeId is not defined: It retrive data from COOKIE first, otherwise return the default store code.
At line 164 add the below patch:

		if(!$storeId){
			if(isset($_COOKIE['store']) && $_COOKIE['store'] !== ''){
				$storeId = $_COOKIE['store'];
			} else {
				$storeId = $this->getDefaultStoreView()->getCode();
			}			
		}

Metadata

Metadata

Assignees

Labels

Issue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions