You are here

function mailchimp_ecommerce_update_8002 in Mailchimp E-Commerce 8

Add 'orders_count', 'total_spent' to 'mailchimp_ecommerce_customer' table.

File

./mailchimp_ecommerce.install, line 63
Install, update and uninstall functions for the mailchimp_ecommerce module.

Code

function mailchimp_ecommerce_update_8002() {

  // Field to track total orders per customer.
  $orders_count = [
    'type' => 'int',
    'description' => 'Total orders for this customer.',
    'unsigned' => TRUE,
    'default' => 0,
  ];

  // Field to track total amount spent per customer.
  // `precision` and `scale` are based on the `price__number` column of the
  // `commerce_product_variation_field_data` table, provided by the
  // Drupal Commerce module.
  $total_spent = [
    'type' => 'numeric',
    'description' => 'Total amount spent by this customer.',
    'unsigned' => TRUE,
    'precision' => 19,
    'scale' => 6,
    'default' => 0,
  ];
  $schema = Database::getConnection()
    ->schema();
  $schema
    ->addField('mailchimp_ecommerce_customer', 'orders_count', $orders_count);
  $schema
    ->addField('mailchimp_ecommerce_customer', 'total_spent', $total_spent);
}