Different baskets for different languages (locale).

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!
Sabir_Ali
Posts: 32
Joined: 12 Feb 2024, 06:43

Different baskets for different languages (locale).

Post by Sabir_Ali » 21 Jun 2024, 11:08

PHP: 8.2.7
Laravel Framework: 10.48.4
System: Debian GNU/Linux 12
Aimeos Laravel v2023.10
~~~~~~~~~~~~~~~~~~~~~

Hi Aimeos!
I have an issue in working with basket for different locale. When I add a product under one language and switch to another language and then add a product to the basket it may not be added to all locales.

I came from this topic:
viewtopic.php?f=18&hilit=basket%20local ... ce11973d3a
and it looks like I use the same version discussed there and the code is the same.

The following code switches the locale in our template:

Code: Select all

use Illuminate\Support\Facades\Cookie;

$enc = $this->encoder();
$currentCookieValue = Cookie::get('user_language', null);

$locale = app()->getLocale();
$defaultLocale = config('app.locale', 'en');
$languages = config('app.language.list', ['en' => 'English']);
$selectedLanguageId = $locale ?? $defaultLocale;

Cookie::queue('user_language', $selectedLanguageId, config('session.cookie_validity.default', 86400 * 30));
app()->setLocale($selectedLanguageId);
$languagesMenuText = $languages[$selectedLanguageId] ?? 'English';
In the https://github.com/aimeos/ai-controller ... #L122-L334 class the $localeStr and $localeKey values are always the same when I switch the locale. So it never goes inside the 'if' statement and does't copy basket addresses. What I should check to fix this problem? Or should I set locale somehow differently?

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

Re: Different baskets for different languages (locale).

Post by aimeos » 23 Jun 2024, 07:58

In Aimeos, the used language is in the Locale object of the context:

Code: Select all

app('aimeos.context')->locale()->getLanguageId()
The language is determined by the "locale" parameter in the URL:
https://github.com/aimeos/aimeos-larave ... hp#L48-L74
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Sabir_Ali
Posts: 32
Joined: 12 Feb 2024, 06:43

Re: Different baskets for different languages (locale).

Post by Sabir_Ali » 24 Jun 2024, 12:20

aimeos wrote: 23 Jun 2024, 07:58 In Aimeos, the used language is in the Locale object of the context:

Code: Select all

app('aimeos.context')->locale()->getLanguageId()
The language is determined by the "locale" parameter in the URL:
https://github.com/aimeos/aimeos-larave ... hp#L48-L74
Yes. I can set the locale by this way also (but only if to initialize the Aimeos context like this:

Code: Select all

$context = app('aimeos.context')->get();

But it doesn't change the behaviour of the app. I still have different baskets for different locales. And in addition to this, when I change locale the quantity of existing products increases on other locales. When I just reload the page the quantity doubles.
When I add first product and change locale - the product stays in all baskets. But when I add second one - it doesn't added to all basket. One of them (three in my case) will stay without second added product. And so on.
When I change quantity in one product (minus one for example), it also uses copyProduct() method and it affects on another product (plus one).
These all are abnormal behaviour.
I thought that this is only in my local case. But the same problem I saw in Your demo site https://laravel.demo.aimeos.org/ - Just add products to the basket several times, switch locale and see what happens.

If there is a way (configuration) to set a single basket for all locales - it would be the best solution. So, I need your advise.

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

Re: Different baskets for different languages (locale).

Post by aimeos » 26 Jun 2024, 11:57

The expected behavior is:
1.) Add a product to the basket
2.) Change language or currency
3.) Product is in the basket with the new language and currency (but only if the product text and product price is available for the selected language and currency)
4.) Increase the quantity in the basket
5.) Change language or currency back to the previous language or currency
6.) Product quantity is now also "2" for the first language and currency combination

The demo matches that behavior as far we can see in our tests.
If you reload the page, the previous action is performed again, which can increase the quantity for sure if you have done that before.

As you've already noted, the copyProducts() method cares about migrating products in the basket between different locales.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Sabir_Ali
Posts: 32
Joined: 12 Feb 2024, 06:43

Re: Different baskets for different languages (locale).

Post by Sabir_Ali » 27 Jun 2024, 06:45

OK. This is one of scenarios on demo site I just did after reading your comment (I did not change the currency to prevent too difficult steps):

Scenario 1.
1. EN. Add one product to the basket.
Expected behaviour: EN. One product is in the basket.
Actual behaviour: EN. One product is in the basket.

2. Go to DE. Add second product to the basket.
Expected behaviour: DE. Second product added to the basket.
Actual behaviour: DE. Second product added to the basket.

3. Go to EN. Add third product to the basket.
Expected behaviour: EN. Third product added to the basket.
Actual behaviour: EN. Third product is not added to the basket.

4. Go to DE. Look to the basket.
Expected behaviour: DE. Three products are in the basket.
Actual behaviour: DE. Two products are in the basket.

5. DE. Increase count of second product.
Expected behaviour: DE. Second product count increased from 1 to 2.
Actual behaviour: DE. Both products count increased from 1 to 2.

I understand that the behaviour may not occur immediately (but I had it with the first one)
and that fact that all of Your demo product must be ready to work properly in multi-language system. And try too keep all my test products in my local project as maximum correct as I can. But I will check them again.

Post Reply