10 years ago
4
Topic

Greetings SEBLODers!

I have a user registration workflow that requires assigning a user to a specific User Group after they have completed an extended user profile which is initially incomplete upon registration and subscription. To do this, I have purchased the Code Pack plugin and intend to use the Before Store action to set the desired User Group based on other information provided in the user profile. My initial attempts have been unsuccessful, so I've configured a simple test to set the User Group to a specific value until I know it's working, then I will add additional code to evaluate and determine which group to assign.

Problem is, even my simple test isn't working, so I assume that I'm doing something wrong. I've searched the forum thoroughly and followed instructions I found in another post here, but without success. Hopefully someone here will recognize my error and lead me toward a solution.

I've configured the field as follows:

Type: BeforeStore
Mode: Free
Code: $config['storages']['#__users']['groups']='14';

'14' is the group_id of a group I want to assign as a simple test to verify that I'm configuring the plugin correctly and that it works. If I can get this simple test working, I'm confident I can extend the code to handle the evaluation of other fields to determine the correct group to assign.

Thanks for any help!
Denver

Get a VIP membership
10 years ago
0
Level 1

UPDATE:  It seems that the field IS working, BUT only when the User content type is first created. It does not execute the code on subsequent edits of the content type form, and unfortunately that is when I need it to work. Has anyone else encountered this? And, is there a way to ensure that the code executes every time the form is saved?

Thanks!

Denver

10 years ago
0
Level 1

Sorry to bump this post, but it's been several days without any comments, so I thought I'd try reaching out to the community again. Several tests have confirmed that this works only when I create a new User-- the BeforeStore code executes and assigns the user to the desired group. However, the same code has no effect when I open and edit the profile of an existing user who is already assigned to another group. In other words, this code works before a new record is stored, but never works when an existing record is edited and before it is stored.

Does this field type (Code Pack: BeforeStore) only work on CREATE and not on UPDATE? I've spent days trying to get past this seemingly small issue that is delaying an important project. Any experience or feedback from others would be greatly appreciated.

Thanks everyone!

693 Posts
rpoy
10 years ago
1
Level 1

Hi Denver,

The format for storing a single data item is like so:

$config['storages'][$table][$field] = $myvalue;

You will need to look in the database using phpMyAdmin to see the table structures. I think your problem might be there is no 'groups' field in the #__user table. This is because each user can belong to more than one user group.

Joomla uses the user_usergroup_map table with user_id and group_id. What you will need to do is get the userid and then update the correct group_id. You should be able to run a mysql update query to update the table. Where things can get a bit messy is if you have users belonging to more than one user group. Are your users belonging to more than one group?

Just be careful that you do not run this as Super Admin, because you could update the wrong rights.

Hope that helps,

Randy

10 years ago
0
Level 2

Thanks, Randy!  I'll do that-- a mysql update query in the CodePack:BeforeStore field to update the user_usergroup_map table for the user. I had initially tried that approach and then felt it would be better to update the database through SEBLOD's interface rather than making the updates directly on the database. If, in this case, that's not going to work, I'll revert to that approach. And because you asked... Each user belongs to a single group, so it shouldn't be too messy.

Thanks again!

Get a VIP membership