diff --git a/modules/order/src/EventSubscriber/OrderReceiptSubscriber.php b/modules/order/src/EventSubscriber/OrderReceiptSubscriber.php index c37b69e7df4e9977051897421e1e0955d00a5225..acec8c8b302e788f6181616407e9e687bc5c3c25 100644 --- a/modules/order/src/EventSubscriber/OrderReceiptSubscriber.php +++ b/modules/order/src/EventSubscriber/OrderReceiptSubscriber.php @@ -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()); } }