Setting up for MailChimp
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 27 Jun 2013 15:58:46 +0000 (15:58 +0000)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 27 Jun 2013 15:58:46 +0000 (15:58 +0000)
example.php for testing working with Mailchimp API
adding to application.ini setting file the api key and list id

Toolkit/LeadManager/MailChimp.php [new file with mode: 0644]
config/application.ini
example.php [new file with mode: 0644]
setup.phtml

diff --git a/Toolkit/LeadManager/MailChimp.php b/Toolkit/LeadManager/MailChimp.php
new file mode 100644 (file)
index 0000000..ce6a722
--- /dev/null
@@ -0,0 +1,62 @@
+<?php
+
+/**
+ * MailChimp.php
+ *
+ * PHP version 5.3
+ *
+ * @category  Toolkit
+ * @package   LeadManager
+ * @author    Steve Sutton <steve@gaslightmedia.com>
+ * @copyright 2013 Gaslight Media
+ * @license   Gaslight Media
+ * @version   SVN: (0.1)
+ * @link      <>
+ */
+
+require_once GLM_APP_BASE . 'Common/LeadManager/Affiliates/MCAPI.class.php';
+/**
+ * Require the MCAPI Class
+ */
+/**
+ * Toolkit_LeadManager_MailChimp
+ *
+ * This class is an Observer class for setting up the contact forms
+ * with the ablity to send contact data to the MailChimp list.
+ *
+ * @category  Toolkit
+ * @package   LeadManager
+ * @author    Steve Sutton <steve@gaslightmedia.com>
+ * @copyright 2013 Gaslight Media
+ * @license   Gaslight Media
+ * @release   Release: (0.1)
+ * @link      <>
+ */
+class Toolkit_LeadManager_MailChimp
+    extends Toolkit_LeadManager_Observer
+{
+    public function send(Toolkit_LeadManager_Lead $subject)
+    {
+        // have to convert the $subject Object to an array to be used
+        // in the mailchimp call to add to list
+        $values = array(
+            'email_address' => $subject->getEmail(),
+            'first_name'    => $subject->getFname(),
+            'last_name'     => $subject->getLname(),
+            'city_name'     => $subject->getCity(),
+            'state_code'    => $subject->getState(),
+            'state_name'    => $GLOBALS['states'][$subject->getState()],
+            'zip_code'      => $subject->getZip(),
+            'home_number'   => $subject->getPhone()
+        );
+        if (is_a($subject, 'Toolkit_LeadManager_Contact')) {
+            $values['address_line_1'] = $subject->getAddress();
+            $values['address_line_2'] = $subject->getAddress2();
+        } else if (is_a($subject, 'Toolkit_LeadManager_Customer')) {
+            $values['address_line_1'] = $subject->getAdd1();
+            $values['address_line_2'] = $subject->getAdd2();
+        }
+    }
+
+
+}
index 3035774..2175994 100644 (file)
@@ -43,6 +43,13 @@ constantcontact.apipath = Off
 ; example BeaverIslandBoatCo/lists/1
 constantcontact.list.0 = Off
 
+; MAILCHIMP API
+contactdb.mcapi.application = On
+; Mailchimp API key
+contactdb.mcapi.apikey = "008fe0f365c71f5ea08aed546da40242-us6"
+; Mailchimp List Id
+contactdb.mcapi.listId = "8ed24143f7"
+
 ; Turn the coupon application On or Off
 coupons.application = Off
 
diff --git a/example.php b/example.php
new file mode 100644 (file)
index 0000000..3be8a28
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+require_once 'setup.phtml';
+require_once GLM_APP_BASE . 'Common/LeadManager/Affiliates/MCAPI.class.php';
+$testEmail = 'steve@gaslightmedia.com';
+//var_dump(MAILCHIMP_APIKEY);
+//var_dump(MAILCHIMP_APP);
+//var_dump(MAILCHIMP_LISTID);
+//var_dump($testEmail);
+//exit;
+$api = new MCAPI(MAILCHIMP_APIKEY);
+
+// get lists
+$ret = $api->lists();
+echo print_r($ret);
+exit;
+$mergVars = array(
+    'FNAME' => 'Test',
+    'LNAME' => 'Account',
+//    'GROUPINGS' => array(
+//        array('name' => 'Your Interests:', 'groups'=>'Bananas,Apples')
+//    )
+);
+$retVal = $api->listSubscribe(MAILCHIMP_LISTID, $testEmail, $mergVars);
+
+if ($api->errorCode) {
+    echo "Unable to load listSubscribe()!\n";
+    echo "\tCode=" . $api->errorCode. "\n";
+    echo "\tMsg=" . $api->errorMessage. "\n";
+} else {
+    echo "Subscribed - look for the confirmation email!\n";
+}
+
index 02b9229..3ea21d1 100644 (file)
@@ -356,6 +356,9 @@ define(
     'CONSTANT_CONTACT_LIST',
     serialize($applicationConfig->constantcontact->list->toArray())
 );
+define('MAILCHIMP_APP', $applicationConfig->contactdb->mcapi->application);
+define('MAILCHIMP_APIKEY', $applicationConfig->contactdb->mcapi->apikey);
+define('MAILCHIMP_LISTID', $applicationConfig->contactdb->mcapi->listId);
 /**
  * Coupons Database Installed?
  */