You are here

function commerce_reports_handler_field_productquantity::pre_query in Commerce Reporting 7.2

Run before the view is built.

This gives all the handlers some time to set up before any handler has been fully run.

Overrides views_handler::pre_query

File

includes/views/commerce_reports_handler_field_productquantity.inc, line 15

Class

commerce_reports_handler_field_productquantity
Field handler to get the quantity of products in an order.

Code

function pre_query() {
  $query = db_select('commerce_line_item', 'li')
    ->fields('li', array(
    'order_id',
  ))
    ->condition('type', 'product')
    ->groupBy('order_id');
  $query
    ->addExpression('SUM(quantity)', 'quantity');
  $res = $query
    ->execute();
  $rows = $res
    ->fetchAllAssoc('order_id', PDO::FETCH_ASSOC);
  $map = array();
  foreach ($rows as $order_id => $row) {
    $map[$order_id] = $row['quantity'];
  }
  $this->items['productquantity'] = $map;
}