public function CustomerHandler::loadCustomerId in Mailchimp E-Commerce 8
@inheritdoc
Overrides CustomerHandlerInterface::loadCustomerId
1 call to CustomerHandler::loadCustomerId()
- CustomerHandler::buildCustomer in src/
CustomerHandler.php - @inheritdoc
File
- src/
CustomerHandler.php, line 115
Class
- CustomerHandler
- Customer handler.
Namespace
Drupal\mailchimp_ecommerceCode
public function loadCustomerId($email) {
$customer = [];
// Load an existing customer using the email.
$query = $this->database
->select('mailchimp_ecommerce_customer', 'c')
->fields('c', [
'mailchimp_customer_id',
])
->condition('mail', $email);
$result = $query
->execute()
->fetch();
if (!empty($result)) {
$customer_id = $result->mailchimp_customer_id;
}
// Create a new customer if no customer is attached to the order.
if (empty($customer_id)) {
$customer_id = $result = $this->database
->insert('mailchimp_ecommerce_customer')
->fields([
'mail' => $email,
])
->execute();
}
return $customer_id;
}