Admin order decorator - Service attributes not updating after $client->save()

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: 213
Joined: 26 Aug 2022, 12:17

Admin order decorator - Service attributes not updating after $client->save()

Post by kdim95 » 09 Apr 2023, 23:15

Laravel framework version: 9.52.4
Aimeos Laravel version: ~2022.10
PHP Version: 8.2.4
Environment: Linux

I can't seem to get the updated service attributes inside the admin order decorator.

Config:

Code: Select all

'admin' => [
	'jqadm' => [
		'order' => [
			'decorators' => [ 'MyDecorator' ],
		],
	],
]
Decorator:

Code: Select all

namespace Aimeos\Admin\JQAdm\Common\Decorator;
	
class MyDecorator
	extends \Aimeos\Admin\JQAdm\Common\Decorator\Base
{
	
	public function save() : ?string
	{
		$view = $this->view();
		$client = $this->getClient();
		
		// Copy the resource so $view->item is available
		$client->copy();
		
		$item_original = $view->item;
		
		$return = $client->save();
		
		$item_changed = $view->item;
		
		$payment_original = $item_original->getService( 'payment' )->first();
		$payment_changed = $item_changed->getService( 'payment' )->first();
			
		$payment_attributes_original = $payment_original->getAttributeItems(); // Gets current (not updated)  attributes
		$payment_attributes_changed = $payment_changed->getAttributeItems() // Does not return the updated attributes
			
		return $return;
	}
		
}

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

Re: Admin order decorator - Service attributes not updating after $client->save()

Post by kdim95 » 10 Apr 2023, 08:40

Another problem is that the invoice payment status change is also not reflected when executing $client->save().

I'm trying to get the old and new values of every order element before and after it has been changed in the admin.

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

Re: Admin order decorator - Service attributes not updating after $client->save()

Post by aimeos » 11 Apr 2023, 07:41

The save() method stores the updated data in the database but doesn't update the items. If you need the updated items in the end, you have to fetch them from the database.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

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

Re: Admin order decorator - Service attributes not updating after $client->save()

Post by kdim95 » 11 Apr 2023, 15:07

Thanks, that seems to have been the case.

Post Reply