Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes for Craft Commerce

## Unreleased

- Fixed a PHP error that could occur when sending emails. ([#4017](https://github.com/craftcms/commerce/issues/4017))

## 5.3.13 - 2025-05-21

- 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))
Expand Down
20 changes: 6 additions & 14 deletions src/queue/jobs/SendEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,20 @@ class SendEmail extends BaseJob implements RetryableJobInterface
*/
public int $orderHistoryId;

/**
* @var Order|null
*/
private ?Order $_order = null;


/**
* @inheritDoc
*/
public function execute($queue): void
{
$this->setProgress($queue, 0.2);

if (!$this->_getOrder()) {
$order = $this->_getOrder();

if (!$order) {
throw new InvalidConfigException('Invalid order ID: ' . $this->orderId);
}

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

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

Expand All @@ -74,11 +70,7 @@ public function execute($queue): void
*/
private function _getOrder(): ?Order
{
if ($this->_order === null) {
$this->_order = Order::find()->id($this->orderId)->one();
}

return $this->_order;
return Order::find()->id($this->orderId)->one();
}

/**
Expand Down
Loading