You are here

function _mailchimp_ecommerce_increment_order_total in Mailchimp E-Commerce 7

Increment order totals

File

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

Code

function _mailchimp_ecommerce_increment_order_total($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;
}