You are here

public function OrderReportGenerator::refreshReports in Commerce Reporting 8

Refreshes order reports for the given order IDs.

In addition to generating new order reports for orders that have not yet been processed, existing order reports are replaced with new order reports, using the orders' current data. Specify a report type plugin id to generate reports for a single report type; otherwise, reports for all types will be generated.

Parameters

array $order_ids: An array of order IDs.

string $plugin_id: (optional) The report type plugin id to be used to generate reports.

Return value

int The number of orders for which reports were generated.

Throws

\Drupal\Core\Entity\EntityStorageException

Overrides OrderReportGeneratorInterface::refreshReports

File

src/OrderReportGenerator.php, line 84

Class

OrderReportGenerator
Generates order reports for orders.

Namespace

Drupal\commerce_reports

Code

public function refreshReports(array $order_ids, $plugin_id = NULL) {

  // Delete any existing reports.
  $query = $this->orderReportStorage
    ->getQuery()
    ->condition('order_id', $order_ids, 'IN');
  if ($plugin_id) {
    $query
      ->condition('type', $plugin_id);
  }
  $order_report_ids = $query
    ->execute();
  $reports = $this->orderReportStorage
    ->loadMultiple($order_report_ids);
  $this->orderReportStorage
    ->delete($reports);
  return $this
    ->generateReports($order_ids, $plugin_id);
}