From c6a2fc7a7ba208d66fe31ed86a422727289b7d91 Mon Sep 17 00:00:00 2001 From: Manuele Menozzi Date: Wed, 5 Dec 2018 17:23:38 +0100 Subject: [PATCH] [fix] Prevents observer call when saving subscriber from webhook If the subscriber is saved from the Mailup webhook the observer should not run (because MailUp has already with that status). Indeed before this fix it's impossible to subscribe a subscriber through MailUp's webhook. --- src/app/code/local/MailUp/MailUpSync/Model/Observer.php | 8 ++++++++ .../MailUp/MailUpSync/controllers/WebhookController.php | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/app/code/local/MailUp/MailUpSync/Model/Observer.php b/src/app/code/local/MailUp/MailUpSync/Model/Observer.php index 63bf3c4..f25f85d 100644 --- a/src/app/code/local/MailUp/MailUpSync/Model/Observer.php +++ b/src/app/code/local/MailUp/MailUpSync/Model/Observer.php @@ -200,6 +200,10 @@ public function leggiUtente($observer) */ public function beforeSave($observer) { + if (isset($GLOBALS['__sl_mailup_save_from_webhook'])) { + return; + } + $model = $observer->getEvent()->getDataObject(); $confirm = Mage::getStoreConfig('mailup_newsletter/mailup/require_subscription_confirmation'); @@ -230,6 +234,10 @@ public function beforeSave($observer) */ public function sendUser($observer) { + if (isset($GLOBALS['__sl_mailup_save_from_webhook'])) { + return $this; + } + $model = $observer->getEvent()->getDataObject(); // Ensure that (if called as singleton), this will only get called once per customer diff --git a/src/app/code/local/MailUp/MailUpSync/controllers/WebhookController.php b/src/app/code/local/MailUp/MailUpSync/controllers/WebhookController.php index d0c31c4..8890d70 100644 --- a/src/app/code/local/MailUp/MailUpSync/controllers/WebhookController.php +++ b/src/app/code/local/MailUp/MailUpSync/controllers/WebhookController.php @@ -42,7 +42,7 @@ public function subscribeAction() die(); } - $GLOBALS["__sl_mailup_invia_utente"] = 1; //avoids observer + $GLOBALS['__sl_mailup_save_from_webhook'] = 1; //avoids observer $model ->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED) ->save(); @@ -88,7 +88,7 @@ public function unsubscribeAction() die(); } - $GLOBALS["__sl_mailup_invia_utente"] = 1; //avoids observer + $GLOBALS['__sl_mailup_save_from_webhook'] = 1; //avoids observer $model ->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED) ->save();