Rules module

28 replies [Last post]
entrepreneur27
Offline
Joined: 09/09/2009
Status: 
Answered

Leighton:

Did you ever add Rules integration to the membership suite? I saw you were considering it in the past. And if not, any plans to do so?

Leighton Whiting
Offline
Joined: 06/02/2009
Entrepreneur, I was

Entrepreneur,
I was originally planning on making the Rules module required and have all of the workflow go through Rules, so that everything would be customizable, but I realized that this would cause more problems than it would solve (confusing users with the complexity), so I launched without it. I am still considering providing a lesser integration with Rules, so that you can add actions to MoneyScripts Triggers, and Rules wouldn't be required to use the module. I'll give this a +1 on the feature list :)

Sincerely,
Leighton Whiting

entrepreneur27
Offline
Joined: 09/09/2009
Feedback

OK. I tell you what I would find very useful. I would like to have an external event generate a trigger (eg creation of a node of some type) and have that trigger lead to a member being assigned to have a specific subscription in your suite.

Alternately, the trigger might lead to creation of an order in your suite. Ideally both would be possible.

Please add that to the wish list.

Leighton Whiting
Offline
Joined: 06/02/2009
I'll work on adding the Rules

I'll work on adding the Rules integration to the next release (even if it only supports a few actions/triggers/conditions at first). In the mean time, if you can think of any good conditions/actions/triggers, feel free to post them here.

Sincerely,
Leighton Whiting

Leighton Whiting
Offline
Joined: 06/02/2009
Here is a list of what I've

Here is a list of what I've added so far and what will be released with Membership Suite 6.9:

Conditions:
-Check if a user has a membership

Actions:
-Add Membership to User
-Set Expiration Date for User Membership
-Change Membership Status (Active, Cancelled, EOT, etc)

Triggers:
-Membership is added to a user
-Membership is expiring
-Membership is cancelled
-Membership has a payment

I'll be posting a video tutorial on how to use these Rules.

Sincerely,
Leighton Whiting

entrepreneur27
Offline
Joined: 09/09/2009
More on Rules

Hi Leighton:

Any word on when we might expect these great additions?

I am also interested in finding a way to create orders using Rules. The reason is that I believe if we did this we would be able to get data about the price paid etc into your suite, and that would allow this information to be reused in the affiliates suite and give the affiliate credit for a new membership that has been added by means of Rules. In contrast if you use Rules to add a membership I suspect there will be no associated price and it will not link to the affiliates suite. Am I correct?

bkbetts
Offline
Joined: 03/29/2010
Sorry to somewhat hijack this

Sorry to somewhat hijack this thread, but the rules integration seems great. If I have things correct, one would be able to create rules for email reminders for all plans. This would allow one to define a "global" expiration message for all plans instead of changing it for each membership plan. The email templates for each plan could even be done away with once rules is integrated as a rule could be created instead. Is this correct?

Leighton Whiting
Offline
Joined: 06/02/2009
@entrepreneur, The Membership

@entrepreneur,
The Membership Suite 6.9 will only include support for Membership Suite rules and a few rules for MS Core. Rules like adding a new Order and adding new payments will come in the next version.

@bkbetts,
Yes, you could use rules to do that, and replace the email functionality that the plans currently use. I won't be taking them out, however, because that would mean requiring that people use rules and that would add some unnecessary difficulty to the system, and I'd like to keep it as simple as possible. The rules integration will be for those advanced users who don't mind getting their hands dirty a little :)

Sincerely,
Leighton Whiting

juicytoo
Offline
Joined: 07/22/2009
rules auto create og

Hi Leighton,

Thanks for the great improvements.

Any chance of adding this feature request in the future:

1. with roles promotion upon payment, an og group is automatically created for that user. Maybe through the use of rules.

Thanks
Ed

Leighton Whiting
Offline
Joined: 06/02/2009
Ed, I can't speak for the OG

Ed,
I can't speak for the OG group creation part, but if they have rules actions that can do that, then this is already possible because Membership Suite provides a trigger for Membership Signups and Expirations.

Sincerely,
Leighton Whiting

entrepreneur27
Offline
Joined: 09/09/2009
Rules question

Hi Leighton:
Just trying out your Rules features. Great start.

I have a use case I am a bit stuck on. Hope you have a suggestion.

