You are here

public function InvoiceController::addForm in Commerce Invoice 8.2

Returns a form to add a new invoice of a specific type.

Parameters

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

\Drupal\commerce_invoice\Entity\InvoiceTypeInterface $commerce_invoice_type: The invoice type.

Return value

array The invoice add form.

1 string reference to 'InvoiceController::addForm'
commerce_invoice.routing.yml in ./commerce_invoice.routing.yml
commerce_invoice.routing.yml

File

src/Controller/InvoiceController.php, line 101

Class

InvoiceController
Provides the invoice download route.

Namespace

Drupal\commerce_invoice\Controller

Code

public function addForm(OrderInterface $commerce_order, InvoiceTypeInterface $commerce_invoice_type) {
  $invoice = $this->invoiceGenerator
    ->generate([
    $commerce_order,
  ], $commerce_order
    ->getStore(), $commerce_order
    ->getBillingProfile(), [
    'type' => $commerce_invoice_type
      ->id(),
  ], FALSE);

  // The invoice generator automatically sets a value for the total paid price
  // but when adding an invoice manually (through the add form), we need to
  // let the store owner decide when an invoice has been paid.
  $total_paid = new Price('0', $commerce_order
    ->getTotalPrice()
    ->getCurrencyCode());
  $invoice
    ->setTotalPaid($total_paid);
  return $this
    ->entityFormBuilder()
    ->getForm($invoice);
}