7
7
8
8
use Magento \Customer \Api \AccountManagementInterface ;
9
9
use Magento \Customer \Api \CustomerRepositoryInterface ;
10
+ use Magento \Framework \App \ObjectManager ;
10
11
use Magento \Framework \Exception \MailException ;
11
12
use Magento \Framework \Exception \NoSuchEntityException ;
13
+ use Magento \Framework \Stdlib \DateTime \DateTime ;
12
14
13
15
/**
14
16
* Subscriber model
@@ -94,6 +96,12 @@ class Subscriber extends \Magento\Framework\Model\AbstractModel
94
96
*/
95
97
protected $ _customerSession ;
96
98
99
+ /**
100
+ * Date
101
+ * @var DateTime
102
+ */
103
+ private $ dateTime ;
104
+
97
105
/**
98
106
* Store manager
99
107
*
@@ -134,9 +142,10 @@ class Subscriber extends \Magento\Framework\Model\AbstractModel
134
142
* @param CustomerRepositoryInterface $customerRepository
135
143
* @param AccountManagementInterface $customerAccountManagement
136
144
* @param \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation
137
- * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
138
- * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
145
+ * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
146
+ * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
139
147
* @param array $data
148
+ * @param DateTime|null $dateTime
140
149
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
141
150
*/
142
151
public function __construct (
@@ -152,7 +161,8 @@ public function __construct(
152
161
\Magento \Framework \Translate \Inline \StateInterface $ inlineTranslation ,
153
162
\Magento \Framework \Model \ResourceModel \AbstractResource $ resource = null ,
154
163
\Magento \Framework \Data \Collection \AbstractDb $ resourceCollection = null ,
155
- array $ data = []
164
+ array $ data = [],
165
+ DateTime $ dateTime = null
156
166
) {
157
167
$ this ->_newsletterData = $ newsletterData ;
158
168
$ this ->_scopeConfig = $ scopeConfig ;
@@ -162,6 +172,7 @@ public function __construct(
162
172
$ this ->customerRepository = $ customerRepository ;
163
173
$ this ->customerAccountManagement = $ customerAccountManagement ;
164
174
$ this ->inlineTranslation = $ inlineTranslation ;
175
+ $ this ->dateTime = $ dateTime ?: ObjectManager::getInstance ()->get (DateTime::class);
165
176
parent ::__construct ($ context , $ registry , $ resource , $ resourceCollection , $ data );
166
177
}
167
178
@@ -810,4 +821,18 @@ public function getSubscriberFullName()
810
821
}
811
822
return $ name ;
812
823
}
824
+
825
+ /**
826
+ * Set date of last changed status
827
+ *
828
+ * @return $this
829
+ */
830
+ public function beforeSave ()
831
+ {
832
+ parent ::beforeSave ();
833
+ if ($ this ->dataHasChangedFor ('subscriber_status ' )) {
834
+ $ this ->setChangeStatusAt ($ this ->dateTime ->gmtDate ());
835
+ }
836
+ return $ this ;
837
+ }
813
838
}
0 commit comments