- 🇮🇳India sorabh.v6 Indore
I think unsubscribing is not enough and we it delete/archive old entry as well.
- 🇺🇸United States mrweiner
That committed D7 patch references http://stackoverflow.com/questions/32224697/mailchimp-api-v3-0-change-su.... One of the solutions there mentions that you can update the contact email via API. Here is a basic way to do this for users specifically.
function mymodule_user_presave(UserInterface $user): void { if (!$user->isNew() && $user->getEmail() !== $user->original->getEmail()) { $original_email = $user->original->getEmail(); $new_email = $user->getEmail(); $lists = mailchimp_get_lists(); foreach ($lists as $list_id => $list) { $info = mailchimp_get_memberinfo($list_id, $original_email); if (empty((array) $info)) { continue; } $tokens = [ 'list_id' => $list_id, 'subscriber_hash' => md5(strtolower($original_email)), ]; $parameters = [ 'email_address' => $new_email, ]; /* @var \Mailchimp\MailchimpLists $mc_lists */ $mc_lists = mailchimp_get_api_object('MailchimpLists'); $mc_lists->request('PUT', '/lists/{list_id}/members/{subscriber_hash}', $tokens, $parameters); } } }
It loops over the lists looking for contacts matching the user's original ID. If one is found, it makes a PUT request to update that contact's email. Since this is done in hook_entity_presave(), it completes before functions like mailchimp_lists_process_subscribe_form_choices(), which will then update the contact instead of adding a new one.
I feel like there must be a cleaner way to do this in the MC module proper, but it's been a long couple of weeks and I just need this working.
- Status changed to RTBC
10 months ago 5:59am 21 February 2024 - 🇬🇧United Kingdom matt b
I've been running in production with this patch for some time now. Let's just get this committed please!
- 🇺🇸United States bdimaggio Boston, MA
Hear you @Matt B! We've got this review (and hopefully commit/release) on the schedule for this coming week.
- 🇺🇸United States xenophyle
I'm thinking this won't work when the email address is on a referenced entity. So you have a content type with the mailchimp subscription field and maybe a reference to a user. The subscription field uses the user's email field. If the user entity gets updated, this module won't notice and be able to unsubscribe the old email.
Or does anyone have that working?
- Status changed to Needs work
10 months ago 2:46pm 8 March 2024 - 🇺🇸United States xenophyle
I've been working on this and hope to have a fix soon.
- Merge request !78Sync subscription email when updating an entity containing a subscribed email → (Open) created by xenophyle
- last update
10 months ago 17 pass - Open on Drupal.org →Core: 9.5.5 + Environment: PHP 7.4 & MySQL 5.7last update
9 months ago Not currently mergeable. - Open on Drupal.org →Core: 9.5.5 + Environment: PHP 7.4 & MySQL 5.7last update
8 months ago Not currently mergeable. - Open on Drupal.org →Core: 9.5.5 + Environment: PHP 7.4 & MySQL 5.7last update
8 months ago Not currently mergeable. - 🇺🇸United States xenophyle
@Matt B The scope has crept to include other merge data besides email, which has drawn this out into a major project. There is an MR in progress that needs testing and review.
- 🇬🇧United Kingdom matt b
Thanks for the update. I no longer use mailchimp due to poor service provision so migrated away last week.