How to add user to group by code ?
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!
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
How to add user to group by code ?
Ubuntu 18.04
PHP 7.2
"aimeos/aimeos-laravel": "^2019.04"
Laravel: 5.8
I create user by code:
But how can I add user to some group? Like editor, to allow user access admin panel ?
PHP 7.2
"aimeos/aimeos-laravel": "^2019.04"
Laravel: 5.8
I create user by code:
Code: Select all
$user = new App\User([
'id_customer' => $id_customer,
'id_customer_ref' => $id_customer_ref,
'firstname' => $firstname,
'lastname' => $lastname,
'email' => $email
]);
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
Re: How to add user to group by code ?
This is the way how do I do it:
Is it right way ?
Code: Select all
$context = $this->getLaravel()->make( 'Aimeos\Shop\Base\Context' )->get( false, 'command' );
$context->setEditor( 'aimeos:account' );
$localeManager = \Aimeos\MShop::create( $context, 'locale' );
$localeItem = $localeManager->bootstrap( 'default', '', '', false );
$context->setLocale( $localeItem );
$groupManager = \Aimeos\MShop::create( $context, 'customer/group' );
$customerListsManager = \Aimeos\MShop::create( $context, 'customer/lists' );
$editorGroupId = $groupManager->findItem( 'editor' )->getId();
$item = $customerListsManager->createItem();
$item->setDomain( 'customer/group' );
$item->setParentId( $user->id );
$item->setRefId( $editorGroupId );
$item->setType( 'default' );
$item->setStatus( 1 );
$customerListsManager->saveItem( $item, false );
Re: How to add user to group by code ?
If you want to do it from the command line, then yes. From the web you should use another context:
https://aimeos.org/docs/Laravel/Extend_Aimeos
https://aimeos.org/docs/Laravel/Extend_Aimeos
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star