Skip to content

Commit 1e9d238

Browse files
authored
Merge pull request #4023 from craftcms/feature/pt-2791-5x-sendemail-job-is-serializing-entire-order-object-to-db
FIxed PHP error when sending emails with orders that could not be serialized.
2 parents 62e2427 + 6600aeb commit 1e9d238

2 files changed

Lines changed: 10 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release Notes for Craft Commerce
22

3+
## Unreleased
4+
5+
- Fixed a PHP error that could occur when sending emails. ([#4017](https://github.com/craftcms/commerce/issues/4017))
6+
37
## 5.3.13 - 2025-05-21
48

59
- Fixed a bug where the “Recipient”, “BCC’d Recipient”, and “CC’d Recipient” email settings weren’t working properly if set to environment variables. ([#4004](https://github.com/craftcms/commerce/issues/4004), [#4002](https://github.com/craftcms/commerce/issues/4002))

src/queue/jobs/SendEmail.php

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,20 @@ class SendEmail extends BaseJob implements RetryableJobInterface
3636
*/
3737
public int $orderHistoryId;
3838

39-
/**
40-
* @var Order|null
41-
*/
42-
private ?Order $_order = null;
43-
44-
4539
/**
4640
* @inheritDoc
4741
*/
4842
public function execute($queue): void
4943
{
5044
$this->setProgress($queue, 0.2);
5145

52-
if (!$this->_getOrder()) {
46+
$order = $this->_getOrder();
47+
48+
if (!$order) {
5349
throw new InvalidConfigException('Invalid order ID: ' . $this->orderId);
5450
}
5551

56-
$email = Plugin::getInstance()->getEmails()->getEmailById($this->commerceEmailId, $this->_getOrder()->getStore()->id);
52+
$email = Plugin::getInstance()->getEmails()->getEmailById($this->commerceEmailId, $order->getStore()->id);
5753
if (!$email) {
5854
throw new InvalidConfigException('Invalid email ID: ' . $this->commerceEmailId);
5955
}
@@ -62,7 +58,7 @@ public function execute($queue): void
6258
$this->setProgress($queue, 0.5);
6359

6460
$error = '';
65-
if (!Plugin::getInstance()->getEmails()->sendEmail($email, $this->_getOrder(), $orderHistory, $this->orderData, $error)) {
61+
if (!Plugin::getInstance()->getEmails()->sendEmail($email, $order, $orderHistory, $this->orderData, $error)) {
6662
throw new EmailException($error);
6763
}
6864

@@ -74,11 +70,7 @@ public function execute($queue): void
7470
*/
7571
private function _getOrder(): ?Order
7672
{
77-
if ($this->_order === null) {
78-
$this->_order = Order::find()->id($this->orderId)->one();
79-
}
80-
81-
return $this->_order;
73+
return Order::find()->id($this->orderId)->one();
8274
}
8375

8476
/**

0 commit comments

Comments
 (0)