Skip to content

Commit 41c21a6

Browse files
authored
Merge pull request #12 from landofcoder/mass-unsubscriber
add after unsubscribe
2 parents f6a676b + 9776477 commit 41c21a6

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

Model/Plugin/Subscriber.php

+23-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function __construct(
5151
Contact $mauticContact,
5252
DeletePublisher $deletePublisher
5353
) {
54-
54+
5555
$this->_helper = $helper;
5656
$this->_storeManager = $storeManager;
5757
$this->_publisher = $publisher;
@@ -107,7 +107,7 @@ protected function getStoreIdFromSubscriber(\Magento\Newsletter\Model\Subscriber
107107

108108
/**
109109
* afterSendConfirmationSuccessEmail
110-
*
110+
*
111111
* @param \Magento\Newsletter\Model\Subscriber $subscriber
112112
* @return \Magento\Newsletter\Model\Subscriber
113113
*/
@@ -125,9 +125,29 @@ public function afterSendConfirmationSuccessEmail(\Magento\Newsletter\Model\Subs
125125
return $subscriber;
126126
}
127127

128+
/**
129+
* afterUnsubscribe
130+
*
131+
* @param \Magento\Newsletter\Model\Subscriber $subscriber
132+
* @return \Magento\Newsletter\Model\Subscriber
133+
*/
134+
public function afterUnsubscribe(\Magento\Newsletter\Model\Subscriber $subscriber)
135+
{
136+
try {
137+
if ($this->_helper->isEnabled($subscriber->getStoreId()) && $subscriber->getSubscriberStatus() == \Magento\Newsletter\Model\Subscriber::STATUS_UNSUBSCRIBE) {
138+
$tags = ["-subscribed"];
139+
$this->createMauticContact($subscriber->getEmail(), $subscriber->getName(), $tags, $subscriber->getStoreId());
140+
}
141+
} catch (\Exception $exception) {
142+
//
143+
}
144+
145+
return $subscriber;
146+
}
147+
128148
/**
129149
* aroundSendConfirmationRequestEmail
130-
*
150+
*
131151
* @param \Magento\Newsletter\Model\Subscriber $subscriber
132152
* @param \Closure $proceed
133153
*/

0 commit comments

Comments
 (0)