You are here

public function InvoiceConfirmationSubscriber::sendInvoiceConfirmation in Commerce Invoice 8.2

Sends an invoice confirmation email.

Parameters

\Drupal\state_machine\Event\WorkflowTransitionEvent $event: The transition event.

File

src/EventSubscriber/InvoiceConfirmationSubscriber.php, line 65

Class

InvoiceConfirmationSubscriber
Sends a confirmation email when an invoice is generated.

Namespace

Drupal\commerce_invoice\EventSubscriber

Code

public function sendInvoiceConfirmation(WorkflowTransitionEvent $event) {

  /** @var \Drupal\commerce_invoice\Entity\InvoiceInterface $invoice */
  $invoice = $event
    ->getEntity();
  $invoice_type_storage = $this->entityTypeManager
    ->getStorage('commerce_invoice_type');

  /** @var \Drupal\commerce_invoice\Entity\InvoiceTypeInterface $invoice_type */
  $invoice_type = $invoice_type_storage
    ->load($invoice
    ->bundle());

  // Don't send the invoice confirmation email right away because doing so
  // triggers an invoice save after generating the invoice file.
  if ($invoice_type
    ->shouldSendConfirmation()) {
    $this->invoicesList[$invoice
      ->id()] = $invoice
      ->id();
  }
}