protected function SensorCommerceTurnover::buildQuery in Monitoring 7
Builds the database query.
Return value
Overrides SensorDatabaseAggregator::buildQuery
File
- lib/
Drupal/ monitoring/ Sensor/ Sensors/ SensorCommerceTurnover.php, line 20 - Contains \Drupal\monitoring\Sensor\Sensors\SensorCommerceTurnover.
Class
- SensorCommerceTurnover
- Monitors commerce order turnover stats.
Namespace
Drupal\monitoring\Sensor\SensorsCode
protected function buildQuery() {
$query = parent::buildQuery();
// Get the field name for the amount field.
$field_amount = $this
->getFieldName($query, array(
'field' => 'commerce_order_total.amount',
));
// Build the field name based on that for the currency in the same table.
list($alias) = explode('.', $field_amount);
$field_currency = _field_sql_storage_columnname('commerce_order_total', 'currency_code');
// Get the amount sum.
$query
->addExpression('sum(' . $field_amount . ')', 'sum_amount');
$query
->addField($alias, $field_currency, 'currency_code');
$query
->groupBy($alias . '.' . $field_currency);
if ($currency_code = $this->info
->getSetting('currency_code')) {
$query
->condition($alias . '.' . $field_currency, $currency_code);
}
return $query;
}