You are here

function _mailchimp_ecommerce_get_local_customer in Mailchimp E-Commerce 7

@inheritdoc

4 calls to _mailchimp_ecommerce_get_local_customer()
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_build_order in modules/mailchimp_ecommerce_ubercart/mailchimp_ecommerce_ubercart.module
Builds a Mailchimp order from an Ubercart order.
_mailchimp_ecommerce_commerce_build_order in modules/mailchimp_ecommerce_commerce/mailchimp_ecommerce_commerce.module
Builds a Mailchimp order from a Commerce order.

File

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

Code

function _mailchimp_ecommerce_get_local_customer($email) {

  // Load an existing customer using the order email.
  $result = db_query("SELECT mailchimp_customer_id FROM {mailchimp_ecommerce_customer} WHERE mail = :mail", [
    ':mail' => $email,
  ]);
  $customer_id = NULL;
  $customer = $result
    ->fetchAssoc();
  if (!empty($customer)) {
    $customer_id = $customer['mailchimp_customer_id'];
  }
  if (empty($customer_id)) {

    // Create a new local customer.
    $customer_id = db_insert('mailchimp_ecommerce_customer')
      ->fields([
      'mail' => $email,
    ])
      ->execute();
  }
  return $customer_id;
}