Jump to content

Synching Prestashop and MailChimp


MightyMouseofGod

Recommended Posts

I think my newsletter signup at the bottom of my homepage stopped working when we upgraded Prestashop to 1.7.8.10 and Mailchimp to v3.0.7 (it had been on 2.something previously). When you type in an email address and hit SUBSCRIBE it just reloads the home page and the email address doesn't appear in Prestashop or Mailchimp.

Looking into configuring the module it complained that I had 2 stores using the same Mailchimp list and I fixed that in the way it suggested. It's still asking me to press the Sync button. I'm more than a little concerned that although it shows the right number of products to sync in the list in Store Sync, there are far fewer customers and subscribers than there are in Prestashop or Mailchimp.

I have exported a contact list from Mailchimp as a backup but I'd still like to understand a bit more about what is going on.

I can give a temporary password to anyone willing to help.

Thanks

Debbie

Link to comment
Share on other sites

  • 2 weeks later...

Hi,

  • Firstly, Make sure that your Mailchimp API key is correctly configured in your Prestashop module settings.
  • Verify that the Mailchimp list ID is correctly set up in your PrestaShop module.
  • If the module is asking you to press the "Sync" button, it's possible that there's a synchronization issue between PrestaShop and Mailchimp. Try clicking the "Sync" button to initiate a manual synchronization.
  • In Mailchimp, check that the list you are syncing with Prestashop is set up correctly. Ensure that the list is active and able to receive new subscribers.
  • Clear the cache in Prestashop.

Thanks!

 

Link to comment
Share on other sites

Hi 

Recently Mailchimp Version was upgraded to a newer version from V2 to V3. Now the way of fetching the list and updating the list has completely changed. 

For Adding new users to the list try the below code

 

            $api_key = // Your API KEY;

            $list_id = // Your List ID;

            $Mailchimp = new Mailchimp($api_key);

            $result = $Mailchimp->post("lists/$list_id/members", array(

                'email_address' => trim($email),

                'status' => 'subscribed',

            )

            );

            $subscriber_hash = $Mailchimp->subscriberHash(trim($email));

            $Mailchimp->patch("lists/$list_id/members/$subscriber_hash", array('merge_fields' => array('FNAME' => $first_name, 'LNAME' => $last_name)));

 

For fetching the list you can refer to the below code

public function mailchimpGetLists($api_key = null)

    {

        if (trim($api_key) != '' && $api_key !== null) {

            try {

                $Mailchimp = new Mailchimp($api_key);

                $lists = $Mailchimp->get('lists');

                if ($lists !== false) {

                    $options = array();

                    foreach ($lists["lists"] as $list) {

                        $options["success"][] = array(

                            'value' => $list["id"],

                            'label' => $list["name"]

                        );

                    }

                } else {

                    $options["error"][] = array(

                        'value' => "0",

                        'label' => $this->l("No list found. (Verify Credentials)")

                    );

                }

            } catch (\Exception $e) {

                $options["error"][] = array(

                    'value' => "0",

                    'label' => $e->getMessage()

                );

            }

        } else {

            $options["error"][] = array(

                'value' => "0",

                'label' => $this->l("No list found. (Verify Credentials)")

            );

        }

 

        return $options;

    }

For using the code when the below library is imported to the desired location you can simply include the library like below

include_once(dirname(__FILE__) . '/libraries/drewm/mailchimp-api/src/MailChimp.php');

 I've attached the library here with the email which you can use in your code.

mailchimp-api.zip

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...