Aimeos Context Serialization Issue
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!
- MuhammadSohailAfzal
- Posts: 1
- Joined: 27 Jul 2023, 21:11
Aimeos Context Serialization Issue
Hi everyone,
I am trying to create a new queue job as laravel provided.
and the function I want to process by this job is using aimeos context object.
now whenever I tried to dispatched the job it throws and exception related to serialization of aimeos context class
Aimeos Version: 2023.07
Laravel Version: 10
I am attaching my some code might be it can help to understand the issue
ProductService
Queue Job
Dispatching the Job
I am trying to create a new queue job as laravel provided.
and the function I want to process by this job is using aimeos context object.
now whenever I tried to dispatched the job it throws and exception related to serialization of aimeos context class
PHP Version: 8.1ErrorException: serialize(): Aimeos\MShop\Context::__sleep() should return an array only containing the names of instance-variables to serialize in file D:\laragon\www\kitchen-aid\vendor\laravel\framework\src\Illuminate\Queue\Queue.php on line 158
Aimeos Version: 2023.07
Laravel Version: 10
I am attaching my some code might be it can help to understand the issue
ProductService
Code: Select all
class ProductService
{
protected $productRepository;
private $aimeosContext;
public function __construct(ERPProductRepository $productRepository)
{
$this->productRepository = $productRepository;
$this->aimeosContext = app('aimeos.context')->get(true);
}
public function syncMshopProductFromErpProduct(array $product)
{
/* @var AimeosItem $productItem */
/* @var AimeosManager $productManager */
/* @var AimeosItem[] $productItems */
$productManager = MShop::create($this->aimeosContext, 'product');
Queue Job
Code: Select all
class ProcessErpProducts implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
private ProductService $productService;
/**
* Create a new job instance.
*/
public function __construct(ProductService $productService)
{
$this->productService = $productService;
}
/**
* Execute the job.
*/
public function handle(): void
{
$product = []; //product data
$this->productService->syncMshopProductFromErpProduct($product);
}
}
Code: Select all
ProcessErpProducts::dispatch($this->productService);
Re: Aimeos Context Serialization Issue
Strange, the __sleep() method of the context object already does that:
https://github.com/aimeos/aimeos-core/b ... t.php#L102
Can you add debug output in that line to see what get_object_vars() returns?
https://github.com/aimeos/aimeos-core/b ... t.php#L102
Can you add debug output in that line to see what get_object_vars() returns?
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
Re: Aimeos Context Serialization Issue
Hi guys!
I have the same issues when i try to add product in basket i have a message.
This data when debug the in __sleep method get_object_vars( $this )
Can you suggest how this can be fixed ?
Aimeos version 2023.10
MacOS, PHP 8.2, Laravel Framework 9.52.5
I have the same issues when i try to add product in basket i have a message.
Code: Select all
#message: "serialize(): Aimeos\MShop\Context::__sleep() should return an array only containing the names of instance-variables to serialize"
Can you suggest how this can be fixed ?
Aimeos version 2023.10
MacOS, PHP 8.2, Laravel Framework 9.52.5
- Attachments
-
- Снимок экрана 2024-12-12 в 14.40.35.png (201.12 KiB) Viewed 21905 times
Re: Aimeos Context Serialization Issue
Thank you for the debug output!
We've changed the __sleep() methods and return only the keys now. Can you please install these versions and try again?
We've changed the __sleep() methods and return only the keys now. Can you please install these versions and try again?
Code: Select all
composer req aimeos/aimeos-base:2023.10.x-dev aimeos/aimeos-core:2023.10.x-dev
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
Re: Aimeos Context Serialization Issue
Yeah, the error's gone, but there's a new one.
I think we still need to adapt this method to the current __sleep implementation( see in attachements ).
Code: Select all
{ "message": "Declaration of Aimeos\\Base\\Filesystem\\Manager\\Laravel::__sleep() must be compatible with Aimeos\\Base\\Filesystem\\Manager\\Standard::__sleep(): array", "exception": "Symfony\\Component\\ErrorHandler\\Error\\FatalError", "file": "/var/www/html/vendor/aimeos/ai-laravel/src/Base/Filesystem/Manager/Laravel.php", "line": 57, "trace": [] }
- Attachments
-
- Снимок экрана 2024-12-12 в 15.38.19.png (79.05 KiB) Viewed 21898 times
Re: Aimeos Context Serialization Issue
Sorry, forgot that one. Please update using:
Code: Select all
composer req aimeos/ai-laravel:2023.10.x-dev
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
Re: Aimeos Context Serialization Issue
Sorry guys another error appeared with the serialization of the closure. Can you take a look, please ?
Code: Select all
Exception {#2674 // vendor/aimeos/ai-client-jsonapi/src/Client/JsonApi/Base.php:205
#message: "Serialization of 'Closure' is not allowed"
#code: 0
#file: "/var/www/html/vendor/aimeos/aimeos-core/src/MShop/Order/Manager/Basket/Standard.php"
#line: 198
trace: {
/var/www/html/vendor/aimeos/aimeos-core/src/MShop/Order/Manager/Basket/Standard.php:198 {
Aimeos\MShop\Order\Manager\Basket\Standard->saveItem(Iface $item, bool $fetch = true): Iface …
›
› $serialized = base64_encode(serialize($clonedItem));
› \t\t$idx = 1;
arguments: {
$value: Aimeos\MShop\Order\Item\AimeosOrder {#2947 …}
}
}
/var/www/html/vendor/aimeos/aimeos-core/src/MShop/Common/Manager/Base.php:210 {
Aimeos\MShop\Common\Manager\Base->save($items, bool $fetch = true) …
› if( method_exists( $this, 'saveItem' ) ) {
› \t$this->saveItem( $item, $fetch );
› } else {
arguments: {
$item: Aimeos\MShop\Order\Item\Basket\Standard {#2781 …}
$fetch: true
}
}
- Attachments
-
- Снимок экрана 2024-12-12 в 15.59.39.png (234.61 KiB) Viewed 21877 times
Re: Aimeos Context Serialization Issue
Can you post your code so we can see what you are trying to serialize?
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
Re: Aimeos Context Serialization Issue
Yes, please.
aimeos-core/src/MShop/Order/Manager/Basket/Standard.php
aimeos-core/src/MShop/Order/Manager/Basket/Standard.php
Code: Select all
$serialized = base64_encode( serialize( clone $item->getItem() ) );
- Attachments
-
- Снимок экрана 2024-12-12 в 16.17.04.png (253.57 KiB) Viewed 21858 times
Last edited by sergey030 on 17 Dec 2024, 12:36, edited 1 time in total.
Re: Aimeos Context Serialization Issue
The getDepositOrder() is your problem. You can't serialize a basket which contains a using a manager. Instead, you have to extend the order manager and add the data when fetching the records from the database. Overwrite/extend the searchRefs() method for that: https://github.com/aimeos/aimeos-core/b ... d.php#L432
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