From 3afed3d030b9dc29936de2aa775a406e999832bc Mon Sep 17 00:00:00 2001 From: IvanK <32677673+nemesis-back@users.noreply.github.com> Date: Mon, 30 Oct 2017 19:19:29 +0300 Subject: [PATCH] #4004: Newsletter Subscriber change_status_at broken --- .../Magento/Newsletter/Model/Subscriber.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/app/code/Magento/Newsletter/Model/Subscriber.php b/app/code/Magento/Newsletter/Model/Subscriber.php index 7847098083949..712d82a5e4d15 100644 --- a/app/code/Magento/Newsletter/Model/Subscriber.php +++ b/app/code/Magento/Newsletter/Model/Subscriber.php @@ -94,6 +94,12 @@ class Subscriber extends \Magento\Framework\Model\AbstractModel */ protected $_customerSession; + /** + * Date + * @var \Magento\Framework\Stdlib\DateTime\DateTime + */ + private $dateTime; + /** * Store manager * @@ -131,6 +137,7 @@ class Subscriber extends \Magento\Framework\Model\AbstractModel * @param \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\Customer\Model\Session $customerSession + * @param \Magento\Framework\Stdlib\DateTime\DateTime $dateTime * @param CustomerRepositoryInterface $customerRepository * @param AccountManagementInterface $customerAccountManagement * @param \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation @@ -147,6 +154,7 @@ public function __construct( \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Customer\Model\Session $customerSession, + \Magento\Framework\Stdlib\DateTime\DateTime $dateTime, CustomerRepositoryInterface $customerRepository, AccountManagementInterface $customerAccountManagement, \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation, @@ -159,6 +167,7 @@ public function __construct( $this->_transportBuilder = $transportBuilder; $this->_storeManager = $storeManager; $this->_customerSession = $customerSession; + $this->dateTime = $dateTime; $this->customerRepository = $customerRepository; $this->customerAccountManagement = $customerAccountManagement; $this->inlineTranslation = $inlineTranslation; @@ -806,4 +815,18 @@ public function getSubscriberFullName() } return $name; } + + /** + * Set date of last changed status + * + * @return $this + */ + public function beforeSave() + { + parent::beforeSave(); + if ($this->dataHasChangedFor('subscriber_status')) { + $this->setChangeStatusAt($this->dateTime->gmtDate()); + } + return $this; + } }