You are here

public function CustomerHandler::getCustomer in Mailchimp E-Commerce 8

@inheritdoc

Overrides CustomerHandlerInterface::getCustomer

File

src/CustomerHandler.php, line 32

Class

CustomerHandler
Customer handler.

Namespace

Drupal\mailchimp_ecommerce

Code

public function getCustomer($customer_id) {
  $customer = NULL;
  try {
    $store_id = mailchimp_ecommerce_get_store_id();
    if (empty($store_id)) {
      throw new \Exception('Cannot get a customer without a store ID.');
    }

    /* @var \Mailchimp\MailchimpEcommerce $mc_ecommerce */
    $mc_ecommerce = mailchimp_get_api_object('MailchimpEcommerce');
    $customer = $mc_ecommerce
      ->getCustomer($store_id, $customer_id);
  } catch (\Exception $e) {
    if ($e
      ->getCode() == 404) {

      // Customer doesn't exist in the store; no need to log an error.
    }
    else {
      mailchimp_ecommerce_log_error_message('Unable to delete a customer: ' . $e
        ->getMessage());
      drupal_set_message($e
        ->getMessage(), 'error');
    }
  }
  return $customer;
}