10
10
use Exception ;
11
11
use Magento \Backend \App \Action ;
12
12
use Magento \Backend \App \Action \Context ;
13
+ use Magento \Backend \Model \Auth \Session ;
13
14
use Magento \Customer \Api \AccountManagementInterface ;
14
15
use Magento \Customer \Api \CustomerRepositoryInterface ;
15
16
use Magento \Framework \Controller \Result \Json ;
@@ -49,6 +50,10 @@ class Index extends Action
49
50
* @var EmailAddress
50
51
*/
51
52
private $ emailAddressValidator ;
53
+ /**
54
+ * @var Session
55
+ */
56
+ private $ authSession ;
52
57
53
58
/**
54
59
* Index constructor.
@@ -59,6 +64,7 @@ class Index extends Action
59
64
* @param JsonFactory $resultJsonFactory
60
65
* @param CustomerRepositoryInterface $customerRepository
61
66
* @param EmailAddress $emailAddressValidator
67
+ * @param Session $authSession
62
68
*/
63
69
public function __construct (
64
70
Context $ context ,
@@ -67,7 +73,8 @@ public function __construct(
67
73
OrderCustomerManagementInterface $ orderCustomerService ,
68
74
JsonFactory $ resultJsonFactory ,
69
75
CustomerRepositoryInterface $ customerRepository ,
70
- EmailAddress $ emailAddressValidator
76
+ EmailAddress $ emailAddressValidator ,
77
+ Session $ authSession
71
78
) {
72
79
parent ::__construct ($ context );
73
80
@@ -77,6 +84,7 @@ public function __construct(
77
84
$ this ->accountManagement = $ accountManagement ;
78
85
$ this ->customerRepository = $ customerRepository ;
79
86
$ this ->emailAddressValidator = $ emailAddressValidator ;
87
+ $ this ->authSession = $ authSession ;
80
88
}
81
89
82
90
/**
@@ -119,6 +127,14 @@ public function execute()
119
127
/** @var $order OrderInterface */
120
128
$ order = $ this ->orderRepository ->get ($ orderId );
121
129
if ($ order ->getEntityId () && $ order ->getCustomerEmail () == $ oldEmailAddress ) {
130
+ $ comment = sprintf (
131
+ __ ("Order email address change from %s to %s by %s " ),
132
+ $ oldEmailAddress ,
133
+ $ emailAddress ,
134
+ $ this ->authSession ->getUser ()->getUserName ()
135
+ );
136
+
137
+ $ order ->addStatusHistoryComment ($ comment );
122
138
$ order ->setCustomerEmail ($ emailAddress );
123
139
$ this ->orderRepository ->save ($ order );
124
140
}
0 commit comments