You are here

function mailchimp_ecommerce_update_customer in Mailchimp E-Commerce 7

Update a customer record in Mailchimp.

Parameters

array $customer: Array of customer fields.

See also

http://developer.mailchimp.com/documentation/mailchimp/reference/ecommer...

5 calls to mailchimp_ecommerce_update_customer()
mailchimp_ecommerce_commerce_batch_add_orders in modules/mailchimp_ecommerce_commerce/mailchimp_ecommerce_commerce.module
Batch callback used to add orders to MailChimp.
mailchimp_ecommerce_commerce_commerce_customer_profile_insert in modules/mailchimp_ecommerce_commerce/mailchimp_ecommerce_commerce.module
Implements hook_commerce_customer_profile_insert().
mailchimp_ecommerce_commerce_commerce_customer_profile_update in modules/mailchimp_ecommerce_commerce/mailchimp_ecommerce_commerce.module
Implements hook_commerce_customer_profile_update().
mailchimp_ecommerce_ubercart_batch_add_orders in modules/mailchimp_ecommerce_ubercart/mailchimp_ecommerce_ubercart.module
Batch callback used to add orders to Mailchimp.
mailchimp_ecommerce_ubercart_uc_order in modules/mailchimp_ecommerce_ubercart/mailchimp_ecommerce_ubercart.module
Implements hook_uc_order().

File

./mailchimp_ecommerce.module, line 355
Mailchimp eCommerce core functionality.

Code

function mailchimp_ecommerce_update_customer($customer) {
  try {
    $store_id = mailchimp_ecommerce_get_store_id();
    $list_id = mailchimp_ecommerce_get_list_id();
    if (empty($store_id)) {
      throw new Exception('Cannot update a customer without a store ID.');
    }

    /* @var \Mailchimp\MailchimpEcommerce $mc_ecommerce */
    $mc_ecommerce = mailchimp_get_api_object('MailchimpEcommerce');

    // Pull member information to get member status.
    $memberinfo = mailchimp_get_memberinfo($list_id, $customer['email_address'], TRUE);
    $customer['opt_in_status'] = isset($memberinfo->status) && $memberinfo->status == 'subscribed' ? TRUE : FALSE;
    $mc_ecommerce
      ->updateCustomer($store_id, $customer);
  } catch (Exception $e) {
    mailchimp_ecommerce_log_error_message('Unable to update a customer: ' . $e
      ->getMessage());
    mailchimp_ecommerce_show_error($e
      ->getMessage());
  }
}