2

I have created a command for my module which calls a class Model/Importer from https://github.com/firegento/FireGento_FastSimpleImport2 extension. but i think it requires admin session.

I have tried to add area code by referring to this question 'Area code not set' issue in custom CLI commands in Magento 2

But still after clearing everything from var folder, i am getting the same exception.

Taral Patoliya
  • 1,576
  • 2
  • 16
  • 44
  • http://tagvibe.com/magento2/how-to-fix-the-area-code-not-set-issue/ Check this URL to fix the area code exception in Magento 2 – rajat kara Apr 20 '21 at 10:29

1 Answers1

3
#File: vendor/magento/framework/App/State.php

If you debug the above file,Magento\Framework\App\State object will only let you set a value once. As you know a command line scripts has no area.

Below code should pass the Area code not set exceptions.

When I was trying for the same, I did get the below working code from somewhere. It was working for me few days ago.

  public function __construct(
    \Magento\Framework\App\State $appState,
    $name=null
)
{
    $appState->setAreaCode('frontend');
    parent::__construct($name);
}
Vishwas Soni
  • 1,567
  • 14
  • 34