Page 1 of 2 12 LastLast
Results 1 to 10 of 403

Hybrid View

  1. #1
    Join Date
    Apr 2013
    Location
    Netherlands
    Posts
    12
    Plugin Contributions
    0

    Default Re: MailChimp Newsletter Sidebox

    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:

    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);
              }
        }
     } 
    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:
    <?php echo zen_draw_hidden_field('email_address_old'$account->fields['customers_email_address'], 'id="email-address-old"'?>
    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:
    $zco_notifier->notify('NOTIFY_HEADER_ACCOUNT_EDIT_UPDATES_COMPLETE');

    PHP Code:
    mailchimp_update($email_address_old$email_address$firstname$lastname$email_format); 
    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.

  2. #2
    Join Date
    Apr 2013
    Location
    Netherlands
    Posts
    12
    Plugin Contributions
    0

    Default Re: MailChimp Newsletter Sidebox

    Note: Only usefull if you've included additional info in your mailchimp list such as first name, last name, country etc.

    I've made a really small improvement.

    I noticed that when a non-customer signs up for the maillinglist with the sidebox module the customer is added to the mailchimp list as supposed to. But when that non-costumer is going to be your customer, the API doesn't update the name field and lastname field (this is only if you've made some changes yourself to the original code to include additional customer information). With a really small change you can let the mailchimp API update the information as soon as the non-costumer becomes a customer.

    In mailchimp_functions.php add
    PHP Code:
    $update_existing true 
    so that the line becomes (in my case)
    PHP Code:
    $retval $api->listSubscribe($list_id$email_address$merge_vars$format$double_optin false$update_existing true); 
    When a newsletter only person signs up for a new account, all the info will be automatically updated to mailchimp!

  3. #3
    Join Date
    May 2011
    Location
    Nova Scotia
    Posts
    35
    Plugin Contributions
    0

    Default Re: MailChimp Newsletter Sidebox

    Quote Originally Posted by MaartenJ View Post
    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:

    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);
              }
        }
     } 
    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:
    <?php echo zen_draw_hidden_field('email_address_old'$account->fields['customers_email_address'], 'id="email-address-old"'?>
    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:
    $zco_notifier->notify('NOTIFY_HEADER_ACCOUNT_EDIT_UPDATES_COMPLETE');

    PHP Code:
    mailchimp_update($email_address_old$email_address$firstname$lastname$email_format); 
    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.
    I would like to do this can anyone see if there is anything wrong with the code above as my customers can sign up using create account or side box it works perfect. If that person unsubscribes from my account link it works fine but if they click the check-box from my account to signup again it does not resign them up.

  4. #4
    Join Date
    Feb 2009
    Location
    UK
    Posts
    1,303
    Plugin Contributions
    1

    Default Re: MailChimp Newsletter Sidebox

    This is a bit of an ask but would anyone be able to share how, using v3 of the API, to update a members email address in the MailChimp list when it is edited in ZC's account_edit page. I believe this can be achieved by using the API's 'PATCH' command. This post has a solution for an earlier API version - which I've attempted to adapt, without success.
    Simon

  5. #5
    Join Date
    Feb 2009
    Location
    UK
    Posts
    1,303
    Plugin Contributions
    1

    Default Re: MailChimp Newsletter Sidebox

    Quote Originally Posted by simon1066 View Post
    This is a bit of an ask but would anyone be able to share how, using v3 of the API, to update a members email address in the MailChimp list when it is edited in ZC's account_edit page. I believe this can be achieved by using the API's 'PATCH' command. This post has a solution for an earlier API version - which I've attempted to adapt, without success.
    Here's what I have so far:

    templates/tpl_account_edit_default.php
    Code:
    <?php echo zen_draw_hidden_field('email_address_old', $account->fields['customers_email_address'], 'id="email-address-old"') ?>
    pages/account_edit/header_php.php
    Code:
    mailchimp_update($email_address_old, $email_address);  
    
    $zco_notifier->notify('NOTIFY_HEADER_ACCOUNT_EDIT_UPDATES_COMPLETE');
    extra_functions/mailchimp_functions.php
    Code:
    function mailchimp_update($email_address_old, $email) {
        $mailchimp = new MailChimp(BOX_MAILCHIMP_NEWSLETTER_API_KEY);
    
        $reply = $mailchimp->list_update_subscriber([
           'id_list' => BOX_MAILCHIMP_NEWSLETTER_ID,
           'email' => $email,
    	   'status' => 'subscribed'
        ]);
    
        if (isset($reply->type)) { 
            $errorMessage = "Unable to run update_subscriber command()!\n" . 
               "\tMsg=" . print_r($reply, true) . "\n";
              $file = DIR_FS_LOGS . '/' . 'MailChimp.log';
              if ($fp = @fopen($file, 'a')) {
                fwrite($fp, $errorMessage);
                fclose($fp);
              }
        }
     }
    extra_functions/mailchimp.php
    Code:
    public function list_update_subscriber(Array $options)
        {
            // Check required params
            if ( ! isset($options['id_list']) OR ! isset($options['email']))
            {
                throw new MailChimpException('Parameters not set on '.__METHOD__);
            }
            $subscriber_hash = md5(strtolower($options['email'])); 
            $endpoint = '/lists/' . $options['id_list'] . '/members/' . $subscriber_hash;
           $payload = [
                'email_address' => $options['email'],
                'status' => 'subscribed'           
            ];
            
            return $this->_execute_request('PATCH', $endpoint, $payload);
        }
    If I use 'PUT' instead of 'PATCH' it adds the new address to the Mailchimp members list - so I guess something is working.
    Simon

  6. #6
    Join Date
    Feb 2009
    Location
    UK
    Posts
    1,303
    Plugin Contributions
    1

    Default Re: MailChimp Newsletter Sidebox

    ZC v1.5.7c
    PHP v7.3

    I've updated my mailchimp.php with the patch for PATCH from @swguy's github contribution. I'm guessing that the issue lies somewhere in the other three edited files.
    Last edited by simon1066; 7 Jan 2022 at 09:55 AM. Reason: Versions
    Simon

  7. #7
    Join Date
    Feb 2009
    Location
    UK
    Posts
    1,303
    Plugin Contributions
    1

    Default Re: MailChimp Newsletter Sidebox

    Quote Originally Posted by simon1066 View Post
    ZC v1.5.7c
    PHP v7.3

    I've updated my mailchimp.php with the patch for PATCH from @swguy's github contribution. I'm guessing that the issue lies somewhere in the other three edited files.
    I've had to give up on being able to have changes of email address in ZC updated on Mailchimp's member's list (although I've confirmed that PATCH is functioning I'm unable to get the change of email to work). I thought I would post my documentation on this tweak to @swguy's mod.

    Mailchimp allows for a list of subscribers to be segregated (into Groups) based on the selection made when completing the sign-up form, such as:

    Click image for larger version. 

Name:	Screenshot 2022-01-09 145041.png 
Views:	82 
Size:	7.4 KB 
ID:	19878

    This is useful for sending different newsletters to different subscribers. However, if a subscriber signs up for newsletters on a ZC website, no groups are transferred to Mailchimp - meaning those subscribers will be missed if solely relying on groups to send newsletters.

    Until I manage (not guaranteed) to add the relevant checkboxes to the account_newsletters page I have assumed that a subscriber on my website will automatically be signed up for both groups (wording the descriptive text on the signup page accordingly). To achieve this here are the relevant code additions (in red):

    includes/languages/english/extra_definitions/mailchimp_sidebox_defines.php
    Code:
    define('BOX_MAILCHIMP_NEWSLETTER_ID','xxxxxxxxxx');  
    define('BOX_MAILCHIMP_NEWSLETTER_U','yyyyyyyyyy');  
    define('BOX_MAILCHIMP_NEWSLETTER_URL','http://YourSite.us1.list-manage.com/subscribe/post');  
    define('BOX_MAILCHIMP_NEWSLETTER_API_KEY','xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
    
    define('MAILCHIMP_INTEREST_ID_A','aaaaaaaaaaa'); 
    define('MAILCHIMP_INTEREST_ID_B','bbbbbbbbbbb');  
    
    // Language defines for newsletter sidebox
    define('BOX_HEADING_MAILCHIMP_SIDEBOX', 'Newsletter'); 
    define('BOX_MAILCHIMP_PITCH', 'Subscribe to our newsletter for periodic updates and valuable coupons.'); 
    define('BOX_MAILCHIMP_SUBSCRIBE', 'Subscribe');
    includes/functions/extra_functions/mailchimp_functions.php
    Code:
     function mailchimp_add($email) {
        $mailchimp = new MailChimp(BOX_MAILCHIMP_NEWSLETTER_API_KEY);
        $reply = $mailchimp->list_add_subscriber([
           'id_list' => BOX_MAILCHIMP_NEWSLETTER_ID,
           'interest_id_A' => MAILCHIMP_INTEREST_ID_A,
           'interest_id_B' => MAILCHIMP_INTEREST_ID_B,
           'email' => $email,
           'status' => 'pending'
        ]);
    includes/functions/extra_functions/mailchimp.php
    Code:
    public function list_add_subscriber(Array $options)
        {
            // Check required params
            if ( ! isset($options['id_list']) OR ! isset($options['email']))
            {
                throw new MailChimpException('Parameters not set on '.__METHOD__);
            }
    
            $endpoint = '/lists/' . $options['id_list'] . '/members/';
            $payload = [
                'email_address' => $options['email'],
                'status' => 'subscribed',			
    	    'interests' => array(
    		$options['interest_id_A'] => true,
    		$options['interest_id_B'] => true
    		)			
                // 'status' => isset($options['status']) ? $options['status'] : 'pending',
            ];
            if (isset($options['merge_fields']) AND $options['merge_fields'])
            {
                $payload['merge_fields'] = $options['merge_fields'];
            }
    
            return $this->_execute_request('POST', $endpoint, $payload);
        }
    Notes: Groups in Mailchimp dev talk are 'interests'. Finding the appropriate id of an interest (to add to the language file) is not straightforward. These days the only way to find these out is via an API call. Add the following code to a new php file in the root directory of your website and run it in a browser e.g. mywebsite[dot]com/mynewfile.php. The code is on this page, but I'll include it here in case it disappears.
    Code:
    <?php
    $api_key = 'xxxxxxxxxxxxxxxxxxx-us13'; // your api key
    $server = 'us13.'; // your server
    
    $list_id = 'xxxxxxxxxxxxx'; // your list id
    $group_id = 'xxxxxxxxxxxx'; // your group id
    
    $auth = base64_encode( 'user:'.$api_key );
    	
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://'.$server.'api.mailchimp.com/3.0/lists/'.$list_id.'/interest-categories/'.$group_id.'/interests');
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json',
    	'Authorization: Basic '.$auth));
    curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    
    $result = curl_exec($ch);
    
    $result_obj = json_decode($result);
    
    foreach ($result_obj->interests as $obj) {
    	echo $obj->id . ' - ' . $obj->name;
    	echo '<br />';
    }
    
    echo '<pre>'; print_r($result_obj); echo '</pre>';
    ?>
    Attached Images Attached Images  
    Last edited by simon1066; 9 Jan 2022 at 04:44 PM.
    Simon

  8. #8
    Join Date
    Aug 2005
    Location
    Trujillo Alto, Puerto Rico
    Posts
    1,550
    Plugin Contributions
    9

    Default Re: MailChimp Newsletter Sidebox

    I believe <<<This is of course MY opinion>>> that updating and developing the MooSend module is the way to go. They already have a module to sync with ZC and do some automations (like abandoned cart or getting into a list). Their service is cheaper and you can create different lists (groups like you call them) for your newsletters, without paying extra. Much more of a selection of templates and some free features that Mailchimp doesn't offer on their free tier.

    The only feature that Mailchip offers for free that MooSend doesn't is the "post on social media" after a newsletter is sent.
    IDEAS Girl
    IDEAS Creative Group
    = Your image... our business!

  9. #9
    Join Date
    Feb 2009
    Location
    UK
    Posts
    1,303
    Plugin Contributions
    1

    Default Re: MailChimp Newsletter Sidebox

    Quote Originally Posted by ideasgirl View Post
    I believe <<<This is of course MY opinion>>> that updating and developing the MooSend module is the way to go. They already have a module to sync with ZC and do some automations (like abandoned cart or getting into a list). Their service is cheaper and you can create different lists (groups like you call them) for your newsletters, without paying extra. Much more of a selection of templates and some free features that Mailchimp doesn't offer on their free tier.

    The only feature that Mailchip offers for free that MooSend doesn't is the "post on social media" after a newsletter is sent.
    Thanks for this, that's interesting. I'll take a look.
    Simon

  10. #10
    Join Date
    Mar 2006
    Location
    Auckland, New Zealand
    Posts
    245
    Plugin Contributions
    0

    Default Re: MailChimp Newsletter Sidebox

    Quote Originally Posted by simon1066 View Post
    I've had to give up on being able to have changes of email address in ZC updated on Mailchimp's member's list (although I've confirmed that PATCH is functioning I'm unable to get the change of email to work). I thought I would post my documentation on this tweak to @swguy's mod.
    Thanks for working this out Simon, I will integrate it this week :-)
    Elemi

    The Art of Bespoke Aromatherapy
    www.AmorAromatherapy.co.nz

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v150 Newsletter Sidebox & Newsletter signup
    By meljen in forum Templates, Stylesheets, Page Layout
    Replies: 4
    Last Post: 28 Nov 2012, 09:44 PM
  2. Login page->Newsletter->Mailchimp
    By Happyworker in forum All Other Contributions/Addons
    Replies: 9
    Last Post: 23 Jun 2010, 10:41 PM
  3. Anyone know how to add field for Mailchimp to sidebox?
    By daneh in forum All Other Contributions/Addons
    Replies: 1
    Last Post: 16 Sep 2009, 04:40 PM
  4. Adding a user to a MailChimp newsletter?
    By fabiola-and-singsing in forum General Questions
    Replies: 3
    Last Post: 16 Feb 2009, 10:07 AM
  5. Stop Sidebox header from linking - MailChimp
    By Mickmo68 in forum Addon Sideboxes
    Replies: 2
    Last Post: 21 Nov 2008, 05:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg