magento2-regenurl
magento2-regenurl copied to clipboard
Area code is not set
I tried to run the regen, but it resulted the following error:
[Magento\Framework\Exception\LocalizedException]
Area code is not set
Trying today on Mageno 2.1.7 | PHP 7 Same issue.
Same error here magento 2.1.8
Same error here magento 2.1.8
yeah, 2.1.9, Same issue.
Confirmed - issue is happening on 2.1.9 too.
@spyrule @samuidavid See the PR: https://github.com/Iazel/magento2-regenurl/pull/21
I changed de code like this PR and now is working, I don't know why it has not been merged yet.
I fix this issure: https://github.com/py4762013/magento2-regenurl
This is fixed in my fork, amongst other issues https://github.com/peterjaap/magento2-regenurl
@py4762013 & @peterjaap - Could you consider submitting a PR rather than forking an entirely new repo? It would help everyone contribute to a single source and keep things much easier to manage for the community :)
TL;DR; - There is a simple fix all the way at the bottom that will alleviate this error.
Tracking down the source of the issue - We are running into a problem on the getAreaCode() method inside execute().
% magento iazel:regenurl -vvv
[Magento\Framework\Exception\LocalizedException]
Area code is not set
Exception trace:
() at /home/vagrant/public_html/vendor/magento/framework/App/State.php:152
Magento\Framework\App\State->getAreaCode() at /home/vagrant/public_html/app/code/Iazel/RegenProductUrl/Console/Command/RegenerateProductUrlCommand.php:71
Magento will throw an exception if the area code isn't set:
In \Magento\Framework\App\State.php:
public function getAreaCode()
{
if (!isset($this->_areaCode)) {
throw new \Magento\Framework\Exception\LocalizedException(
new \Magento\Framework\Phrase('Area code is not set')
);
}
return $this->_areaCode;
}
Which makes the if (! $this->state->getAreaCode()) { conditional worthless here.
The values for area codes are set in Magento\Framework\App\Area.
const AREA_GLOBAL = 'global';
const AREA_FRONTEND = 'frontend';
const AREA_ADMINHTML = 'adminhtml';
const AREA_DOC = 'doc';
const AREA_CRONTAB = 'crontab';
const AREA_WEBAPI_REST = 'webapi_rest';
const AREA_WEBAPI_SOAP = 'webapi_soap';
/**
* @deprecated
*/
const AREA_ADMIN = 'admin';
I personally think that the best solution would be to allow for a CLI option to set which area code you'd like to use. I would assume the best 3 would AREA_GLOBAL, AREA_FRONTEND & AREA_ADMINHTML.
TL;DR;
For a quick fix, I replaced the conditional check for getAreaCode() within the exceute() function in RegenerageProductUrlCommand.php.
Replace:
if (!$this->state->getAreaCode()) {
$this->state->setAreaCode('admin');
}
With:
$this->state->setAreaCode(\Magento\Framework\App\Area::AREA_GLOBAL);
And the command proceeded to work without throwing an exception.
With all that being said, my URL's still did not regenerate correctly :)
@dambrogia I would consider it but this repo seems abandoned (10 outstanding pull requests and no sign from the repo owner for months). So it seems like a waste of time. Use my fork instead, that one works.