Customer manager save event

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!
MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

Re: Customer manager save event

Post by MikaelNazarenko » 05 Nov 2019, 21:34

Thank you very much! It works. But another problem( Method saveItem from my decorator also called when I delete customer in backend. How can I know if saveItem was called because of deletion ? Or how to solve it.. ?

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

Re: Customer manager save event

Post by aimeos » 06 Nov 2019, 11:53

Currently, that's hard to distingish. In the next version, we will delete the referenced items directly instead of using saveItem().

In the meantime, you can overwrite the JQAdm customer class and replace saveItem() in https://github.com/aimeos/ai-admin-jqad ... d.php#L152 by:

Code: Select all

$rmIds = [];

foreach( $view->item->getListItemsDeleted() as $listItem )
{
	if( $listItem->getRefItem() !== null ) {
		$rmIds[$listItem->getDomain()][] = $listItem->getRefId();
	}
}

foreach( $rmIds as $refDomain => $ids ) {
	\Aimeos\MShop::create( $context, $refDomain )->deleteItems( $ids );
}
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

Re: Customer manager save event

Post by MikaelNazarenko » 06 Nov 2019, 13:37

Another problem I faced with (( In the decorator's saveItem method can I know if $item was modified ? And which fields was modified ?

For now I only have stupid idea to fetch this item from DB and compare fields. But it will be one more query each time when saveItem...

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

Re: Customer manager save event

Post by aimeos » 08 Nov 2019, 10:23

For the main items, you can use:

Code: Select all

$item->isModified()
But you have to check the referenced items and properties too if you want to know if ANYTHING changed (each item has the isModified() method).
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

Re: Customer manager save event

Post by MikaelNazarenko » 09 Nov 2019, 11:32

Hmmm, I check isModified() method in my decorator before saveItem. And when I go to some customer in backend and change nothing, just click save - it gives me true.. But I have not changed any fields.. Can I solve it somehow ?

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

Re: Customer manager save event

Post by aimeos » 11 Nov 2019, 08:35

The database driver converts fetched data to unexpected types ('' => NULL and 5 => '5'). That lead to modified items whenever you press save in the admin interface. We've implemented a workaround for that. Can you please run that commands and test if the modified flag isn't set any more without change?

Code: Select all

composer req aimeos/aimeos-core 2019.10.x-dev
composer req aimeos/ai-admin-jqadm 2019.10.x-dev
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

Re: Customer manager save event

Post by MikaelNazarenko » 11 Nov 2019, 21:03

Thank you for great cooperation! I have executed that commands and successfully got dev versions:

Code: Select all

"aimeos/ai-admin-jqadm": "2019.10.x-dev",
"aimeos/aimeos-core": "2019.10.x-dev",
But no success ((

I tried $item->isModified() in my customer manager decorator and in my custom customer manager in saveItem() method. It always returns true. I tried from back-end, just went into some customer and clicked save. Nothing changed (

How can I revert back my composer to exact versions which I used before ?

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

Re: Customer manager save event

Post by aimeos » 12 Nov 2019, 09:09

You can find out what's causing the modified flag if you add the code below here:
https://github.com/aimeos/aimeos-core/b ... e.php#L135

Code: Select all

if( !strncmp( $name, 'customer', 8 ) ) {
	error_log( 'modified: ' . $name . ' :: ' . var_export( $this->bdata[$name] ?? null, true ) . ' -> ' . var_export( $value, true ) );
}
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

MikaelNazarenko
Expert
Posts: 274
Joined: 27 Jun 2019, 16:19

Re: Customer manager save event

Post by MikaelNazarenko » 15 Nov 2019, 15:19

Ok, I have tried it with this:

Code: Select all

"aimeos/ai-admin-jqadm": "2019.10.x-dev",
"aimeos/aimeos-core": "2019.10.x-dev",
And I have changed nothing as usual and the log looks like this:

Code: Select all

[15-Nov-2019 15:18:15 UTC] modified: customer.groups :: NULL -> array (
  0 => 1,
)
Can I solve this problem ?

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

Re: Customer manager save event

Post by aimeos » 17 Nov 2019, 16:23

We've found the problem with get/setGroups(). Can you run "composer update" to get the latest aimeos/aimeos-core 2019.10.x-dev version and try again?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply