I noticed that seller-written status comments are not delivered to customers in email notifications sent through bulk actions. This functionality may not have been implemented, but I consider it a clear bug. I am attaching a ready-to-use patch that resolves the issue. The status comment can be included in an email template as follows:
[IF:STATUS_COMMENT]
Message regarding your order status:
[STATUS_COMMENT]
[/IF:STATUS_COMMENT]
I know you don't like it when people post ready-made solutions, but I don't like having to fix my store after the official, incomplete component updates ;-)
Below is a patch you can paste directly into Git
best,
KK
---------------------------------------
diff --git a/administrator/components/com_j2commerce/src/Controller/OrderController.php b/administrator/components/com_j2commerce/src/Controller/OrderController.php
--- a/administrator/components/com_j2commerce/src/Controller/OrderController.php
+++ b/administrator/components/com_j2commerce/src/Controller/OrderController.php
@@ -210,7 +210,7 @@ class OrderController extends FormController
if ($notify) {
$order = $model->getItem($orderId);
$notifyResult = $order && !empty($order->order_id)
- ? $model->sendOrderNotification($order->order_id, true, true)
+ ? $model->sendOrderNotification($order->order_id, true, true, $comment)
: ['customer_sent' => 0, 'errors' => []];
if (($notifyResult['customer_sent'] ?? 0) === 0) {
diff --git a/administrator/components/com_j2commerce/src/Controller/OrdersController.php b/administrator/components/com_j2commerce/src/Controller/OrdersController.php
--- a/administrator/components/com_j2commerce/src/Controller/OrdersController.php
+++ b/administrator/components/com_j2commerce/src/Controller/OrdersController.php
@@ -123,7 +123,7 @@ class OrdersController extends AdminController
continue;
}
- $notifyResult = $model->sendOrderNotification($order->order_id, true, true);
+ $notifyResult = $model->sendOrderNotification($order->order_id, true, true, $comment);
if (($notifyResult['customer_sent'] ?? 0) === 0) {
$missingTemplateIds[] = $order->order_id;
diff --git a/administrator/components/com_j2commerce/src/Model/OrderModel.php b/administrator/components/com_j2commerce/src/Model/OrderModel.php
--- a/administrator/components/com_j2commerce/src/Model/OrderModel.php
+++ b/administrator/components/com_j2commerce/src/Model/OrderModel.php
@@ -1221,7 +1221,7 @@ class OrderModel extends AdminModel
// Send notification emails when requested
if ($notify) {
- $this->sendOrderNotification($order->order_id, true, true);
+ $this->sendOrderNotification($order->order_id, true, true, $comment);
}
return true;
@@ -4348,10 +4348,16 @@ class OrderModel extends AdminModel
* @param string $orderId The order_id (varchar).
* @param bool $notifyCustomer Send to customer.
* @param bool $notifyAdmin Send to admin.
+ * @param string $statusComment Comment entered for this status change.
*
* @return array{sent: int, customer_sent: int, admin_sent: int, errors: string[]}
*/
- public function sendOrderNotification(string $orderId, bool $notifyCustomer = true, bool $notifyAdmin = true): array
+ public function sendOrderNotification(
+ string $orderId,
+ bool $notifyCustomer = true,
+ bool $notifyAdmin = true,
+ string $statusComment = ''
+ ): array
{
$result = ['sent' => 0, 'customer_sent' => 0, 'admin_sent' => 0, 'errors' => []];
@@ -4376,6 +4382,10 @@ class OrderModel extends AdminModel
return $result;
}
+ // Transient context for the email generated by this status-change operation.
+ // Do not recover it from order history: history also contains system and mail-log rows.
+ $order->status_comment = $statusComment;
+
$emailHelper = EmailHelper::getInstance();
PluginHelper::importPlugin('j2commerce');
diff --git a/administrator/components/com_j2commerce/src/Helper/EmailHelper.php b/administrator/components/com_j2commerce/src/Helper/EmailHelper.php
--- a/administrator/components/com_j2commerce/src/Helper/EmailHelper.php
+++ b/administrator/components/com_j2commerce/src/Helper/EmailHelper.php
@@ -89,6 +89,7 @@ class EmailHelper
'[DOWNLOAD_LINKS]',
// Escaped at assignment, before nl2br() adds the only markup it carries.
'[CUSTOMER_NOTE]',
+ '[STATUS_COMMENT]',
'[BANK_TRANSFER_INFORMATION]',
'[PAYMENT_INSTRUCTIONS]',
'[FOOTER_TEXT]',
@@ -945,6 +946,7 @@ class EmailHelper
'[SHIPPING_TYPE]' => $language->_($shipping->ordershipping_name ?? ''),
'[SHIPPING_TRACKING_ID]' => $shipping->ordershipping_tracking_id ?? '',
'[CUSTOMER_NOTE]' => self::encodeTagDelimiters(nl2br(htmlspecialchars((string) ($order->customer_note ?? ''), ENT_QUOTES, 'UTF-8'))),
+ '[STATUS_COMMENT]' => self::encodeTagDelimiters(nl2br(htmlspecialchars((string) ($order->status_comment ?? ''), ENT_QUOTES, 'UTF-8'))),
'[PAYMENT_TYPE]' => $this->getPaymentMethodTitle($order->orderpayment_type ?? '', $language),
'[ORDER_TOKEN]' => $isAdminCopy ? '' : $orderToken,
'[TOKEN]' => $isAdminCopy ? '' : $orderToken,
diff --git a/administrator/components/com_j2commerce/src/Helper/MessageHelper.php b/administrator/components/com_j2commerce/src/Helper/MessageHelper.php
--- a/administrator/components/com_j2commerce/src/Helper/MessageHelper.php
+++ b/administrator/components/com_j2commerce/src/Helper/MessageHelper.php
@@ -101,6 +101,7 @@ class MessageHelper
* - [SITEURL]: Website URL
* - [INVOICE_URL]: Link to customer invoice/order page
* - [CUSTOMER_NOTE]: Customer notes from checkout
+ * - [STATUS_COMMENT]: Comment entered for the current order status change
* - [PAYMENT_TYPE]: Payment method used
* - [SHIPPING_TYPE]: Shipping method used
* - [ORDERID]: Order ID number
@@ -133,6 +134,7 @@ class MessageHelper
'[GUEST_ORDER_URL]' => Text::_('COM_J2COMMERCE_EMAILTEMPLATE_TAG_GUEST_ORDER_URL'),
'[DOWNLOAD_LINKS]' => Text::_('COM_J2COMMERCE_EMAILTEMPLATE_TAG_DOWNLOAD_LINKS'),
'[CUSTOMER_NOTE]' => Text::_('COM_J2COMMERCE_EMAILTEMPLATE_TAG_CUSTOMER_NOTE'),
+ '[STATUS_COMMENT]' => Text::_('COM_J2COMMERCE_FIELD_STATUS_COMMENT'),
'[PAYMENT_TYPE]' => Text::_('COM_J2COMMERCE_EMAILTEMPLATE_TAG_PAYMENT_TYPE'),
'[SHIPPING_TYPE]' => Text::_('COM_J2COMMERCE_SHIPM_SHIPPING_TYPE'),
'[ORDERID]' => Text::_('COM_J2COMMERCE_EMAILTEMPLATE_TAG_ORDERID'),



