Skip to content

Commit 8fcee2c

Browse files
author
Oleksii Korshenko
committed
MAGETWO-83257: #4004: Newsletter Subscriber create-date not set, and change_status_at broken #11879
- Merge Pull Request #11879 from nemesis-back/magento2:bugfix/4004-newsletter-subscriber-change-status - Merged commits: 1. 3afed3d
2 parents 0483421 + 3afed3d commit 8fcee2c

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;
@@ -810,4 +819,18 @@ public function getSubscriberFullName()
810819
}
811820
return $name;
812821
}
822+
823+
/**
824+
* Set date of last changed status
825+
*
826+
* @return $this
827+
*/
828+
public function beforeSave()
829+
{
830+
parent::beforeSave();
831+
if ($this->dataHasChangedFor('subscriber_status')) {
832+
$this->setChangeStatusAt($this->dateTime->gmtDate());
833+
}
834+
return $this;
835+
}
813836
}

0 commit comments

Comments
 (0)