commerce icon indicating copy to clipboard operation
commerce copied to clipboard

[5.x]: Locale::switchAppLanguage(): Argument #2 ($formattingLocale) must be of type ?string, craft\i18n\Locale given

Open gopeter opened this issue 1 year ago • 2 comments

What happened?

Description

I need to set the current site for some jobs, but once I do this, I get this error: Locale::switchAppLanguage(): Argument #2 ($formattingLocale) must be of type ?string, craft\i18n\Locale given.

Looking at the code, Locale::switchAppLanguage in https://github.com/craftcms/commerce/blob/5.x/src/services/OrderStatuses.php#L505 will always throw this, since $originalFormattingLocale = Craft::$app->formattingLocale; returns a Locale and not a string.

I could imagine to allow the Locale also and check for the type inside switchAppLanguage?

Craft CMS version

Craft Pro 5.4.8

Craft Commerce version

5.1.3

PHP version

No response

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

No response

gopeter avatar Oct 21 '24 10:10 gopeter

This is how I have solved this locally: https://github.com/craftcms/commerce/compare/5.x...evernow-io:craft-commerce:feature/locale-fix

Not sure if you want to pick this up as a PR?

gopeter avatar Oct 21 '24 10:10 gopeter

Thanks, this is fixed for the next release.

To get the fix early, change your craftcms/commerce requirement in composer.json to:

"require": {
  "craftcms/commerce": "5.x-dev#dc76f2ff9401604404aaeb5412856465dc58991c as 5.2.0",
  "...": "..."
}

Then run composer update.

We will update this ticket once the release is out.

lukeholder avatar Oct 23 '24 13:10 lukeholder

Commerce 5.2.1 has now been released with this fix included.

Thanks!

nfourtythree avatar Oct 23 '24 14:10 nfourtythree