You are here

function uc_coupon_handler_field_all_orders_total::query in Ubercart Discount Coupons 7.3

Same name and namespace in other branches
  1. 7.2 views/uc_coupon_handler_field_all_orders_total.inc \uc_coupon_handler_field_all_orders_total::query()

Here we add the aggregate field that will sum the orders.

Overrides views_handler_field::query

2 methods override uc_coupon_handler_field_all_orders_total::query()
uc_coupon_handler_field_all_orders_gross::query in views/uc_coupon_handler_field_all_orders_gross.inc
Add the aggregate field that will sum total+value
uc_coupon_handler_field_all_orders_value::query in views/uc_coupon_handler_field_all_orders_value.inc
Here we add the aggregate field that will sum the value.

File

views/uc_coupon_handler_field_all_orders_total.inc, line 53
Coupon order total field handler

Class

uc_coupon_handler_field_all_orders_total
@file Coupon order total field handler

Code

function query() {
  $this
    ->ensure_my_table();
  $uco = $this->query
    ->ensure_table('uc_coupons_orders');
  $uo = $this->query
    ->ensure_table('uc_orders');
  $this
    ->add_additional_fields();
  if (empty($this->options['statuses'])) {

    // If no status specified, then we show all.
    $in_status = "1";
  }
  else {

    // An array of statuses was specified.
    $in_status = "{$uo}.order_status IN('" . implode("', '", $this->options['statuses']) . "')";
  }
  $this->field_alias = $this->query
    ->add_field(NULL, "CASE WHEN {$in_status} THEN {$uo}.order_total ELSE 0 END", $this->table_alias . '_' . $this->field . '_' . implode('_', $this->options['statuses']), array(
    'function' => 'sum',
  ));
}