Change locale of context in dependency injection container

Help for integrating the Laravel package
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!
FedericoCánovas
Posts: 7
Joined: 16 Jul 2018, 17:50

Change locale of context in dependency injection container

Post by FedericoCánovas » 30 Oct 2018, 11:48

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:

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);
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.

User avatar
aimeos
Administrator
Posts: 7836
Joined: 01 Jan 1970, 00:00

Re: Change locale of context in dependency injection contain

Post by aimeos » 30 Oct 2018, 22:23

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.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply