Skip to content

Instantly share code, notes, and snippets.

@pmeissner
Created June 4, 2011 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmeissner/1007782 to your computer and use it in GitHub Desktop.
Save pmeissner/1007782 to your computer and use it in GitHub Desktop.
LemonStand AJAX Handler for MailChimp function
function process_mailing_list($controller)
{
if (post('mailinglist_signup')) {
$url = "https://us2.api.mailchimp.com/1.2/?output=php&method=listSubscribe";
$data = Shop_CheckoutData::get_billing_info();
$country = Shop_Country::create()->find($data->country);
$state = Shop_CountryState::create()->find($data->state);
$fields = array(
'FNAME' => $data->first_name,
'LNAME' => $data->last_name,
'FORM_LOCAT' => 'rt-reg',
'STREET' => $data->street_address,
'CITY' => $data->city,
'STATE' => $state->name,
'ZIP' => $data->zip,
'COUNTRY' => $country->name
);
$postdata = http_build_query(
array(
'apikey' => '',
'id' => '',
'email_address' => $data->email,
'merge_vars' => $fields,
'email_type' => 'html',
'double_option' => true,
'update_existing' => true
)
);
$options = array(
'http' => array(
'method' => 'POST',
'content' => $postdata,
'header' => 'Content-Type: application/x-www-form-urlencoded'
)
);
$context = stream_context_create( $options );
$return = file_get_contents( $url, false, $context );
}
$controller->action();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment