Skip to content

Commit 3afed3d

Browse files
committed
#4004: Newsletter Subscriber change_status_at broken
1 parent 9b87eb0 commit 3afed3d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

app/code/Magento/Newsletter/Model/Subscriber.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ class Subscriber extends \Magento\Framework\Model\AbstractModel
9494
*/
9595
protected $_customerSession;
9696

97+
/**
98+
* Date
99+
* @var \Magento\Framework\Stdlib\DateTime\DateTime
100+
*/
101+
private $dateTime;
102+
97103
/**
98104
* Store manager
99105
*
@@ -131,6 +137,7 @@ class Subscriber extends \Magento\Framework\Model\AbstractModel
131137
* @param \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder
132138
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
133139
* @param \Magento\Customer\Model\Session $customerSession
140+
* @param \Magento\Framework\Stdlib\DateTime\DateTime $dateTime
134141
* @param CustomerRepositoryInterface $customerRepository
135142
* @param AccountManagementInterface $customerAccountManagement
136143
* @param \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation
@@ -147,6 +154,7 @@ public function __construct(
147154
\Magento\Framework\Mail\Template\TransportBuilder $transportBuilder,
148155
\Magento\Store\Model\StoreManagerInterface $storeManager,
149156
\Magento\Customer\Model\Session $customerSession,
157+
\Magento\Framework\Stdlib\DateTime\DateTime $dateTime,
150158
CustomerRepositoryInterface $customerRepository,
151159
AccountManagementInterface $customerAccountManagement,
152160
\Magento\Framework\Translate\Inline\StateInterface $inlineTranslation,
@@ -159,6 +167,7 @@ public function __construct(
159167
$this->_transportBuilder = $transportBuilder;
160168
$this->_storeManager = $storeManager;
161169
$this->_customerSession = $customerSession;
170+
$this->dateTime = $dateTime;
162171
$this->customerRepository = $customerRepository;
163172
$this->customerAccountManagement = $customerAccountManagement;
164173
$this->inlineTranslation = $inlineTranslation;
@@ -806,4 +815,18 @@ public function getSubscriberFullName()
806815
}
807816
return $name;
808817
}
818+
819+
/**
820+
* Set date of last changed status
821+
*
822+
* @return $this
823+
*/
824+
public function beforeSave()
825+
{
826+
parent::beforeSave();
827+
if ($this->dataHasChangedFor('subscriber_status')) {
828+
$this->setChangeStatusAt($this->dateTime->gmtDate());
829+
}
830+
return $this;
831+
}
809832
}

0 commit comments

Comments
 (0)