Skip to content
Snippets Groups Projects

re-roll the Patch with the Di changes.

Open Prem Suthar requested to merge issue/commerce-3512173:3512173-add-token-support into 3.x
@@ -6,6 +6,7 @@ use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\commerce_order\Mail\OrderReceiptMailInterface;
use Drupal\state_machine\Event\WorkflowTransitionEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Drupal\Core\Utility\Token;
/**
* Sends a receipt email when an order is placed.
@@ -26,6 +27,13 @@ class OrderReceiptSubscriber implements EventSubscriberInterface {
*/
protected $orderReceiptMail;
/**
* The token service.
*
* @var \Drupal\Core\Utility\Token
*/
protected $token;
/**
* Constructs a new OrderReceiptSubscriber object.
*
@@ -33,10 +41,13 @@ class OrderReceiptSubscriber implements EventSubscriberInterface {
* The entity type manager.
* @param \Drupal\commerce_order\Mail\OrderReceiptMailInterface $order_receipt_mail
* The mail handler.
* @param \Drupal\Core\Utility\Token $token
* The token service.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, OrderReceiptMailInterface $order_receipt_mail) {
public function __construct(EntityTypeManagerInterface $entity_type_manager, OrderReceiptMailInterface $order_receipt_mail, Token $token) {
$this->entityTypeManager = $entity_type_manager;
$this->orderReceiptMail = $order_receipt_mail;
$this->token = $token;
}
/**
@@ -60,6 +71,9 @@ class OrderReceiptSubscriber implements EventSubscriberInterface {
/** @var \Drupal\commerce_order\Entity\OrderTypeInterface $order_type */
$order_type = $order_type_storage->load($order->bundle());
if ($order_type->shouldSendReceipt()) {
// Replace the tokens in the email fields.
$order_type->setReceiptBcc($this->token->replace($order_type->getReceiptBcc(), ['commerce_order' => $order]));
$this->orderReceiptMail->send($order, $order->getEmail(), $order_type->getReceiptBcc());
}
}
Loading