Change locale of context in dependency injection container
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
-
- Posts: 7
- Joined: 16 Jul 2018, 17:50
Change locale of context in dependency injection container
I'm trying to change the locale of the context available in the DI container in order to have the correct site (locale) set along the current script execution or process:
If I check $context, it's already set with the correct locale. But If I try to get again the context object from the DI container, it returns the old context with the old locale.
What I'm trying to achieve is to use laravel jobs, listeners, mailables, notifications... with the right context and locale set making use of the DI object instead of passing the modified context in cascade.
Code: Select all
$context = app()->make('\Aimeos\Shop\Base\Context')->get();
$localeManager = \Aimeos\MShop\Factory::createManager($this->getAimeosContext(), 'locale');
$item = $localeManager->bootstrap($siteCode);
$context->setLocale($item);
What I'm trying to achieve is to use laravel jobs, listeners, mailables, notifications... with the right context and locale set making use of the DI object instead of passing the modified context in cascade.
Re: Change locale of context in dependency injection contain
The DI container only returns a new "base" context object without locale if you call get(false) and with an empty locale when created with get() in a command:
https://github.com/aimeos/aimeos-larave ... xt.php#L99
If you don't want to pass the context object around, you need to store it somewhere else.
https://github.com/aimeos/aimeos-larave ... xt.php#L99
If you don't want to pass the context object around, you need to store it somewhere else.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star