-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from magento-commerce/magento2-login-as-custom…
…er/issues/28 magento2-login-as-customer/issues/28: Admin order noted in Order Comments.
- Loading branch information
Showing
4 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
app/code/Magento/LoginAsCustomer/Plugin/AdminAddCommentOnOrderPlacementPlugin.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\LoginAsCustomer\Plugin; | ||
|
||
use Magento\Backend\Model\Auth\Session; | ||
use Magento\Sales\Model\Order; | ||
|
||
/** | ||
* Add comment after order placed by admin using admin panel. | ||
*/ | ||
class AdminAddCommentOnOrderPlacementPlugin | ||
{ | ||
/** | ||
* @var Session | ||
*/ | ||
private $userSession; | ||
|
||
/** | ||
* @param Session $session | ||
*/ | ||
public function __construct( | ||
Session $session | ||
) { | ||
$this->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; | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
app/code/Magento/LoginAsCustomer/Plugin/FrontAddCommentOnOrderPlacementPlugin.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\LoginAsCustomer\Plugin; | ||
|
||
use Magento\Customer\Model\Session; | ||
use Magento\Sales\Model\Order; | ||
use Magento\User\Model\UserFactory; | ||
|
||
/** | ||
* Add comment after order placed by admin using login-as-customer. | ||
*/ | ||
class FrontAddCommentOnOrderPlacementPlugin | ||
{ | ||
/** | ||
* @var Session | ||
*/ | ||
private $customerSession; | ||
|
||
/** | ||
* @var UserFactory | ||
*/ | ||
private $userFactory; | ||
|
||
/** | ||
* @param Session $session | ||
* @param UserFactory $userFactory | ||
*/ | ||
public function __construct( | ||
Session $session, | ||
UserFactory $userFactory | ||
) { | ||
$this->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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
<type name="Magento\Sales\Model\Order"> | ||
<plugin name="lac-front-order-placement-comment" type="Magento\LoginAsCustomer\Plugin\FrontAddCommentOnOrderPlacementPlugin"/> | ||
</type> | ||
</config> |