class OrderReport in Commerce Reporting 8
Same name in this branch
- 8 src/Entity/OrderReport.php \Drupal\commerce_reports\Entity\OrderReport
- 8 src/Plugin/Commerce/ReportType/OrderReport.php \Drupal\commerce_reports\Plugin\Commerce\ReportType\OrderReport
Provides the basic Order Report.
Plugin annotation
@CommerceReportType(
id = "order_report",
label = @Translation("Order Report"),
description = @Translation("Basic order report with order id, total, and created date")
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\commerce_reports\Plugin\Commerce\ReportType\ReportTypeBase implements ReportTypeInterface, ContainerFactoryPluginInterface
- class \Drupal\commerce_reports\Plugin\Commerce\ReportType\OrderReport
- class \Drupal\commerce_reports\Plugin\Commerce\ReportType\ReportTypeBase implements ReportTypeInterface, ContainerFactoryPluginInterface
Expanded class hierarchy of OrderReport
File
- src/
Plugin/ Commerce/ ReportType/ OrderReport.php, line 19
Namespace
Drupal\commerce_reports\Plugin\Commerce\ReportTypeView source
class OrderReport extends ReportTypeBase {
/**
* {@inheritdoc}
*/
public function buildFieldDefinitions() {
$fields = [];
$fields['order_type_id'] = BundleFieldDefinition::create('entity_reference')
->setLabel(t('Order type'))
->setDescription(t('The order type.'))
->setSetting('target_type', 'commerce_order_type')
->setReadOnly(TRUE);
$fields['amount'] = BundleFieldDefinition::create('commerce_price')
->setLabel(t('Total Amount'))
->setDescription(t('The total amount of the order'))
->setCardinality(1)
->setRequired(TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['mail'] = BundleFieldDefinition::create('email')
->setLabel(t('Contact email'))
->setDescription(t('The email address associated with the order.'))
->setCardinality(1)
->setSetting('max_length', 255)
->setRequired(TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['billing_address'] = BundleFieldDefinition::create('address')
->setLabel(t('Address'))
->setDescription(t('The store address.'))
->setCardinality(1)
->setRequired(TRUE)
->setDisplayConfigurable('view', TRUE);
return $fields;
}
/**
* {@inheritdoc}
*/
public function generateReports(OrderInterface $order) {
$billing_profile = $order
->getBillingProfile();
/** @var \Drupal\address\Plugin\Field\FieldType\AddressItem $address */
$address = $billing_profile
->get('address')
->first();
$values = [
'order_type_id' => $order
->bundle(),
'amount' => $order
->getTotalPrice(),
'mail' => $order
->getEmail(),
'billing_address' => $address
->toArray(),
];
$this
->createFromOrder($order, $values);
}
/**
* {@inheritdoc}
*/
public function buildQuery(QueryAggregateInterface $query) {
$query
->aggregate('mail', 'COUNT');
$query
->aggregate('amount.number', 'SUM');
$query
->aggregate('amount.number', 'AVG');
$query
->groupBy('amount.currency_code');
}
/**
* {@inheritdoc}
*/
protected function doBuildReportTableHeaders() {
return [
'formatted_date' => t('Date'),
'order_id_count' => t('# Orders'),
'mail_count' => t('# Customers'),
'amountnumber_sum' => t('Total revenue'),
'amountnumber_avg' => t('Average revenue'),
'amount_currency_code' => t('Currency'),
];
}
/**
* {@inheritdoc}
*/
protected function doBuildReportTableRow(array $result) {
$currency_code = $result['amount_currency_code'];
$row = [
$result['formatted_date'],
$result['order_id_count'],
$result['mail_count'],
[
'data' => [
'#type' => 'inline_template',
'#template' => '{{price|commerce_price_format}}',
'#context' => [
'price' => new Price($result['amountnumber_sum'], $currency_code),
],
],
],
[
'data' => [
'#type' => 'inline_template',
'#template' => '{{price|commerce_price_format}}',
'#context' => [
'price' => new Price($result['amountnumber_avg'], $currency_code),
],
],
],
$currency_code,
];
return $row;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
OrderReport:: |
public | function |
Builds the field definitions for entities of this bundle. Overrides BundlePluginInterface:: |
|
OrderReport:: |
public | function |
Builds the aggregate query. Overrides ReportTypeInterface:: |
|
OrderReport:: |
protected | function |
Builds the report table headers. Overrides ReportTypeBase:: |
|
OrderReport:: |
protected | function |
Build the report table row. Overrides ReportTypeBase:: |
|
OrderReport:: |
public | function |
Generates order reports for an order. Overrides ReportTypeInterface:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
ReportTypeBase:: |
protected | property | The order report storage. | |
ReportTypeBase:: |
public | function |
Build a report table from query results. Overrides ReportTypeInterface:: |
|
ReportTypeBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
2 |
ReportTypeBase:: |
public | function |
Creates a new order report using the given order and values. Overrides ReportTypeInterface:: |
|
ReportTypeBase:: |
public | function |
Gets the order report type description. Overrides ReportTypeInterface:: |
|
ReportTypeBase:: |
public | function |
Gets the order report type label. Overrides ReportTypeInterface:: |
|
ReportTypeBase:: |
public | function |
Constructs a new ReportTypeBase object. Overrides PluginBase:: |
2 |