-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unsubscribed contact are resubscribed in CiviCRM after edition in Mailchimp #336
Comments
The following patch seems to fix it: diff --git a/CRM/Mailchimp/Page/WebHook.php b/CRM/Mailchimp/Page/WebHook.php
index 9bd13d9..3eaec26 100644
--- a/CRM/Mailchimp/Page/WebHook.php
+++ b/CRM/Mailchimp/Page/WebHook.php
@@ -350,11 +366,19 @@ class CRM_Mailchimp_Page_WebHook extends CRM_Core_Page {
civicrm_api3('Contact', 'create', ['contact_id' => $this->contact_id] + $edits);
}
+ // [SV] fixing a bug where the contact is unsubscribed in Mailchimp but added here
+ // it would happen any time an admin update an account in mailchimp
+ $api = CRM_Mailchimp_Utils::getMailchimpApi();
+ $subscriber_hash = md5(strtolower($this->request_data['email']));
+ $list_id = $this->request_data['list_id'];
+ $response = $api->get("/lists/{$list_id}/members/{$subscriber_hash}", ['fields' => 'status']);
+ $status = $response->data->status == 'unsubscribed' ? 'Removed' : 'Added';
+
// Contact has just subscribed, we'll need to add them to the list.
civicrm_api3('GroupContact', 'create', [
'contact_id' => $this->contact_id,
'group_id' => $this->sync->membership_group_id,
- 'status' => 'Added',
+ 'status' => $status,
]);
$this->updateInterestsFromMerges(); Not sure my code works for all cases as I assume only
|
I'm trying to see any difference between Mailchimp and CiviCRM list and:
|
I've seen that it's already in the code so let's ignore the cleaned part and focus on the bug described. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To reproduce:
ensure that the contact is properly unsubscribed in CiviCRM
edit profile or groups in Mailchimp
The contact will be resubscribed to the list.
The text was updated successfully, but these errors were encountered: