Hello,

When I edit user profile fields, which are displayed in separate tabs as categories, and click on 'Save' on the profile category, the changes do not sync with the mailchimp list.
But if I click on 'Save settings' on the Newsletters tab on the user profile page, the changes are synced. But practically this is not going to be the case.

I did come across this issue earlier on http://drupal.org/node/605246, but I do not think there had been a solution.

Please advise.
Thanks!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

levelos’s picture

Status: Active » Closed (works as designed)

For lists that are currently not set to required, this is indeed the case. Required lists have all settings and profile data synced whenever a change to a user object is made. But opt-in/out lists only have their settings saved when you actually submit the newsletter form. I had to make this decision in order to solve some other issues by placing all the information on the same tab. Open to suggestions for a better solution, but in the meantime, perhaps your lists could be set to required.

jm.federico’s picture

Hi Guys

Here I have a temporary solution for people in need of this functionality.

Within your own module create this function:

function YOUR_MODULE_HERE_user($op, &$edit, &$account, $category = NULL){
  switch ($op){
    case 'update':
      /**
       * Lets complement the MAILCHIMP module to synch profiles and e-mail
       * when a user updates his/her profile and a list is not set as required *drupal.org/comment/reply/770528
       */
       $old_mail = $account->mail;
       $new_mail = $edit['mail'];
       if($old_mail != $new_mail && $new_mail){
         $mc_api = 'YOUR API';
         // Get lists it is subscribed to
         $lists = unserialize(file_get_contents("http://LAST DIGITS OF THE API AFTER THE "-".api.mailchimp.com/1.2/?output=php&method=listsForEmail&apikey=$mc_api&email_address=$account->mail"));
         foreach($lists as $list){
           // Update e-mail
           file_get_contents("http://LAST DIGITS OF THE API AFTER THE "-".api.mailchimp.com/1.2/?output=php&method=listUpdateMember&apikey=$mc_api&id=$list&email_address=$old_mail&merge_vars[EMAIL]=$new_mail");
         }
       }
       break;
     case 'delete':
      /**
       * Lets complement the MAILCHIMP module to synch profiles and e-mail
       * when a user delete his/her profile and a list is not set as required *drupal.org/comment/reply/770528
       */
       $old_mail = $account->mail;
       $mc_api = 'YOUR API';
       // Get lists it is subscribed to
       $lists = unserialize(file_get_contents("http://LAST DIGITS OF THE API AFTER THE "-".api.mailchimp.com/1.2/?output=php&method=listsForEmail&apikey=$mc_api&email_address=$account->mail"));
       foreach($lists as $list){
         // Delete e-mail
         file_get_contents("http://LAST DIGITS OF THE API AFTER THE "-".api.mailchimp.com/1.2/?output=php&method=listUnsubscribe&apikey=$mc_api&id=$list&email_address=$old_mail&delete_member=TRUE");
       }
       break;
  }
}

This will takes care of updating the e-mail and deleing it if users deletes the account in Drupal.
I am not mapping other fields, but you could use MAIL CHIMP'S api to do it.

It is by all means no perfect:

  • there is no error checking
  • no feedback on the results
  • Haven't tested when some lists are set as required
  • for me it does the job

Federico

douggreen’s picture

Version: 6.x-2.0-rc4 » 7.x-2.5
Component: Code » General

I just want to confirm that this is still true in the current version (well, actually I'm one version off, but confirming the current version is good).

If a user changes their email address, then only the "required" lists are re-synced. The non-required lists are not synced. Thus if a user changes their email address, any subscriptions to non-required lists remain on the old email address. This really seems like a bug, but if I read this ticket right, it's intentional. Is that right?

douggreen’s picture

Component: General » Lists
Status: Closed (works as designed) » Active
douggreen’s picture

Status: Active » Needs review
FileSize
3.95 KB

Given that @levelos says that this was just a UI problem, I took a stab at a fix, including fixing the UI.

dsnopek’s picture

Assigned: apramakr » Unassigned
Status: Needs review » Reviewed & tested by the community
FileSize
3.67 KB

I have re-rolled the patch from douggreen against the latest git 7.x-2.x. It works perfectly for me!

With this patch, when a user save changes on their account page (for example, their "Username" which I have connected to the Mailchimp FNAME mergevar) it will be immediately reflected in Mailchimp -- for both optional and required lists. (Without the patch this only works for required lists.)

douggreen’s picture

Version: 7.x-2.5 » 7.x-2.7
Status: Reviewed & tested by the community » Needs review
FileSize
5.55 KB

This new patch (rolled for 7.x-2.7) updates list groupings mergevars, which is necessary when using this to subdivide a list. It also forces removal of the old email from all lists, even when the role doesn't change.

Khumbu’s picture

Tested it and I can confirm that this works....thx...you made my christmas :)

levelos’s picture

Assigned: Unassigned » gcb
gcb’s picture

Status: Needs review » Fixed

Thanks for the patch fellas! Rolled into the latest batch of commits with a few minor tweaks to work with another patch to the list syncing behavior. We'll roll into a release shortly.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.