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: 8380
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

sergey030
Posts: 4
Joined: 12 Dec 2024, 11:32

Re: Aimeos Context Serialization Issue

Post by sergey030 » 12 Dec 2024, 12:41

Hi guys!
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"
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
Attachments
Снимок экрана 2024-12-12 в 14.40.35.png
Снимок экрана 2024-12-12 в 14.40.35.png (201.12 KiB) Viewed 21905 times

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

Re: Aimeos Context Serialization Issue

Post by aimeos » 12 Dec 2024, 12:56

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?

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, Image give us a star

sergey030
Posts: 4
Joined: 12 Dec 2024, 11:32

Re: Aimeos Context Serialization Issue

Post by sergey030 » 12 Dec 2024, 13:39

Yeah, the error's gone, but there's a new one.

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": [] }
I think we still need to adapt this method to the current __sleep implementation( see in attachements ).
Attachments
Снимок экрана 2024-12-12 в 15.38.19.png
Снимок экрана 2024-12-12 в 15.38.19.png (79.05 KiB) Viewed 21898 times

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

Re: Aimeos Context Serialization Issue

Post by aimeos » 12 Dec 2024, 13:43

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, Image give us a star

sergey030
Posts: 4
Joined: 12 Dec 2024, 11:32

Re: Aimeos Context Serialization Issue

Post by sergey030 » 12 Dec 2024, 14:01

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
Снимок экрана 2024-12-12 в 15.59.39.png (234.61 KiB) Viewed 21877 times

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

Re: Aimeos Context Serialization Issue

Post by aimeos » 12 Dec 2024, 14:14

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, Image give us a star

sergey030
Posts: 4
Joined: 12 Dec 2024, 11:32

Re: Aimeos Context Serialization Issue

Post by sergey030 » 12 Dec 2024, 14:19

Yes, please.
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
Снимок экрана 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.

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

Re: Aimeos Context Serialization Issue

Post by aimeos » 12 Dec 2024, 16:37

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, Image give us a star

Post Reply