Same basket for different languages

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!
columbo
Advanced
Posts: 125
Joined: 09 Oct 2019, 09:42

Same basket for different languages

Post by columbo » 25 Jan 2024, 11:03

Hi,
  1. start: current local / language setting: DE
  2. user adds item to basket, eg. 4 items
  3. customer changes local / language to: EN
    -> basket empty, 0 items
  4. switch back to DE: basket has 4 items again
-> The basket items are saved according to the language/local setting.

How / where can we make the basket language-independet?
After switching to EN (step 3 above), the 4 items should remain in the basket and only be displayed in EN.

Thank you!

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

Re: Same basket for different languages

Post by aimeos » 30 Jan 2024, 08:52

Hm, the code for migrating products between baskets for different languages/currencies exists and it should work. Can you have to look what happens there in your case:
https://github.com/aimeos/ai-controller ... #L122-L334
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

columbo
Advanced
Posts: 125
Joined: 09 Oct 2019, 09:42

Re: Same basket for different languages

Post by columbo » 30 Jan 2024, 13:49

added a protocol / log output, it seems like ai-controller-frontend/src/Controller/Frontend/Basket/Base.php is not executed at all


FYI: the same behavior also applies to Aimeos Demo shop on https://laravel.demo.aimeos.org
1. add item to cart
2. change language
-> cart empty
3. change language back
-> item form step 1 is in the cart

columbo
Advanced
Posts: 125
Joined: 09 Oct 2019, 09:42

Re: Same basket for different languages

Post by columbo » 07 Feb 2024, 20:51

added a log output of the exception message:
Log::info(print_r($e->getMessage(), true));
in https://github.com/aimeos/ai-controller ... e.php#L284

with every language change:
"Adding product with ID "1234" is not allowed "


Why?
It's a standard article (type: article) and can be added to the basket on the EN and DE category page without any problems.

columbo
Advanced
Posts: 125
Joined: 09 Oct 2019, 09:42

Re: Same basket for different languages

Post by columbo » 09 Feb 2024, 09:16

Please give a hint
I am stuck here and have no clue why it is not working and why this message "Adding product with ID "###" is not allowed" appears
Thank you!

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

Re: Same basket for different languages

Post by aimeos » 09 Feb 2024, 09:50

The message is from the catalog decorator for the basket controller:
https://github.com/aimeos/ai-controller ... hp#L37-L62

It checks if the product is assigned to a category because otherwise, it's not allowed to add the product to the basket (products without categories are e.g. rebate products).

Guess, the product is a variant article of a selection product and the problem is located here:
https://github.com/aimeos/ai-controller ... e.php#L271

Instead of:

Code: Select all

$item = $manager->get( $product->getProductId(), $domains );
It must be:

Code: Select all

$item = $manager->get( $product->getParentProductId() ?: $product->getProductId(), $domains );
Does that fix the problem?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

columbo
Advanced
Posts: 125
Joined: 09 Oct 2019, 09:42

Re: Same basket for different languages

Post by columbo » 09 Feb 2024, 13:12

it's working now for variants "default article" linked to a select article) - thank you!

but for "simple" default article we get:
Error migrating product with code "018501" in basket to locale "default|en|EUR": Adding product with ID "7680" is not allowed
(the article is active of course and we don't have a stock limitation)

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

Re: Same basket for different languages

Post by aimeos » 10 Feb 2024, 18:47

columbo wrote: 09 Feb 2024, 13:12 it's working now for variants "default article" linked to a select article) - thank you!
The fix is now available in dev-master and 2023.10.x-dev.
columbo wrote: 09 Feb 2024, 13:12 but for "simple" default article we get:
Error migrating product with code "018501" in basket to locale "default|en|EUR": Adding product with ID "7680" is not allowed
(the article is active of course and we don't have a stock limitation)
Product "7680" is of type "default"? Does it have a category assigned?
Can you check what happens here for that product?
https://github.com/aimeos/ai-controller ... hp#L46-L79
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

columbo
Advanced
Posts: 125
Joined: 09 Oct 2019, 09:42

Re: Same basket for different languages

Post by columbo » 11 Feb 2024, 19:17

thank you!
Product "7680" is of type "default"? Does it have a category assigned?
Yes, it is of type "default"and has two active (standard) categories assigned.

If you disable (comment) lines 52-56 in https://github.com/aimeos/ai-controller ... hp#L52-L56 basket translation works


So it seems as the product is not assigned to any category, but in fact it is assigned to (standard) categories.
Also tried with other products that are only assigned to one category, but same behaviour

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

Re: Same basket for different languages

Post by aimeos » 12 Feb 2024, 07:54

Fetching categories was missing when migrating products. This is now patched in ai-controller-frontend dev-master and 2023.10.x-dev. Thank you very much for your support! :-)
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply