[SOLVED] Adding user to usergroup when purchasing merchandise

7 years 1 month ago - 7 years 1 month ago #291443 by ksaltman
I am implementing a number of different merchandise plans that I would like, after payment, to have the user added to a usergroup.

When I look at the Access tab of the plan of a subscription there is the second section Subscribers Access Level Settings that will do exactly that for a subscription. The Access tab however does not appear on a Merchandise plan.

Is there another way to add a user to a usergroup after making a payment for a Merchandise plan? I thought maybe an AutoAction might do it, but honestly I'm not real good at setting up Autoactions.

Any help appreciated.

Please Log in to join the conversation.

7 years 1 month ago #291459 by krileon
Merchandise plans don't really have an active or inactive state so CBSubs can't really control the usergroup. It will never be able to reverse the addition of the usergroup, etc.. You can try forcing this behavior using the below in CB Auto Actions.

Plan Active
Global
Triggers: onCPayUserStateChange
User: Automatic
Access: Everybody
Conditions
1: [var3] Equal To PLAN_ID_HERE
2: [var2] Equal To A

For PLAN_ID_HERE use your merchandise plans id. I'm unsure if this will work with merchandise plans.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

7 years 1 month ago #291518 by ksaltman
How much of a world of hurt would I put myself in if I used the CBSubs SQL plug in to do this.

The group I'm trying to add the user who purchases the mercchise item is group_id 28.

So to avoid duplicates in the Joomla #_user_usergroup_map Table SQL Action 1 on Activiation could be:

DELETE FROM #_user_usergroup_map WHERE user_id=[user_id] AND group_id=28;

Then to add the user into the group Action 2 on Activation could be:

INSERT INTO #_user_usergroup_map (user_id, group_id) VALUES ([user_id], 28);

Please advise if the SQL on Activation statements will be executed for a merchandise plan.

Thanks

Please Log in to join the conversation.

7 years 1 month ago #291542 by krileon

How much of a world of hurt would I put myself in if I used the CBSubs SQL plug in to do this.

A lot. Do not tamper with ACL directly through the database. There's a lot of dependencies for ACL. Did the above auto action not work?


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

7 years 1 month ago #291572 by ksaltman
Thanks for the quick response. Well won't go that way.

I didn't try the Auto Action for a number of reasons.
  • Your hesitation regarding would it work with a merchandise plan made me nervous that even if it works today it may not in future versions of CB or CBSubs
  • I'm not really very Auto Action savvy. I did attempt to locate some documentation on each event and what variables are available when it's fired (i.e. your use of var2 & var3) but was not successful. It's probably out there just couldn't find it.

So I think I have come up with an alternative approach. Referencing the Joomla documentation there is the JUserHelper library. It contains addUserToGroup . I am considering using the CBSubs URL plugin and just write a small php file that will add the user to the group on first activation.

I feel comfortable this is well documented, supportable and stays with in the know behavior of CB, CBSubs and Joomla.

What say you?

Please Log in to join the conversation.

7 years 1 month ago #291590 by krileon

Your hesitation regarding would it work with a merchandise plan made me nervous that even if it works today it may not in future versions of CB or CBSubs

That was in regards to the conditions. I can't recall if merchandise plans send an active state to that trigger, but I'm pretty confident they do.

I'm not really very Auto Action savvy. I did attempt to locate some documentation on each event and what variables are available when it's fired (i.e. your use of var2 & var3) but was not successful. It's probably out there just couldn't find it.

There's no documentation for CB Auto Actions beyond the videos below. Most of CB Auto Actions usage is self explanatory. You select the trigger you want to act on, select what type of action you want to execute, then configure the action further from there. Conditions and substitutions can be tricky if you don't know what variables a trigger has, but we've the below page with some of the triggers and their variables.

www.youtube.com/playlist?list=PLp0puRITgC7McQcw0Sli1qfSUQGwmflzi
www.joomlapolis.com/documentation/279-community-builder/tutorials/18358-using-cb-triggers

With that said you should only need exactly the below.

Global
Triggers: onCPayUserStateChange
Type: Usergroup
User: Automatic
Access: Everybody
Conditions
1: [var3] Equal To PLAN_ID_HERE
2: [var2] Equal To A
Action
Mode: Add Usergroups
Groups: SELECT_USERGROUPS_HERE

Replace PLAN_ID_HERE with the ID of your merchandise plan then select what usergroups you want to add.

So I think I have come up with an alternative approach. Referencing the Joomla documentation there is the JUserHelper library. It contains addUserToGroup . I am considering using the CBSubs URL plugin and just write a small php file that will add the user to the group on first activation.

That is going to be significantly more complex to do and maintain than just letting CB Auto Actions handle it. The URL action does not let you use Joomla API as it's just an HTTP request. If your HTTP request isn't to an internal Joomla page then your PHP file will never know Joomla even exists.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.234 seconds

Facebook Twitter LinkedIn