I’m working on a few projects converting old Magento 1 extensions to Magento 2. One extension I was working on had a “frontend area checker” in an observer that would return early if the request didn’t happen on the frontend. Like any good refactoring programmer, rather than spend days trying to piece together why the extension had this behavior, I decided it was best just to reimplement the checker in Magento 2.
<?php
namespace PackageNameModuleNameHelperIs;
class Frontend
{
protected $applicationState;
protected $request;
public function __construct(
MagentoFrameworkAppState $applicationState
)
{
$this->applicationState = $applicationState;
}
public function check()
{
if($this->applicationState->getAreaCode() !== 'frontend')
{
return false;
}
return true;
}
}
However, this turned out to be a mistake, or at least incomplete. I haven’t pinpointed the exact code yet, but it looks like Magento 2’s new cart checkout uses the restful API to place the order. i.e. the following code
$this->applicationState->getAreaCode()
returned webapi_rest
when a user placed an order.
If any of your extensions use explicit area checking, you’ll need/want to recheck your assumptions about how the extension works during order placing.