Product list item is not saving nor deleting

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!
kdim95
Advanced
Posts: 205
Joined: 26 Aug 2022, 12:17

Product list item is not saving nor deleting

Post by kdim95 » 30 Aug 2023, 02:01

Laravel framework version: 10.16.1
Aimeos Laravel version: 2023.04.*
PHP Version: 8.2.8
Environment: Linux

I can't seem to get this working, is it because of the custom list type?
I added a new Aimeos\Admin\JQAdm\Product\Related\Custom.
Also added a new template, which adds a third box in the "related products" section in the admin product page.
The saving works for the related product tabs in the admin, but saving programmatically seems to fail.
Am I doing something wrong?

Save:

Code: Select all

$product_manager = \Aimeos\MShop::create( $this->context, 'product' );
$index_manager = \Aimeos\MShop::create( $this->context, 'index' );

$product_manager->begin();

$product_item = $product_manager->get( <ID> );
$product_ref_item = $product_manager->get( <REF ID> );

$product_list_item = $product_manager->createListItem()->setType('custom-type');
$product_item->addListItem( 'product', $product_list_item, $product_ref_item  );

$product_manager->save( $product_item );
$product_manager->commit();
$index_manager->rebuild( [ $product_item ] );
Delete:

Code: Select all

$product_manager = \Aimeos\MShop::create( $this->context, 'product' );

$product_manager->begin();

$product_item = $product_manager->get( <ID> );

$list_items = $product_item->getListItems( 'product', 'custom-type', null, false );
$product_item->deleteListItems( $list_items );

$product_manager->save( $product_item );
$product_manager->commit();
$index_manager->rebuild( [ $product_item ] )

kdim95
Advanced
Posts: 205
Joined: 26 Aug 2022, 12:17

Re: Product list item is not saving nor deleting

Post by kdim95 » 30 Aug 2023, 13:12

I did some digging and I found the following.

Apart from the $product_manager transaction, I also begin a $stock_manager transaction:
$stock_manager->begin();

It seems like both transactions need to be finished for the product to be saved.

Is this behavior intended?

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

Re: Product list item is not saving nor deleting

Post by aimeos » 31 Aug 2023, 06:17

This is a side effect of the shared database connections. Each data domain (product, stock. etc.) uses the same database connection if not told otherwise.

If you open two transactions, one in the product manager and one in the stock manager, the transaction requests are stacked and you need to call two times commit() to actually commit the transactions.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply