You are here

public function OrderItemsReport::generateReports in Commerce Reporting 8

Generates order reports for an order.

Parameters

\Drupal\commerce_order\Entity\OrderInterface $order: The order.

Overrides ReportTypeInterface::generateReports

File

src/Plugin/Commerce/ReportType/OrderItemsReport.php, line 126

Class

OrderItemsReport
Provides the Order Items Report.

Namespace

Drupal\commerce_reports\Plugin\Commerce\ReportType

Code

public function generateReports(OrderInterface $order) {
  foreach ($order
    ->getItems() as $order_item) {
    $values = [
      'order_item_type_id' => $order_item
        ->bundle(),
      'order_item_id' => $order_item
        ->id(),
      'title' => $order_item
        ->label(),
      'quantity' => $order_item
        ->getQuantity(),
      'unit_price' => $order_item
        ->getUnitPrice(),
      'total_price' => $order_item
        ->getTotalPrice(),
      'adjusted_unit_price' => $order_item
        ->getAdjustedUnitPrice(),
      'adjusted_total_price' => $order_item
        ->getAdjustedTotalPrice(),
    ];
    $this
      ->createFromOrder($order, $values);
  }
}