Skip to main content

You can use an admin authauthentication session for this:

ExampleAn example with a plugin for \Magento\Sales\Api\OrderManagementInterface:

Acme/StackExchange/Plugin/Sales/Api/OrderManagementInterfacePlugin.php

<?php
declare(strict_types=1);

namespace Acme\StackExchange\Plugin\Sales\Api;

use Magento\Backend\Model\Auth\Session as AuthSession;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\OrderManagementInterface;

class OrderManagementInterfacePlugin
{
    /**
     * @var AuthSession
     */
    protected $authSession;

    public function __construct(
        AuthSession $authSession
    ) {
        $this->authSession = $authSession;
    }


    public function afterPlace(
        OrderManagementInterface $subject,
        OrderInterface $result,
        OrderInterface $order
    ): OrderInterface {
        if ($this->authSession->getUser()) {
            // the order placed by admin
            $firstName = $this->authSession->getUser()->getFirstName();
            $lastName  = $this->authSession->getUser()->getLastName();

            // your logic here
        }

        return $result;
    }
}

You can use admin auth session for this

Example with plugin for \Magento\Sales\Api\OrderManagementInterface

Acme/StackExchange/Plugin/Sales/Api/OrderManagementInterfacePlugin.php

<?php
declare(strict_types=1);

namespace Acme\StackExchange\Plugin\Sales\Api;

use Magento\Backend\Model\Auth\Session as AuthSession;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\OrderManagementInterface;

class OrderManagementInterfacePlugin
{
    /**
     * @var AuthSession
     */
    protected $authSession;

    public function __construct(
        AuthSession $authSession
    ) {
        $this->authSession = $authSession;
    }


    public function afterPlace(
        OrderManagementInterface $subject,
        OrderInterface $result,
        OrderInterface $order
    ): OrderInterface {
        if ($this->authSession->getUser()) {
            // the order placed by admin
            $firstName = $this->authSession->getUser()->getFirstName();
            $lastName  = $this->authSession->getUser()->getLastName();

            // your logic here
        }

        return $result;
    }
}

You can use an admin authentication session for this:

An example with a plugin for \Magento\Sales\Api\OrderManagementInterface:

Acme/StackExchange/Plugin/Sales/Api/OrderManagementInterfacePlugin.php

<?php
declare(strict_types=1);

namespace Acme\StackExchange\Plugin\Sales\Api;

use Magento\Backend\Model\Auth\Session as AuthSession;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\OrderManagementInterface;

class OrderManagementInterfacePlugin
{
    /**
     * @var AuthSession
     */
    protected $authSession;

    public function __construct(
        AuthSession $authSession
    ) {
        $this->authSession = $authSession;
    }


    public function afterPlace(
        OrderManagementInterface $subject,
        OrderInterface $result,
        OrderInterface $order
    ): OrderInterface {
        if ($this->authSession->getUser()) {
            // the order placed by admin
            $firstName = $this->authSession->getUser()->getFirstName();
            $lastName  = $this->authSession->getUser()->getLastName();

            // your logic here
        }

        return $result;
    }
}
Source Link
Victor Tihonchuk
  • 3.6k
  • 1
  • 7
  • 18

You can use admin auth session for this

Example with plugin for \Magento\Sales\Api\OrderManagementInterface

Acme/StackExchange/Plugin/Sales/Api/OrderManagementInterfacePlugin.php

<?php
declare(strict_types=1);

namespace Acme\StackExchange\Plugin\Sales\Api;

use Magento\Backend\Model\Auth\Session as AuthSession;
use Magento\Sales\Api\Data\OrderInterface;
use Magento\Sales\Api\OrderManagementInterface;

class OrderManagementInterfacePlugin
{
    /**
     * @var AuthSession
     */
    protected $authSession;

    public function __construct(
        AuthSession $authSession
    ) {
        $this->authSession = $authSession;
    }


    public function afterPlace(
        OrderManagementInterface $subject,
        OrderInterface $result,
        OrderInterface $order
    ): OrderInterface {
        if ($this->authSession->getUser()) {
            // the order placed by admin
            $firstName = $this->authSession->getUser()->getFirstName();
            $lastName  = $this->authSession->getUser()->getLastName();

            // your logic here
        }

        return $result;
    }
}