Open luigifab opened 6 years ago
Hi, @luigifab38. AFAIK, this behavior is related to a bug in old versions of magento when this field wasn't updated automatically.
Okay, but now there is a problem, every time I or Magento save the customer, the newsletter _change_statusat get a new date, even if no change occur.
Where do you use this field (_change_statusat)? In OroCRM? For synchronisation? Or just for information? Can I remove the Magento observer in Magento 1.9.3.2?
So, here is a suggestion.
public function beforeNewsletterSubscriberSave($observer)
{
$subscriber = $observer->getSubscriber();
if (in_array($subscriber->getData('change_status_at'), array('', '0000-00-00 00:00:00', null))) {
$now = new \DateTime('now', new \DateTimeZone('UTC'));
$subscriber->setData('change_status_at', $now->format('Y-m-d H:i:s'));
}
else {
$oldSubscriber = clone $subscriber;
$oldSubscriber->load($subscriber->getId());
if ($subscriber->getData('subscriber_status') != $oldSubscriber->getData('subscriber_status')) {
$now = new \DateTime('now', new \DateTimeZone('UTC'));
$subscriber->setData('change_status_at', $now->format('Y-m-d H:i:s'));
}
}
}
In Oro_Api_Model_Observer::beforeNewsletterSubscriberSave() (for the _newsletter_subscriber_savebefore event), why you are updating change_status_at everytime?