I want to grant a membership when the user creates a node of a particular type (content type "Signup for role"). However I want the membership to be one of several possible ones, and to have the Rule select the right membership depending on some field in the node the user creates.

I can think of several possible ways to do this, but so far none seems right. Here they are:

1. If a membership plan were a node then I could create a node reference field in the content type "Signup for role" that allows the user to select one of the available membership plans.

2. I could hard code a Rule set that matched a plan and some other variable on the "Signup for Role" node. For example, "If varx = plan 1, set membership type 1 etc". However then I would need to adjust this Rule set every time I added a plan and that would be a pain.

Any ideas? Basically the Rules implementation would be even better if there is some way for the Rule to be fed something that tells it which plan to add.

Leighton Whiting
Offline
Joined: 06/02/2009
Entrepreneur, I think a new

Entrepreneur,
I think a new action needs to be created for this to work. Try replacing your ms_membership.rules.inc with the attached file, which adds a new action called 'Add a Membership to a User by Plan ID'. You would then have to use either tokens or php to automatically get the plan id number that you want to use from the node (probably stored in a CCK field, for example).

Let me know if that works for you.

Sincerely,
Leighton Whiting

AttachmentSize
ms_membership.rules_.zip 1.63 KB
ssmemrules.PNG 22.83 KB
entrepreneur27
Offline
Joined: 09/09/2009
Almost but still a problem

Hi Leighton:

I like this so please keep this functionality in later releases. I can get the Rules to create a membership just fine this way. It all looks fine on the membership list page. However the MS module does not appear to be granting the appropriate roles to the user when I create the membership this way. In contrast if I go in and manually add a membership a role is granted as expected.

I suspect this is a bug. Please advise.

Leighton Whiting
Offline
Joined: 06/02/2009
Entrepreneur, I'll keep it

Entrepreneur,
I'll keep it in. I found a bug that I think was causing that problem. Attached is the updated file. Give it a try and let me know if it works.

Sincerely,
Leighton Whiting

AttachmentSize
ms_membership.rules_.zip 1.68 KB
entrepreneur27
Offline
Joined: 09/09/2009
Not fixed

Leighton:
Sorry to say the problem remains unchanged with this new file. I ran update before testing too.

Leighton Whiting
Offline
Joined: 06/02/2009
Oops, I only applied the fix

Oops, I only applied the fix to the 'Add Membership to User' action and forgot the 'Add Membership to User by Plan ID' action. The attached file should work.

Sincerely,
Leighton Whiting

AttachmentSize
ms_membership.rules_.zip 1.68 KB
entrepreneur27
Offline
Joined: 09/09/2009
Not the problem

Sorry. Still does not work. It is not assigning a role. Is it doing that on your site?

Leighton Whiting
Offline
Joined: 06/02/2009
Entrepreneur, The last one

Entrepreneur,
The last one works for me, it adds the membership and the roles as it should.

Sincerely,
Leighton Whiting

entrepreneur27
Offline
Joined: 09/09/2009
Right file

Are you sure you attached the right file as a download to your comment above? It looks quite similar, and that would explain it perhaps??

Also I want to add a membership to a user while they are still blocked. Could that cause any issues?

Leighton Whiting
Offline
Joined: 06/02/2009
Yeah, I just downloaded it to

Yeah, I just downloaded it to check, and the fix is in there. This is the function that was changed so you can check it yourself:

/**
* Action: Add a membership to a user
*/
function ms_membership_action_add_membership_by_id($mpid, $account) {
$m_plan = ms_membership_load_membership_plan($mpid);
// Add a new membership for this user
$membership = ms_membership_insert_new_membership($m_plan, $account);
// Add and remove the roles at the start of the membership
ms_membership_change_roles($account->uid, $m_plan->start_grant_roles, $m_plan->start_remove_roles);
return array('membership' => $membership);
}

I added in the ms_membership_change_roles function so that the roles would be added.

Sincerely,
Leighton Whiting

entrepreneur27
Offline
Joined: 09/09/2009
Definitely not working here

Hmm. Well I downloaded it again just in case. When the Rule gets run, the membership gets assigned just fine and I can see it on the membership list under "Users". However the role is not granted.

Any ideas what I may be missing? Or any ideas how to get to the bottom of this? I could really use this functionality and everything else is working fine.

entrepreneur27
Offline
Joined: 09/09/2009
One more thing

