Skip to content

Commit

Permalink
magento#4004: Newsletter Subscriber change_status_at broken
Browse files Browse the repository at this point in the history
  • Loading branch information
nemesis-back committed Oct 31, 2017
1 parent 9b87eb0 commit 3afed3d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions app/code/Magento/Newsletter/Model/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ class Subscriber extends \Magento\Framework\Model\AbstractModel
*/
protected $_customerSession;

/**
* Date
* @var \Magento\Framework\Stdlib\DateTime\DateTime
*/
private $dateTime;

/**
* Store manager
*
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 3afed3d

Please sign in to comment.