class OrderReceiptMail in Commerce Core 8.2
Hierarchy
- class \Drupal\commerce_order\Mail\OrderReceiptMail implements OrderReceiptMailInterface uses StringTranslationTrait
Expanded class hierarchy of OrderReceiptMail
1 string reference to 'OrderReceiptMail'
- commerce_order.services.yml in modules/
order/ commerce_order.services.yml - modules/order/commerce_order.services.yml
1 service uses OrderReceiptMail
File
- modules/
order/ src/ Mail/ OrderReceiptMail.php, line 11
Namespace
Drupal\commerce_order\MailView source
class OrderReceiptMail implements OrderReceiptMailInterface {
use StringTranslationTrait;
/**
* The mail handler.
*
* @var \Drupal\commerce\MailHandlerInterface
*/
protected $mailHandler;
/**
* The order total summary.
*
* @var \Drupal\commerce_order\OrderTotalSummaryInterface
*/
protected $orderTotalSummary;
/**
* The profile view builder.
*
* @var \Drupal\profile\ProfileViewBuilder
*/
protected $profileViewBuilder;
/**
* Constructs a new OrderReceiptMail object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\commerce\MailHandlerInterface $mail_handler
* The mail handler.
* @param \Drupal\commerce_order\OrderTotalSummaryInterface $order_total_summary
* The order total summary.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, MailHandlerInterface $mail_handler, OrderTotalSummaryInterface $order_total_summary) {
$this->mailHandler = $mail_handler;
$this->orderTotalSummary = $order_total_summary;
$this->profileViewBuilder = $entity_type_manager
->getViewBuilder('profile');
}
/**
* {@inheritdoc}
*/
public function send(OrderInterface $order, $to = NULL, $bcc = NULL) {
$to = isset($to) ? $to : $order
->getEmail();
if (!$to) {
// The email should not be empty.
return FALSE;
}
$subject = $this
->t('Order #@number confirmed', [
'@number' => $order
->getOrderNumber(),
]);
$body = [
'#theme' => 'commerce_order_receipt',
'#order_entity' => $order,
'#totals' => $this->orderTotalSummary
->buildTotals($order),
];
if ($billing_profile = $order
->getBillingProfile()) {
$body['#billing_information'] = $this->profileViewBuilder
->view($billing_profile);
}
$params = [
'id' => 'order_receipt',
'from' => $order
->getStore()
->getEmail(),
'bcc' => $bcc,
'order' => $order,
];
$customer = $order
->getCustomer();
if ($customer
->isAuthenticated()) {
$params['langcode'] = $customer
->getPreferredLangcode();
}
return $this->mailHandler
->sendMail($to, $subject, $body, $params);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
OrderReceiptMail:: |
protected | property | The mail handler. | |
OrderReceiptMail:: |
protected | property | The order total summary. | |
OrderReceiptMail:: |
protected | property | The profile view builder. | |
OrderReceiptMail:: |
public | function |
Sends the order receipt email. Overrides OrderReceiptMailInterface:: |
|
OrderReceiptMail:: |
public | function | Constructs a new OrderReceiptMail object. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |