When setting the session for customer or Order gets this Area code not set error:

vendor/magento/framework/Session/SessionManager.php line 175: Area code not set: Area code must be set before starting a session

Area code not set: Area code must be set before starting a session

After some research, I found out it was related to which area of Magento 2 you want to have your session related to.

You can use either “frontend” or “admin”. Find below the two implementations:

$objectManager = Magento\Framework\App\ObjectManager::getInstance();
$objectManager->get('Magento\Framework\App\State')
            ->setAreaCode('frontend');

 

It’s Fixed related to this :

  • Magento 2.2 area code not set: area code must be set before starting a session.
  • upgrading data.. area code not set: area code must be set before starting a session.
  • Magento 2 setup upgrade import failed: area code is not set
  • import failed: area code not set: area code must be set before starting a session.
  • Magento 2 area code admin does not exist
  • processing configurations data from configuration file… import failed: area code is not set
  • import failed: area code is not set magento2
  • area code “” does not exist Magento 2