I am using sales_order_save_after in Global scope. I am creating orders from admin programmatically( Order, Invoice and Shipment). Each and every time this event is calling.

I want to check and update the order increment id with the prefix value only from the front end order.

How can i check the observer calling from front end scope?

1 Answer 1


Inject the Magento\Framework\App\State class object in your observer's __construct method and store the object into the observer class property, so that you can access getAreaCode().

For example:

protected $state;

public function __construct (
    \Magento\Framework\App\State $state
) {
    $this->state = $state;

public function getArea()
    return $this->state->getAreaCode();

Refer: Magento2 : Check it is frontend or backend?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.