diff --git a/CHANGELOG.md b/CHANGELOG.md index fe6512ccc3..b2eef3140e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Fixed an SQL error that occurred when duplicating variants. ([#3727](https://github.com/craftcms/commerce/issues/3727)) - Fixed a PHP error that could occur when completing an order. ([#3733](https://github.com/craftcms/commerce/issues/3733)) - Fixed a bug where the “Product” navigation item could be missing from the navigation. ([#3735](https://github.com/craftcms/commerce/issues/3735)) +- Fixed a PHP error that could occur when completing an order. ([#3736](https://github.com/craftcms/commerce/issues/3736)) ## 5.2.0 - 2024-10-16 diff --git a/src/controllers/DownloadsController.php b/src/controllers/DownloadsController.php index 92011c410d..be5685e834 100644 --- a/src/controllers/DownloadsController.php +++ b/src/controllers/DownloadsController.php @@ -72,7 +72,7 @@ public function actionPdf(): Response $renderedPdf = Plugin::getInstance()->getPdfs()->renderPdfForOrder($order, $option, null, [], $pdf); // Set previous language back - Locale::switchAppLanguage($originalLanguage, $originalFormattingLocale); + Locale::switchAppLanguage($originalLanguage, $originalFormattingLocale->id); $fileName = $this->getView()->renderObjectTemplate((string)$pdf->fileNameFormat, $order); if (!$fileName) { diff --git a/src/controllers/OrdersController.php b/src/controllers/OrdersController.php index fb61553061..871261b627 100644 --- a/src/controllers/OrdersController.php +++ b/src/controllers/OrdersController.php @@ -930,7 +930,7 @@ public function actionSendEmail(): Response } // Set previous language back - Locale::switchAppLanguage($originalLanguage, $originalFormattingLocale); + Locale::switchAppLanguage($originalLanguage, $originalFormattingLocale->id); if (!$success) { $error = $error ?: Craft::t('commerce', 'Could not send email'); diff --git a/src/queue/jobs/SendEmail.php b/src/queue/jobs/SendEmail.php index 06750134b3..60ae119a6d 100644 --- a/src/queue/jobs/SendEmail.php +++ b/src/queue/jobs/SendEmail.php @@ -76,7 +76,7 @@ public function execute($queue): void } // Set previous language back - Locale::switchAppLanguage($originalLanguage, $originalFormattingLocale); + Locale::switchAppLanguage($originalLanguage, $originalFormattingLocale->id); $this->setProgress($queue, 1); } diff --git a/src/services/OrderStatuses.php b/src/services/OrderStatuses.php index 03a8a7ecec..80c8c864ca 100644 --- a/src/services/OrderStatuses.php +++ b/src/services/OrderStatuses.php @@ -502,7 +502,7 @@ public function statusChangeHandler(Order $order, OrderHistory $orderHistory): v } // Set previous language back - Locale::switchAppLanguage($originalLanguage, $originalFormattingLocale); + Locale::switchAppLanguage($originalLanguage, $originalFormattingLocale->id); } /** diff --git a/src/services/Pdfs.php b/src/services/Pdfs.php index 86875b8ab6..444e054dc3 100644 --- a/src/services/Pdfs.php +++ b/src/services/Pdfs.php @@ -509,7 +509,7 @@ public function renderPdfForOrder(Order $order, string $option = '', string $tem if (!$event->template || !$view->doesTemplateExist($event->template)) { // Restore the original template mode $view->setTemplateMode($oldTemplateMode); - Locale::switchAppLanguage($originalLanguage, $originalFormattingLanguage); + Locale::switchAppLanguage($originalLanguage, $originalFormattingLanguage->id); throw new Exception('PDF template file does not exist.'); } @@ -518,14 +518,14 @@ public function renderPdfForOrder(Order $order, string $option = '', string $tem // TODO Add event $html = $view->renderTemplate($event->template, $variables); } catch (\Exception $e) { - Locale::switchAppLanguage($originalLanguage, $originalFormattingLanguage); + Locale::switchAppLanguage($originalLanguage, $originalFormattingLanguage->id); // Set the pdf html to the render error. Craft::error('Order PDF render error. Order number: ' . $order->getShortNumber() . '. ' . $e->getMessage()); Craft::$app->getErrorHandler()->logException($e); $html = Craft::t('commerce', 'An error occurred while generating this PDF.'); } - Locale::switchAppLanguage($originalLanguage, $originalFormattingLanguage); + Locale::switchAppLanguage($originalLanguage, $originalFormattingLanguage->id); // Restore the original template mode $view->setTemplateMode($oldTemplateMode);