Allright, coded the update function after my diner. When a customer updates his or her information on the "my account" page, this change will be synced with your Mail Chimp list. Here's how I dit it:
In mailchimp_functions.php from this great module I added my own function at the end of the file. Note that I added a field for Firstname and Lastname. You can do that, but if you don't want to just delete everything with firstname and lastname in it:
In htdocs/includes/templates/YOURTEMPLATE/templates/tpl_account_edit_default.php you must make an invisible field to be able to pass the old email address (email_address_old) to the mailchimp_update() function. I've placed this line below the entry for the e-mail address, but you can paste in anywhere as long as it is within the form:PHP Code://Mailchimp update function: update customers data to the mailchimp list.
function mailchimp_update($email_address_old, $email_address, $firstname, $lastname, $email_format) {
include_once(DIR_WS_CLASSES . "MCAPI.class.php");
$api = new MCAPI(BOX_MAILCHIMP_NEWSLETTER_API_KEY);
$merge_vars = array('FNAME'=>$firstname, 'LNAME'=>$lastname, 'EMAIL'=>$email_address);
if ($email_format == 'TEXT') {
$format = 'text';
} else {
$format = 'html';
}
$list_id = BOX_MAILCHIMP_NEWSLETTER_ID;
$retval = $api->listUpdateMember($list_id, $email_address_old, $merge_vars, $format);
if ($api->errorCode){
$errorMessage = "Unable to update member info with listUpdateMember()!\n" .
"\tCode=".$api->errorCode."\n" .
"\tMsg=".$api->errorMessage."\n";
$file = DIR_FS_SQL_CACHE . '/' . 'MailChimp.log';
if ($fp = @fopen($file, 'a')) {
fwrite($fp, $errorMessage);
fclose($fp);
}
}
}
At last you must make a call to the function. When the form is submitted it will use /includes/modules/pages/account_edit/header_php.php to make all the magic happen. Paste the following around line 154 above the line:PHP Code:<?php echo zen_draw_hidden_field('email_address_old', $account->fields['customers_email_address'], 'id="email-address-old"') ?>
$zco_notifier->notify('NOTIFY_HEADER_ACCOUNT_EDIT_UPDATES_COMPLETE');
That's all! Now your mailchimp list will be updated as soon as your customer edits his or her information! Next thing to do is to make a sync for the "Subscribe or unsubscribe from newsletters." page.PHP Code:mailchimp_update($email_address_old, $email_address, $firstname, $lastname, $email_format);


Reply With Quote
