skip to Main Content

this is the error.

Fatal error: Uncaught MagentoFrameworkExceptionLocalizedException: Area code is not set in /var/www/html/magento22/vendor/magento/framework/App/State.php:152 Stack trace: #0 /var/www/html/magento22/vendor/magento/framework/Session/SessionManager.php(173): MagentoFrameworkAppState->getAreaCode() #1 /var/www/html/magento22/generated/code/Magento/Framework/Session/Generic/Interceptor.php(50): MagentoFrameworkSessionSessionManager->start() #2 /var/www/html/magento22/vendor/magento/framework/Session/SessionManager.php(130): MagentoFrameworkSessionGenericInterceptor->start() #3 /var/www/html/magento22/generated/code/Magento/Framework/Session/Generic/Interceptor.php(14): MagentoFrameworkSessionSessionManager->__construct(Object(MagentoFrameworkAppRequestHttp), Object(MagentoFrameworkSessionSidResolverProxy), Object(MagentoFrameworkSessionConfig), Object(MagentoFrameworkSessionSaveHandler), Object(MagentoFrameworkSessionValidator), Object(MagentoFrameworkSessionStorage), Object(MagentoFramewor in /var/www/html/magento22/vendor/magento/framework/Session/SessionManager.php on line 175

this is the code .I am converting Mage::getModel(‘sales/order’); in magento 2

$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$orders = $objectManager->get('MagentoSalesModelOrder')

how to deal with this?

2

Answers


  1. Chosen as BEST ANSWER

    Thank you for your answers. I found solution so want to share it. Add this line

    $objectManager->get('MagentoFrameworkAppState')->setAreaCode('frontend');
    

    before

    $orders = $objectManager->get('MagentoSalesModelOrder');
    

  2. To convert Mage::getModel('sales/order'); in magento2 you can use following code

    $objectManager = MagentoFrameworkAppObjectManager::getInstance();
    $orders = $objectManager->get('MagentoSalesModelOrder')->getCollection();
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search