GDP
GDP

Reputation: 8178

How can I change the Joomla User Group of an existing user

We'd like to change the user from "Registered" to a custom User Group "Customer" when they place an order. I've been tinkering with the various ACL functions, but can't seem to find the way to make it happen.

I started with this, which I found on SO somewhere, but it seems to be dated because $authorize->get_group_id is not found, which makes me think the whole approach is wrong to begin with.

$user           = & JFactory::getUser();
$authorize      = & JFactory::getACL();
$newUsertype    = 'Customer';
$user->set('usertype', $newUsertype);
$user->set('gid', $authorize->get_group_id( '', $newUsertype, 'ARO' ));
$user->save();

Upvotes: 0

Views: 167

Answers (1)

GDP
GDP

Reputation: 8178

Stupid simple....

$newUserGroup = 9;
$result = JUserHelper::addUserToGroup($user_id, $newUserGroup);

Upvotes: 1

Related Questions