I was looking at the code and noticed it says "add and remove role at start of membership".

So I went and looked at the membership that Rules just created and noticed it has a start date of 6/24. Now at present (when Rules created membership) it is 6/23 at 10.10pm in CA. My server displays that time in the Drupal installation but the server itself is on East Coast time. So I am guessing the membership draws its start date from the east Coast server (previous times it seems to have started the membership on the day it was applied).

If this is just a display issue, I dont care about it. However I am wondering if the role grant is on creation of the membership or at some specific date/time, and whether this could be causing any issues?

Otherwise it seems this function is just not executing. I am pretty sure I have the correct user selected in the Rules parameters because it is creating the membership correctly. Just not assigning a role.

Im hoping you have a good idea how to proceed. :)

Leighton Whiting
Offline
Joined: 06/02/2009
The server time shouldn't

The server time shouldn't affect the granting of the roles, since it is run immediately after the membership is added to the user. I would check the membership plan and make sure that it is set up to add a role at the start of the membership. Also, turn on the Debug Messages and run it and then check the logs. It should say what it is doing.

Sincerely,
Leighton Whiting

entrepreneur27
Offline
Joined: 09/09/2009
Some debugging for you

Hi Leighton:

I did some debugging tests, and am hoping this will help figure out what the problem is. Here is what I did.

1. I added a membership to testclient5 using Rules ( add membership by plan id).
The membership shows up as adding with correct expiration etc. However no role is assigned. The log shows entries as below.

Log message on adding membership with Rules.:
ms_membership 06/24/2010 - 09:48 Sending an Email to a User. Message:
Array
(
...
richard
ms_membership 06/24/2010 - 09:48 Sending an Email to a User. Message:
Array
(
...
richard
ms_membership 06/24/2010 - 09:48 Added role Premium: Silver Intro trial to

2. I deleted the above membership and then added the same membership back, but this time used the MS U/I to add the membership instead of Rules.
The membership was added and looks the same as it did when Rules did the adding on the membership screen. But this time the role was correctly added. The log entires are below.

Log message on adding membership manually:

ms_membership 06/24/2010 - 09:55 Membership Plan Premium: Silver Intro trial ... richard
ms_membership 06/24/2010 - 09:55 Sending an Email to a User. Message:
Array
(
...
richard
ms_membership 06/24/2010 - 09:55 Sending an Email to a User. Message:
Array
(
...
richard
ms_membership 06/24/2010 - 09:55 Added role Premium: Silver Intro trial to richard

Comments
a. There seems to be an extra log entry in the case of the manual process that is not there in the Rules entry. Not sure why that would be?
b. Seems like the Rules action is somehow not doing what it needs to do.
c. Hoping this helps.

entrepreneur27
Offline
Joined: 09/09/2009
Release 6.10

Hi leighton:

Would you expect v 6.10 to fix this Rules issue? Have you added more Rules support in this release?

Leighton Whiting
Offline
Joined: 06/02/2009
Other than adding that code

Other than adding that code (which was working for me) to the rules integration, I haven't changed anything with rules in this release. I was planning on adding some more Core rules (like creating orders, payments, etc) but wanted to get this release out first because of some bug fixes.

Sincerely,
Leighton Whiting

entrepreneur27
Offline
Joined: 09/09/2009
OK

Do you have any good ideas how I can troubleshoot the fact that it is not working for me? Not sure if you saw the post two up from here where I added log entries. Seemed like something was missing but dont know how to troubleshoot further.

Leighton Whiting
Offline
Joined: 06/02/2009
It looks like according to

It looks like according to the log, the role is being added correctly both times, which is also the case for me. I suspect that when the Rule triggers, something happens afterwards that removes the role from the user. Can you expand a bit on what the rule does (when it triggers) and also if you can think of any other rules or modules that deal with removing roles from users?

Sincerely,
Leighton Whiting

entrepreneur27
Offline
Joined: 09/09/2009
Solved I think

Thanks Leighton:

I still need to test further but I think you made the right suggestion. I have another rule running after this that is meant to remove a different and unrelated role. For some reason it seems to remove the wrong role (in this case the membership role) in the case when the user does not have the role it is supposed to remove. Easily rectified with an extra condition in the subsequent rule.

If I don't post again it means this is fixed.

Twitter Feed