You are here

class OrderReceiptMail in Commerce Core 8.2

Hierarchy

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
commerce_order.order_receipt_mail in modules/order/commerce_order.services.yml
Drupal\commerce_order\Mail\OrderReceiptMail

File

modules/order/src/Mail/OrderReceiptMail.php, line 11

Namespace

Drupal\commerce_order\Mail
View 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

Namesort descending Modifiers Type Description Overrides
OrderReceiptMail::$mailHandler protected property The mail handler.
OrderReceiptMail::$orderTotalSummary protected property The order total summary.
OrderReceiptMail::$profileViewBuilder protected property The profile view builder.
OrderReceiptMail::send public function Sends the order receipt email. Overrides OrderReceiptMailInterface::send
OrderReceiptMail::__construct public function Constructs a new OrderReceiptMail object.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.