Skip to content

Commit

Permalink
Always pass the locale ID string
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeholder committed Oct 23, 2024
1 parent 53d4a16 commit dc76f2f
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/controllers/DownloadsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/OrdersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion src/queue/jobs/SendEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/OrderStatuses.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/services/Pdfs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
Expand All @@ -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);

Expand Down

0 comments on commit dc76f2f

Please sign in to comment.