From 8920a7ae91e41f1aa0a4656b4bd8fcbfdec56bb0 Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky Date: Wed, 1 Apr 2020 13:12:06 +0300 Subject: [PATCH] magento2-login-as-customer/issues/28: Admin order noted in Order Comments. --- .../AdminAddCommentOnOrderPlacementPlugin.php | 55 +++++++++++++++ .../FrontAddCommentOnOrderPlacementPlugin.php | 67 +++++++++++++++++++ .../LoginAsCustomer/etc/adminhtml/di.xml | 3 + .../LoginAsCustomer/etc/webapi_rest/di.xml | 12 ++++ 4 files changed, 137 insertions(+) create mode 100644 app/code/Magento/LoginAsCustomer/Plugin/AdminAddCommentOnOrderPlacementPlugin.php create mode 100644 app/code/Magento/LoginAsCustomer/Plugin/FrontAddCommentOnOrderPlacementPlugin.php create mode 100755 app/code/Magento/LoginAsCustomer/etc/webapi_rest/di.xml 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 @@ + + + + + + +