public function CustomerHandler::incrementCustomerOrderTotal in Mailchimp E-Commerce 8
@inheritdoc
Overrides CustomerHandlerInterface::incrementCustomerOrderTotal
File
- src/
CustomerHandler.php, line 194
Class
- CustomerHandler
- Customer handler.
Namespace
Drupal\mailchimp_ecommerceCode
public function incrementCustomerOrderTotal($email_address, $total_spent, $orders_count = 1) {
$query = $this->database
->select('mailchimp_ecommerce_customer', 'c')
->fields('c', [
'mailchimp_customer_id',
'orders_count',
'total_spent',
])
->condition('mail', $email_address);
$result = $query
->execute()
->fetch();
if (!empty($result)) {
$customer_id = $result->mailchimp_customer_id;
$new_orders_count = $result->orders_count + $orders_count;
$new_total_spent = $result->total_spent + $total_spent;
$this->database
->update('mailchimp_ecommerce_customer')
->fields([
'orders_count' => $new_orders_count,
'total_spent' => $new_total_spent,
])
->condition('mailchimp_customer_id', $customer_id)
->execute();
return TRUE;
}
return FALSE;
}