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

Customer manager save event

Post by MikaelNazarenko » 29 Oct 2019, 14:40

I need to export customer when it was saved. But not in all cases. In some case it must not do import. I have added logic to my custom customer manager saveItem() method. But problem is that I can't tell to manager when I don't need to make export or another action. I need make export of customer when it was saved on admin panel or front-end. I tried to add field 'makeExport' to manager or customer entity but it still makes export when I don't need it.... Can you, please, suggest me something.. ? I hope my problem is understandable )

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

Re: Customer manager save event

Post by aimeos » 30 Oct 2019, 07:14

Add your decorator only for frontend and backend but not for command in your ./config/shop.php:
https://github.com/aimeos/aimeos-larave ... #L104-L108
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 » 30 Oct 2019, 08:16

Thank you! But can you please clarify how this settings with decorator must look like:

Code: Select all

	'frontend' => [
	],
	'backend' => [
	],
And how the decorator must look like for this specific case ? Ideally it must catch the customer saving. So when customer saved from backend or frontend - my logic will do necessary things

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

Re: Customer manager save event

Post by aimeos » 31 Oct 2019, 08:47

You have to implement the saveItem() and saveItems() method in your manager decorator:
https://aimeos.org/docs/Developers/Libr ... s#Easy_way

Configuration for frontend and backend would be:

Code: Select all

'frontend' => [
    'customer' => [
        'manager' => [
            'decorators' => [
                'local' => ['Myproject']
            ]
        ]
    ]
],
'backend' => [
    'customer' => [
        'manager' => [
            'decorators' => [
                'local' => ['Myproject']
            ]
        ]
    ]
],
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 » 31 Oct 2019, 09:29

Aimeos, thank you very much !!

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

Re: Customer manager save event

Post by MikaelNazarenko » 31 Oct 2019, 11:34

One moment, it that documentation from your post, the class \Aimeos\MShop\Common\Manager\Decorator doesn't exist in newest versions of Aimeos. Which class should I use ? I guess \Aimeos\MShop\Common\Manager\Decorator\Base this one ?

My config looks like:

Code: Select all

	'backend' => [
	    'customer' => [
	        'manager' => [
	            'decorators' => [
	                'local' => ['Customer']
                ]
            ]
        ]
	],
My decorator:

Code: Select all

namespace Aimeos\MShop\Customer\Manager\Decorator;

class Customer extends \Aimeos\MShop\Common\Manager\Decorator\Base
{
    public function saveItem( \Aimeos\MShop\Common\Item\Iface $item, $fetch = true )
    {
        die;
        // do something before
        $result = $this->getManager()->saveItem( $item, $fetch );
        // do somthing afterwards
        return $result;
    }
}
But when I save some customer in backend nothing happens..

What the problem ?

Versions of the components:

Code: Select all

aimeos/ai-admin-jqadm                 2019.10.3 Aimeos ai-admin-jqadm extension
aimeos/ai-admin-jsonadm               2019.10.1 Aimeos ai-admin-jsonadm extension
aimeos/ai-client-html                 2019.10.4 Aimeos ai-client-html extension
aimeos/ai-client-jsonapi              2019.10.1 Aimeos JSON API extension
aimeos/ai-controller-frontend         2019.10.2 Aimeos ai-controller-frontend extension
aimeos/ai-controller-jobs             2019.10.2 Aimeos ai-controller-jobs extension
aimeos/ai-gettext                     2019.10.1 Aimeos Gettext extension
aimeos/ai-laravel                     2019.10.1 Laravel adapter for Aimeos web shops and e-commerce solutions
aimeos/ai-payments                    2019.10.1 Payment extension for Aimeos web shops and e-commerce solutions
aimeos/ai-swiftmailer                 2019.10.1 SwiftMailer adapter for Aimeos web shops and e-commerce solutions
aimeos/aimeos-core                    2019.10.2 Full-featured e-commerce components for high performance online shops
aimeos/aimeos-laravel                 2019.10.1 Professional, full-featured and high performance Laravel e-commerce package for online shops and complex B2B projects

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

Re: Customer manager save event

Post by MikaelNazarenko » 05 Nov 2019, 16:21

Are you sure that it works ? For me doesn't.. And I can't find documentation for this for 2019 version..

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

Re: Customer manager save event

Post by aimeos » 05 Nov 2019, 16:26

Indeed, it's

Code: Select all

class Myproject extends \Aimeos\MShop\Common\Manager\Decorator\Base
Sorry for that, documentation is fixed.
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 » 05 Nov 2019, 16:58

My problem is because nothing happens when I save the customer from admin panel (back-end). But there is a die; I described my files in couple posts above..

This is my decorators path /var/www/schmuck/ext/labor/lib/custom/src/MShop/Customer/Manager/Decorator/Customer.php

And decorator looks like:

Code: Select all

namespace Aimeos\MShop\Customer\Manager\Decorator;

class Customer extends \Aimeos\MShop\Common\Manager\Decorator\Base
{
    public function saveItem( \Aimeos\MShop\Common\Item\Iface $item, $fetch = true )
    {
        die;
        // do something before
        $result = $this->getManager()->saveItem( $item, $fetch );
        // do somthing afterwards
        return $result;
    }
}
I can't understand what is the problem.. I also tried to set wrong decorator in settings like:

Code: Select all

	'backend' => [
	    'customer' => [
	        'manager' => [
	            'decorators' => [
	                'local' => ['CustomerNotExisting']
                ]
            ]
        ]
	],

But no any errors....

Maybe because I extended customer manager and sqls for insert, update, search.. But it should not..

Thanks for the help !

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

Re: Customer manager save event

Post by aimeos » 05 Nov 2019, 17:22

MikaelNazarenko wrote: 05 Nov 2019, 16:58

Code: Select all

	'backend' => [
	    'customer' => [
	        'manager' => [
	            'decorators' => [
	                'local' => ['CustomerNotExisting']
                ]
            ]
        ]
],
You forgot the "mshop" key in your config:

Code: Select all

'backend' => [
    'mshop' => [
        'customer' => [
            'manager' => [
                'decorators' => [
                    'local' => ['Customer']
                ]
            ]
        ]
    ]
],
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply