Categories


Archives


Recent Posts


Categories


Magento 2 Order Placing is a REST Request

astorm

Frustrated by Magento? Then you’ll love Commerce Bug, the must have debugging extension for anyone using Magento. Whether you’re just starting out or you’re a seasoned pro, Commerce Bug will save you and your team hours everyday. Grab a copy and start working with Magento instead of against it.

Updated for Magento 2! No Frills Magento Layout is the only Magento front end book you'll ever need. Get your copy today!

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.

Copyright © Alana Storm 1975 – 2023 All Rights Reserved

Originally Posted: 9th March 2016

email hidden; JavaScript is required