Skip to content

Commit

Permalink
MAGETWO-83257: #4004: Newsletter Subscriber create-date not set, and …
Browse files Browse the repository at this point in the history
…change_status_at broken #11879
  • Loading branch information
Oleksii Korshenko authored Nov 7, 2017
2 parents c896f2c + 60a698d commit a12e731
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions app/code/Magento/Newsletter/Model/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

use Magento\Customer\Api\AccountManagementInterface;
use Magento\Customer\Api\CustomerRepositoryInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Exception\MailException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Stdlib\DateTime\DateTime;

/**
* Subscriber model
Expand Down Expand Up @@ -94,6 +96,12 @@ class Subscriber extends \Magento\Framework\Model\AbstractModel
*/
protected $_customerSession;

/**
* Date
* @var DateTime
*/
private $dateTime;

/**
* Store manager
*
Expand Down Expand Up @@ -134,9 +142,10 @@ class Subscriber extends \Magento\Framework\Model\AbstractModel
* @param CustomerRepositoryInterface $customerRepository
* @param AccountManagementInterface $customerAccountManagement
* @param \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
* @param array $data
* @param DateTime|null $dateTime
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand All @@ -152,7 +161,8 @@ public function __construct(
\Magento\Framework\Translate\Inline\StateInterface $inlineTranslation,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = []
array $data = [],
DateTime $dateTime = null
) {
$this->_newsletterData = $newsletterData;
$this->_scopeConfig = $scopeConfig;
Expand All @@ -162,6 +172,7 @@ public function __construct(
$this->customerRepository = $customerRepository;
$this->customerAccountManagement = $customerAccountManagement;
$this->inlineTranslation = $inlineTranslation;
$this->dateTime = $dateTime ?: ObjectManager::getInstance()->get(DateTime::class);
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
}

Expand Down Expand Up @@ -810,4 +821,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 a12e731

Please sign in to comment.