Score:0

Attach PDF file to Drupal Commerce Order Notification generated with invoice commerce

ls flag

How do I attach a pdf file to the commerce email?

I have invoice commerce.

Invoice commerce show view pdf option on every order and I want to send that pdf in email

I am stumped on how to get the pdf into a File object.

module_name_mail_alter(&$message) {
 $my_attachment = array(
'filecontent' => $pdf,
'filemime' => $pdf->filemime,
'filename' => $pdf->filename,
'filepath' => NULL,
);
$message['params']['attachments'][] = $my_attachment;
}

I tried below code but It seems there is no table with name commerce_invoice and there is no output

$invoice_storage =\Drupal::entityTypeManager()->getStorage('commerce_invoice');
  $invoice_ids = $invoice_storage->getQuery()
    ->condition('orders', [$order->id()], 'IN')
    ->accessCheck(FALSE)
    ->execute();
$invoices = $invoice_storage->loadMultiple($invoice_ids);

if ($invoices) { 
  $invoice = reset($invoices);
  $vars['invoice_download_url'] = $invoice->toUrl('download');
}
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.