You are here

public function InvoiceGenerator::generate in Commerce Invoice 8.2

Generates an invoice for the given orders.

Parameters

\Drupal\commerce_order\Entity\OrderInterface[] $orders: The orders to generate an invoice for.

\Drupal\commerce_Store\Entity\StoreInterface $store: The store.

\Drupal\profile\Entity\ProfileInterface|null $profile: (optional) The billing profile.

array $values: (optional) An array of values to set on the invoice, keyed by property name.

bool $save: (optional) Whether to save the generated invoice and its items or not. Defaults to TRUE.

Return value

\Drupal\commerce_invoice\Entity\InvoiceInterface|null The generated invoice, NULL if it could not be generated.

Overrides InvoiceGeneratorInterface::generate

File

src/InvoiceGenerator.php, line 69

Class

InvoiceGenerator

Namespace

Drupal\commerce_invoice

Code

public function generate(array $orders, StoreInterface $store, ProfileInterface $profile = NULL, array $values = [], $save = TRUE) {
  $transaction = $this->connection
    ->startTransaction();
  try {
    return $this
      ->doGenerate($orders, $store, $profile, $values, $save);
  } catch (\Exception $exception) {
    $transaction
      ->rollBack();
    watchdog_exception('commerce_invoice', $exception);
    return NULL;
  }
}