Aimeos Context Serialization Issue

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!
User avatar
MuhammadSohailAfzal
Posts: 1
Joined: 27 Jul 2023, 21:11

Aimeos Context Serialization Issue

Post by MuhammadSohailAfzal » 27 Jul 2023, 21:25

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
ErrorException: 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
PHP Version: 8.1
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);
    }
}
Dispatching the Job

Code: Select all

ProcessErpProducts::dispatch($this->productService);

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

Re: Aimeos Context Serialization Issue

Post by aimeos » 29 Jul 2023, 10:57

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

Post Reply