Magento 2 “Area code not set” warning in Observer from moduleRedirect from ObserverEvent Observer Module for Upsellmodule to add custom code in code_core_mage_sales_etc_config.xml via module or observerget product ID from observerSet custom price of product when adding to cart code not workingHow to call an observer from custom module: Magento 2Custom Module Observer not sending mailBest way to redirect from observer in magento 2Magento 2 : Set free shipping method programatically from an observerNot able to set cookie in observer
How can I show that the speed of light in vacuum is the same in all reference frames?
Host telling me to cancel my booking in exchange for a discount?
How far off did Apollo 11 land?
Why didn't Balak request Bilam to bless his own people?
I want light controlled by one switch, not two
Do I care if the housing market has gone up or down, if I'm moving from one house to another?
Do we have to introduce the character's name before using their names in a dialogue tag?
Do gauntlets count as armor?
Three Subway Escalators
A bicolour masyu
Ethiopian Airlines tickets seem to always have the same price regardless of the proximity of the date?
Does the Bracer of Flying Daggers really let a thief make 4 attacks per round?
How does mathematics work?
What is the intuition for higher homotopy groups not vanishing?
1025th term of the given sequence.
Could a US citizen born through "birth tourism" become President?
Grease/lubricate rubber stabilizer bar bushings?
Find position equal columns of matrix
Is art a form of communication?
A Real World Example for Divide and Conquer Method
Quickest way to move a line in a text file before another line in a text file?
What's a German word for »Sandbagger«?
Time war story - soldier name lengthens as he travels further from the battle front
ISCSI, multiple initiaros for the same lun
Magento 2 “Area code not set” warning in Observer from module
Redirect from ObserverEvent Observer Module for Upsellmodule to add custom code in code_core_mage_sales_etc_config.xml via module or observerget product ID from observerSet custom price of product when adding to cart code not workingHow to call an observer from custom module: Magento 2Custom Module Observer not sending mailBest way to redirect from observer in magento 2Magento 2 : Set free shipping method programatically from an observerNot able to set cookie in observer
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I get "Area code not set error" when my observer executes. What can I do?
Code:
<?php
namespace MyCompanyMyModuleObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkAppBootstrap;
class SaveOrder implements ObserverInterface
private $logger;
private $state;
public function __construct(
MagentoFrameworkViewElementContext $context,
PsrLogLoggerInterface $logger,
MagentoFrameworkAppState $state
)
$this->_layout = $context->getLayout();
$this->_request = $context->getRequest();
$this->logger = $logger;
$this->_state = $state;
try
$this->_state->setAreaCode(MagentoFrameworkAppArea::AREA_ADMINHTML);
catch (MagentoFrameworkExceptionLocalizedException $e)
// nothing to do
public function execute(MagentoFrameworkEventObserver $observer)
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$objDate = $objectManager->create('MagentoFrameworkStdlibDateTimeDateTime');
$date = $objDate->gmtDate();
$resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
$connection = $resource->getConnection();
$orderId = $observer->getEvent()->getOrderIds()[0];
$sql = "INSERT INTO sap_orders (entity_id, order_id, sent, timestamp) Values (''," .
$orderId .
", '" .
"0" .
"', '" .
$date .
"')" ;
$connection->query($sql);
event-observer third-party-module magento2.3.2
add a comment |
I get "Area code not set error" when my observer executes. What can I do?
Code:
<?php
namespace MyCompanyMyModuleObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkAppBootstrap;
class SaveOrder implements ObserverInterface
private $logger;
private $state;
public function __construct(
MagentoFrameworkViewElementContext $context,
PsrLogLoggerInterface $logger,
MagentoFrameworkAppState $state
)
$this->_layout = $context->getLayout();
$this->_request = $context->getRequest();
$this->logger = $logger;
$this->_state = $state;
try
$this->_state->setAreaCode(MagentoFrameworkAppArea::AREA_ADMINHTML);
catch (MagentoFrameworkExceptionLocalizedException $e)
// nothing to do
public function execute(MagentoFrameworkEventObserver $observer)
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$objDate = $objectManager->create('MagentoFrameworkStdlibDateTimeDateTime');
$date = $objDate->gmtDate();
$resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
$connection = $resource->getConnection();
$orderId = $observer->getEvent()->getOrderIds()[0];
$sql = "INSERT INTO sap_orders (entity_id, order_id, sent, timestamp) Values (''," .
$orderId .
", '" .
"0" .
"', '" .
$date .
"')" ;
$connection->query($sql);
event-observer third-party-module magento2.3.2
add a comment |
I get "Area code not set error" when my observer executes. What can I do?
Code:
<?php
namespace MyCompanyMyModuleObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkAppBootstrap;
class SaveOrder implements ObserverInterface
private $logger;
private $state;
public function __construct(
MagentoFrameworkViewElementContext $context,
PsrLogLoggerInterface $logger,
MagentoFrameworkAppState $state
)
$this->_layout = $context->getLayout();
$this->_request = $context->getRequest();
$this->logger = $logger;
$this->_state = $state;
try
$this->_state->setAreaCode(MagentoFrameworkAppArea::AREA_ADMINHTML);
catch (MagentoFrameworkExceptionLocalizedException $e)
// nothing to do
public function execute(MagentoFrameworkEventObserver $observer)
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$objDate = $objectManager->create('MagentoFrameworkStdlibDateTimeDateTime');
$date = $objDate->gmtDate();
$resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
$connection = $resource->getConnection();
$orderId = $observer->getEvent()->getOrderIds()[0];
$sql = "INSERT INTO sap_orders (entity_id, order_id, sent, timestamp) Values (''," .
$orderId .
", '" .
"0" .
"', '" .
$date .
"')" ;
$connection->query($sql);
event-observer third-party-module magento2.3.2
I get "Area code not set error" when my observer executes. What can I do?
Code:
<?php
namespace MyCompanyMyModuleObserver;
use MagentoFrameworkEventObserverInterface;
use MagentoFrameworkAppBootstrap;
class SaveOrder implements ObserverInterface
private $logger;
private $state;
public function __construct(
MagentoFrameworkViewElementContext $context,
PsrLogLoggerInterface $logger,
MagentoFrameworkAppState $state
)
$this->_layout = $context->getLayout();
$this->_request = $context->getRequest();
$this->logger = $logger;
$this->_state = $state;
try
$this->_state->setAreaCode(MagentoFrameworkAppArea::AREA_ADMINHTML);
catch (MagentoFrameworkExceptionLocalizedException $e)
// nothing to do
public function execute(MagentoFrameworkEventObserver $observer)
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$objDate = $objectManager->create('MagentoFrameworkStdlibDateTimeDateTime');
$date = $objDate->gmtDate();
$resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
$connection = $resource->getConnection();
$orderId = $observer->getEvent()->getOrderIds()[0];
$sql = "INSERT INTO sap_orders (entity_id, order_id, sent, timestamp) Values (''," .
$orderId .
", '" .
"0" .
"', '" .
$date .
"')" ;
$connection->query($sql);
event-observer third-party-module magento2.3.2
event-observer third-party-module magento2.3.2
asked Jul 12 at 10:03
Ángel Carlos del Pozo MuelaÁngel Carlos del Pozo Muela
357 bronze badges
357 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You need to set Area code(Frontend/Backend) when using bootstrap class
public function execute(MagentoFrameworkEventObserver $observer)
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');
(or)
$state = $objectManager->get('MagentoFrameworkAppState');
$state->setAreaCode('backend');
$objDate = $objectManager->create('MagentoFrameworkStdlibDateTimeDateTime');
$date = $objDate->gmtDate();
$resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
$connection = $resource->getConnection();
$orderId = $observer->getEvent()->getOrderIds()[0];
$sql = "INSERT INTO sap_orders (entity_id, order_id, sent, timestamp) Values (''," .
$orderId .
", '" .
"0" .
"', '" .
$date .
"')" ;
$connection->query($sql);
It works, not it doesn't show area code error.
– Ángel Carlos del Pozo Muela
Jul 12 at 10:49
You are welcome..
– aravind
Jul 12 at 11:01
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f281868%2fmagento-2-area-code-not-set-warning-in-observer-from-module%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to set Area code(Frontend/Backend) when using bootstrap class
public function execute(MagentoFrameworkEventObserver $observer)
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');
(or)
$state = $objectManager->get('MagentoFrameworkAppState');
$state->setAreaCode('backend');
$objDate = $objectManager->create('MagentoFrameworkStdlibDateTimeDateTime');
$date = $objDate->gmtDate();
$resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
$connection = $resource->getConnection();
$orderId = $observer->getEvent()->getOrderIds()[0];
$sql = "INSERT INTO sap_orders (entity_id, order_id, sent, timestamp) Values (''," .
$orderId .
", '" .
"0" .
"', '" .
$date .
"')" ;
$connection->query($sql);
It works, not it doesn't show area code error.
– Ángel Carlos del Pozo Muela
Jul 12 at 10:49
You are welcome..
– aravind
Jul 12 at 11:01
add a comment |
You need to set Area code(Frontend/Backend) when using bootstrap class
public function execute(MagentoFrameworkEventObserver $observer)
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');
(or)
$state = $objectManager->get('MagentoFrameworkAppState');
$state->setAreaCode('backend');
$objDate = $objectManager->create('MagentoFrameworkStdlibDateTimeDateTime');
$date = $objDate->gmtDate();
$resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
$connection = $resource->getConnection();
$orderId = $observer->getEvent()->getOrderIds()[0];
$sql = "INSERT INTO sap_orders (entity_id, order_id, sent, timestamp) Values (''," .
$orderId .
", '" .
"0" .
"', '" .
$date .
"')" ;
$connection->query($sql);
It works, not it doesn't show area code error.
– Ángel Carlos del Pozo Muela
Jul 12 at 10:49
You are welcome..
– aravind
Jul 12 at 11:01
add a comment |
You need to set Area code(Frontend/Backend) when using bootstrap class
public function execute(MagentoFrameworkEventObserver $observer)
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');
(or)
$state = $objectManager->get('MagentoFrameworkAppState');
$state->setAreaCode('backend');
$objDate = $objectManager->create('MagentoFrameworkStdlibDateTimeDateTime');
$date = $objDate->gmtDate();
$resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
$connection = $resource->getConnection();
$orderId = $observer->getEvent()->getOrderIds()[0];
$sql = "INSERT INTO sap_orders (entity_id, order_id, sent, timestamp) Values (''," .
$orderId .
", '" .
"0" .
"', '" .
$date .
"')" ;
$connection->query($sql);
You need to set Area code(Frontend/Backend) when using bootstrap class
public function execute(MagentoFrameworkEventObserver $observer)
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
$state = $objectManager->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');
(or)
$state = $objectManager->get('MagentoFrameworkAppState');
$state->setAreaCode('backend');
$objDate = $objectManager->create('MagentoFrameworkStdlibDateTimeDateTime');
$date = $objDate->gmtDate();
$resource = $objectManager->get('MagentoFrameworkAppResourceConnection');
$connection = $resource->getConnection();
$orderId = $observer->getEvent()->getOrderIds()[0];
$sql = "INSERT INTO sap_orders (entity_id, order_id, sent, timestamp) Values (''," .
$orderId .
", '" .
"0" .
"', '" .
$date .
"')" ;
$connection->query($sql);
answered Jul 12 at 10:16
aravindaravind
5911 silver badge13 bronze badges
5911 silver badge13 bronze badges
It works, not it doesn't show area code error.
– Ángel Carlos del Pozo Muela
Jul 12 at 10:49
You are welcome..
– aravind
Jul 12 at 11:01
add a comment |
It works, not it doesn't show area code error.
– Ángel Carlos del Pozo Muela
Jul 12 at 10:49
You are welcome..
– aravind
Jul 12 at 11:01
It works, not it doesn't show area code error.
– Ángel Carlos del Pozo Muela
Jul 12 at 10:49
It works, not it doesn't show area code error.
– Ángel Carlos del Pozo Muela
Jul 12 at 10:49
You are welcome..
– aravind
Jul 12 at 11:01
You are welcome..
– aravind
Jul 12 at 11:01
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f281868%2fmagento-2-area-code-not-set-warning-in-observer-from-module%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown