From bf599fc1fdae4237746fba95ebd0485180e29100 Mon Sep 17 00:00:00 2001
From: PremSutharM <premsutharm@gmail.com>
Date: Wed, 9 Apr 2025 19:41:00 +0530
Subject: [PATCH 1/3] re-roll the Patch with the Di changes.

---
 .../EventSubscriber/OrderReceiptSubscriber.php   | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/modules/order/src/EventSubscriber/OrderReceiptSubscriber.php b/modules/order/src/EventSubscriber/OrderReceiptSubscriber.php
index c37b69e7d..acec8c8b3 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());
     }
   }
-- 
GitLab


From 40df0efc389825c9eb343b83e931bcdd989e0ccd Mon Sep 17 00:00:00 2001
From: PremSutharM <premsutharm@gmail.com>
Date: Thu, 10 Apr 2025 15:04:23 +0530
Subject: [PATCH 2/3] added the token argument on the services.yml.

---
 modules/order/commerce_order.services.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/modules/order/commerce_order.services.yml b/modules/order/commerce_order.services.yml
index b5a178985..ffba77b77 100644
--- a/modules/order/commerce_order.services.yml
+++ b/modules/order/commerce_order.services.yml
@@ -83,7 +83,7 @@ services:
 
   commerce_order.order_receipt_subscriber:
     class: Drupal\commerce_order\EventSubscriber\OrderReceiptSubscriber
-    arguments: ['@entity_type.manager', '@commerce_order.order_receipt_mail']
+    arguments: ['@entity_type.manager', '@commerce_order.order_receipt_mail', '@token']
     tags:
       - { name: 'event_subscriber' }
 
-- 
GitLab


From c43d188279d95e89ef0f7a841052959ca06baf3c Mon Sep 17 00:00:00 2001
From: PremSutharM <premsutharm@gmail.com>
Date: Mon, 14 Apr 2025 12:14:03 +0530
Subject: [PATCH 3/3] remove the Token argument services.

---
 modules/order/commerce_order.services.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/modules/order/commerce_order.services.yml b/modules/order/commerce_order.services.yml
index ffba77b77..b5a178985 100644
--- a/modules/order/commerce_order.services.yml
+++ b/modules/order/commerce_order.services.yml
@@ -83,7 +83,7 @@ services:
 
   commerce_order.order_receipt_subscriber:
     class: Drupal\commerce_order\EventSubscriber\OrderReceiptSubscriber
-    arguments: ['@entity_type.manager', '@commerce_order.order_receipt_mail', '@token']
+    arguments: ['@entity_type.manager', '@commerce_order.order_receipt_mail']
     tags:
       - { name: 'event_subscriber' }
 
-- 
GitLab