From: Steve Sutton Date: Wed, 7 Nov 2018 17:39:43 +0000 (-0500) Subject: Adding mailchimp X-Git-Tag: v1.5.24^2 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=e1013feea0f09beca919211f20b934e069653ff7;p=web%2FGaylordGolfMecca.git Adding mailchimp Using php curl and the mailchimp 3.0 API. --- diff --git a/Toolkit/Contacts/ContactUs.php b/Toolkit/Contacts/ContactUs.php index 2579b6a..ec99548 100755 --- a/Toolkit/Contacts/ContactUs.php +++ b/Toolkit/Contacts/ContactUs.php @@ -1105,6 +1105,10 @@ class Toolkit_Contacts_ContactUs && CONSTANT_CONTACT) { $contact->attach(new Toolkit_LeadManager_ConstantContact()); } + if ( defined('MAILCHIMP_APP') + && MAILCHIMP_APP) { + $contact->attach(new Toolkit_LeadManager_MailChimp()); + } } $contact->save($this->dbh, false); return true; diff --git a/Toolkit/LeadManager/MailChimp.php b/Toolkit/LeadManager/MailChimp.php new file mode 100644 index 0000000..adb991f --- /dev/null +++ b/Toolkit/LeadManager/MailChimp.php @@ -0,0 +1,97 @@ + + * @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 + * @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(); + } + + // Test if this email is in the list + $ch = curl_init(); + $email = md5( strtolower( $subject->getEmail() ) ); + $url = 'https://us19.api.mailchimp.com/3.0/lists/'.MAILCHIMP_LISTID.'/members/'. $email; + $data = array( + 'email_address' => $subject->getEmail(), + 'status' => 'pending', + 'merge_fields' => array( + 'FNAME' => ($subject->getFname())?$subject->getFname():'', + 'LNAME' => ($subject->getLname())?$subject->getLname():'', + 'PHONE' => ($subject->getPhone())?$subject->getPhone():'', + ) + ); + // echo '
$data: ' . print_r( $data, true ) . '
'; + $jsonData = json_encode( $data ); + curl_setopt_array( + $ch, + array( + CURLOPT_URL => $url, + CURLOPT_USERPWD => MAILCHIMP_USER . ':' . MAILCHIMP_APIKEY, + CURLOPT_HTTPHEADER => array( 'Content-Type: application/json' ), + CURLOPT_RETURNTRANSFER => true, + CURLOPT_HEADER => false, + CURLOPT_POST => true, + CURLOPT_SSL_VERIFYPEER => false, + CURLOPT_CUSTOMREQUEST => 'PUT', + CURLOPT_POSTFIELDS => $jsonData, + ) + ); + $output = curl_exec( $ch ); + // echo '
$output: ' . print_r( json_decode( $output ), true ) . '
'; + // $info = curl_getinfo( $ch ); + // echo '
$info: ' . print_r( $info, true ) . '
'; + + } + + +} diff --git a/config/application.ini b/config/application.ini index 06dd760..e8dde2d 100644 --- a/config/application.ini +++ b/config/application.ini @@ -18,7 +18,7 @@ contactdb.html_email = "ON" ; STREAM SEND API ; Turn on the streamsend module to use with our contact application -contactdb.streamsend.application = On +contactdb.streamsend.application = Off ; Login id for the streamsend account contactdb.streamsend.login = "7KDfOTJvGNOH" ; Transaction key for the streamsend account @@ -43,6 +43,15 @@ constantcontact.apipath = Off ; example BeaverIslandBoatCo/lists/1 constantcontact.list.0 = Off +; MAILCHIMP API +contactdb.mcapi.application = On +; Mailchimp API key +contactdb.mcapi.apikey = "f78346e39590822f683c7572d25259f2-us19" +; Mailchimp List Id (List) +contactdb.mcapi.listId = "8b27bab6a8" +; Mailchimp username +contactdb.mcapi.user = "GolfMecca101"; + ; Turn the coupon application On or Off coupons.application = Off @@ -133,6 +142,9 @@ blocks.application = On ; development server configuration data inherits from production and ; overrides values as necessary [development : production] +contactdb.mcapi.apikey = "bc09e2b095b07e87e65169df37deacfd-us19" +contactdb.mcapi.listId = "af73c15416" +contactdb.mcapi.user = "steve@gaslightmedia.com"; ; chuck's server configuration data inherits from development ; and overrides values as necessary diff --git a/setup.phtml b/setup.phtml index 8c9e7be..40677f1 100644 --- a/setup.phtml +++ b/setup.phtml @@ -359,6 +359,10 @@ 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_USER', $applicationConfig->contactdb->mcapi->user); +define('MAILCHIMP_LISTID', $applicationConfig->contactdb->mcapi->listId); /** * Coupons Database Installed? */