TransWikia.com

Magento 2 How to identify order is placed from frontend or rest API?

Magento Asked on November 8, 2021

How to identify order is placed from frontend or rest API ?

when we are trying to area code from any event after order placed

$this->_checkState->getAreaCode()

then we are getting always area code is "webapi_rest"

it must be frontend.

If checkout placed order is using REST API then how to identify order placed is from frontend or rest API or any other medium?

One Answer

Since Magento checkout page uses rest API thatswhy its giving you result like this.

try getting current layout like this

    public function __construct(
    ...
    MagentoFrameworkAppRequestHttp $request
) {
    ...
    $this->_request = $request;
}

public function yourFunctionName()
{
    $handle = $this->_request->getFullActionName();
    ....
}

if it returns something like checkout_index_index then the order is from theme else API

let me know if you face any problem.

Answered by Adarsh Shukla on November 8, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP