Basket locale() error after upgrade to 2024.10

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: 151
Joined: 09 Oct 2019, 09:42

Basket locale() error after upgrade to 2024.10

Post by columbo » 25 Nov 2024, 07:54

Hi,

our customers have to log in before they can add products to their basket.
To save their basekts from one login to the next, we changed from $token to $userid:

in /src/MShop/Order/Base.php

Code: Select all

$context = $this->context();

//$token = $context->user();
$userid  = $context->token();
		
$locale = $context->locale();
$currency = $locale->getCurrencyId();
$language = $locale->getLanguageId();
$sitecode = $locale->getSiteItem()->getCode();

$key = $userid . '-' . $sitecode . '-' . $language . '-' . $currency . '-' . $type;

As with aimeos 2024 getSession() and setSession() have moved to Session.php we have changed the order manager the same way in /src/MShop/Order/Manager/Session.php

Now for customers who don't have a basket yet, it works fine - baskets are stored an reloaded the next time the they log in.
But for customers who already had an "old 2023.10 basket" (so before migrating to aimeos 2024.10) we get the following error:

Aimeos\MShop\Order\Item\Base::locale(): Return value must be of type Aimeos\MShop\Locale\Item\Iface, null returned {"userId":195,"exception":"[object] (TypeError(code: 0): Aimeos\\MShop\\Order\\Item\\Base::locale(): Return value must be of type Aimeos\\MShop\\Locale\\Item\\Iface, null returned at /vendor/aimeos/aimeos-core/src/MShop/Order/Item/Base.php:939)


Do we need some migration step(s) of the saved 2023-baskets for 2024.10?
Thank you

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

Re: Basket locale() error after upgrade to 2024.10

Post by columbo » 28 Nov 2024, 09:02

May I ask you for any hint as I'm still struggling with this.

when I copy mshop_order_basket.content from 2023.10 to 2024.10 DB (of course same user id (eg.: 1-default-de-EUR-default))
=> causing: Aimeos\MShop\Order\Item\Base::locale(): Return value must be of type Aimeos\MShop\Locale\Item\Iface, null returned

So it seems that saved baskets from aimeos 2023 are not usable in aimeos 2024

After deleting the "2023 content entry" in 2024 mshop_order_basket DB, it works fine.
=> creating and storing new baskets within 2024 works without any issues.


Since we have many saved baskets in aimeos 2023 I'm looking for a fix or any migration option(s);

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

Re: Basket locale() error after upgrade to 2024.10

Post by aimeos » 28 Nov 2024, 14:11

The values in the content column of the mshop_order_basket table are base64 encoded, PHP serialized order items. They have a locale item when being serialized but it seems that PHP can't un-serialize it in your new setup. Also, we are not aware that something relevant has changed in locale items (the constructor parameters have changed but the constructor isn't used during un-serialization.

We would suggest that you store an empty basket using Aimeos 2023.10 and 2024.10, then base64-decode both and compare if there are differences in the serialized representation.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

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

Re: Basket locale() error after upgrade to 2024.10

Post by columbo » 02 Dec 2024, 08:02

I made a comparison of both (2023.10 and 2024.10) mshop_order_basket.content.
From my point of view all local-data are present, but the structure is different

in 2023: * locale and child of O:32:"Aimeos\MShop\Order\Item\Standard"
in 2024: .locale, child of s:8:" * bdata"
notepad++_O6TB92qVAC.png
notepad++_O6TB92qVAC.png (103.09 KiB) Viewed 38342 times
Could this be the cause and how / where can I solve this?

There have been some changes in vendor\aimeos\aimeos-core\src\MShop\Order\Item\Base.php
I tried to solve it there, but unfortunately that didn't work

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

Re: Basket locale() error after upgrade to 2024.10

Post by aimeos » 02 Dec 2024, 09:38

Hopefully, this fixes the problem:
https://github.com/aimeos/aimeos-core/c ... e1db475bb9

Most relevant are the last two modified lines in locale() and setLocale().
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

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

Re: Basket locale() error after upgrade to 2024.10

Post by columbo » 02 Dec 2024, 13:08

one step further, but unfortunately not yet solved - after updateing src/MShop/Order/Item/Base.php we get

Typed property Aimeos\MShop\Price\Item\Standard::$precision must not be accessed before initialization
in packages/<my extension>/src/MShop/Order/Item/Base.php:865

in getPrice(), at line 865

Code: Select all

$price = $this->price->clear();

laravel.log:

Code: Select all

ERROR: Typed property Aimeos\MShop\Price\Item\Standard::$precision must not be accessed before initialization {"userId":1,"exception":"[object] (Error(code: 0): Typed property Aimeos\\MShop\\Price\\Item\\Standard::$precision must not be accessed before initialization at /vendor/aimeos/aimeos-core/src/MShop/Price/Item/Standard.php:166)
[stacktrace]
#0 /vendor/aimeos/aimeos-core/src/MShop/Price/Item/Base.php(86): Aimeos\\MShop\\Price\\Item\\Standard->getPrecision()
#1 /vendor/aimeos/aimeos-core/src/MShop/Price/Item/Base.php(73): Aimeos\\MShop\\Price\\Item\\Base->formatNumber()
#2 /vendor/aimeos/aimeos-core/src/MShop/Price/Item/Standard.php(387): Aimeos\\MShop\\Price\\Item\\Base->checkPrice()
#3 /vendor/aimeos/aimeos-core/src/MShop/Price/Item/Standard.php(452): Aimeos\\MShop\\Price\\Item\\Standard->setValue()
#4 /packages/<my extension>/src/MShop/Order/Item/Base.php(865): Aimeos\\MShop\\Price\\Item\\Standard->clear()
#5 /packages/<my extension>/templates/client/html/basket/mini/body.php(92): Aimeos\\MShop\\Order\\Item\\Base->getPrice()
#6 /vendor/aimeos/aimeos-base/src/View/Standard.php(281): include('...')
#7 /vendor/aimeos/aimeos-base/src/View/Standard.php(263): Aimeos\\Base\\View\\Standard->includeFile()
...

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

Re: Basket locale() error after upgrade to 2024.10

Post by aimeos » 02 Dec 2024, 13:56

Can you please check if this is because the price class property has been moved from the Base.php to Standard.php?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

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

Re: Basket locale() error after upgrade to 2024.10

Post by columbo » 02 Dec 2024, 20:21

Unfortunately, I'm not sure how to do this.

I replaced the Base.php and Standard.php 2024.10 version with the 2023.10 in /packages/<my extension>/src/MShop/Price/Item but this caused:
Class Aimeos\MShop\Price\Item\Standard contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Aimeos\MShop\Common\Item\TypeRef\Iface::getTypeItem)

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

Re: Basket locale() error after upgrade to 2024.10

Post by aimeos » 03 Dec 2024, 09:19

Can you try this change: https://github.com/aimeos/aimeos-core/c ... a62e13e3fa
Maybe it's already enough.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

jafo66
Posts: 68
Joined: 06 Mar 2024, 04:42

Re: Basket locale() error after upgrade to 2024.10

Post by jafo66 » 03 Dec 2024, 17:49

Not the best answer, but I had to clear out all the old baskets, then everything started working properly again.

Post Reply