diff --git a/app/code/Magento/LoginAsCustomer/Plugin/AdminAddCommentOnOrderPlacementPlugin.php b/app/code/Magento/LoginAsCustomer/Plugin/AdminAddCommentOnOrderPlacementPlugin.php new file mode 100644 index 0000000000000..e87e5553ef4c8 --- /dev/null +++ b/app/code/Magento/LoginAsCustomer/Plugin/AdminAddCommentOnOrderPlacementPlugin.php @@ -0,0 +1,55 @@ +userSession = $session; + } + + /** + * Add comment after order placed by admin using admin panel. + * + * @param Order $subject + * @param Order $result + * @return Order + */ + public function afterPlace(Order $subject, Order $result): Order + { + $adminUser = $this->userSession->getUser(); + $subject->addCommentToStatusHistory( + 'Order Placed by Store Administrator', + false, + true + )->setIsCustomerNotified(false); + $subject->addCommentToStatusHistory( + "Order Placed by {$adminUser->getFirstName()} {$adminUser->getLastName()} using Admin Panel", + false, + false + )->setIsCustomerNotified(false); + + return $result; + } +} diff --git a/app/code/Magento/LoginAsCustomer/Plugin/FrontAddCommentOnOrderPlacementPlugin.php b/app/code/Magento/LoginAsCustomer/Plugin/FrontAddCommentOnOrderPlacementPlugin.php new file mode 100644 index 0000000000000..898e80356656c --- /dev/null +++ b/app/code/Magento/LoginAsCustomer/Plugin/FrontAddCommentOnOrderPlacementPlugin.php @@ -0,0 +1,67 @@ +customerSession = $session; + $this->userFactory = $userFactory; + } + + /** + * Add comment after order placed by admin using login-as-customer. + * + * @param Order $subject + * @param Order $result + * @return Order + */ + public function afterPlace(Order $subject, Order $result): Order + { + $adminId = $this->customerSession->getLoggedAsCustomerAdmindId(); + if ($adminId) { + $adminUser = $this->userFactory->create()->load($adminId); + $subject->addCommentToStatusHistory( + 'Order Placed by Store Administrator', + false, + true + )->setIsCustomerNotified(false); + $subject->addCommentToStatusHistory( + "Order Placed by {$adminUser->getFirstName()} {$adminUser->getLastName()} using Login as Customer", + false, + false + )->setIsCustomerNotified(false); + } + + return $result; + } +} diff --git a/app/code/Magento/LoginAsCustomer/etc/adminhtml/di.xml b/app/code/Magento/LoginAsCustomer/etc/adminhtml/di.xml index df46bb8d8676f..b676052c1943b 100644 --- a/app/code/Magento/LoginAsCustomer/etc/adminhtml/di.xml +++ b/app/code/Magento/LoginAsCustomer/etc/adminhtml/di.xml @@ -9,4 +9,7 @@ + + + diff --git a/app/code/Magento/LoginAsCustomer/etc/webapi_rest/di.xml b/app/code/Magento/LoginAsCustomer/etc/webapi_rest/di.xml new file mode 100755 index 0000000000000..0b39471eb7968 --- /dev/null +++ b/app/code/Magento/LoginAsCustomer/etc/webapi_rest/di.xml @@ -0,0 +1,12 @@ + + + + + + +