Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
selusi opened this issue Oct 14, 2017 · 11 comments
Closed

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

selusi opened this issue Oct 14, 2017 · 11 comments
Assignees
Labels
Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release

Comments

@selusi
Copy link

selusi commented Oct 14, 2017

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();
			}			
		}
@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Oct 14, 2017
@selusi selusi changed the title Magento 2.2 fix Home Page error if not store view is setted Magento 2.2 fix Home Page error if store view is not defined Oct 14, 2017
@orlangur
Copy link
Contributor

Patch does not look good to me. On line 168 $storeId must already have a valid value.

Obtaining default store code logic is placed in $this->currentStoreId = $this->storeResolver->getCurrentStoreId();.

@selusi
Copy link
Author

selusi commented Oct 16, 2017

@orlangur You have right .
A better solution is to change 155 line of Magento\Store\Model\StoreManager:

from

if (null === $this->currentStoreId) {

to (solution 1)

if (null === $this->currentStoreId || '' === $this->currentStoreId) {

or shortest (solution 2 as in Magento 2.1.9 version)

if (!$this->currentStoreId) {

This works well for me, though there has to be a reason why this line has been modified in Magento 2.2.0 version, but I still do not understand why. Probably because the 'store_id' of the administration panel is '0', in this case solution 1 should be better.

Sicurly the null value of $this->currentStoreId has a sense on reinitStores() method but there must be another point where the variable $this -> currentStoreId is initialized to an empty value.

@magento-engcom-team magento-engcom-team added Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed 2.2.x Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Oct 17, 2017
@magento-engcom-team
Copy link
Contributor

@selusi, thank you for your report.
We've created internal ticket(s) MAGETWO-82103 to track progress on the issue.

@sbaixauli
Copy link

I am working on it at #mm17es

@sbaixauli
Copy link

Impossible to reproduce the error.

Magento Version: 2.2.1-dev
Add Store Code to Urls = Yes
Remove Cache, etc = Yes

Open url in a new browser and type url with store code and every thing works properly. No one modified this file '/app/code/Magento/Store/Model/StoreManager.php' since 5/8/17, so maybe someone fix it in a high level.

@dmanners
Copy link
Contributor

dmanners commented Nov 4, 2017

I think this was solved with #11337

@selusi
Copy link
Author

selusi commented Nov 9, 2017

@sbaixauli the error is only displayed if you type a url without a store code.
es: http://www.mystore.com

@ci2014
Copy link

ci2014 commented Feb 14, 2018

Caution:

Please note that it even appears, if the home page is generally working, but if you go to the home page with a GET Parameter, any Query String will cause that error. That means you will have big trouble with Google AdWords, because GA adds a Query String to the URL, when clicking the link.

This is quite serious in my opinion.

@elvinristi
Copy link
Contributor

elvinristi commented Mar 7, 2018

@selusi 's provided fix helped

-            if (null === $this->currentStoreId) {
+            if (null === $this->currentStoreId || '' === $this->currentStoreId) {

@kashif-folio3
Copy link

kashif-folio3 commented Apr 12, 2018

The below fix, will hide the buttons "add root category" and "add sub category" under admin->categories...

            if(!$storeId){

		if(isset($_COOKIE['store']) && $_COOKIE['store'] !== ''){

			$storeId = $_COOKIE['store'];

		} else {

			$storeId = $this->getDefaultStoreView()->getCode();

		}			

	 }

So, plz go with following solution with little change.

	if(!$storeId){

		if(isset($_COOKIE['store']) && $_COOKIE['store'] !== ''){

			$storeId = $_COOKIE['store'];

		} else {

			$storeId = 0;

		}			

	}

Thanks,

@okorshenko okorshenko removed the mm17es label Jun 5, 2018
@magento-engcom-team
Copy link
Contributor

Hi @selusi

This issue seems to be fixed already. Please use #11337 as a reference.

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

No branches or pull requests

10 participants