I have 3 rules which make up my "membership".
Please note the 2 and 4 minutes are only there for testing purposes, they will become 350 and 365 days.
While both 2. or 3. work, I have two issues:
Rules n2 and n3 fire at the same time, so at 2 mins mark not only the email is sent, but also the role is removed.
Let's say user MARK purchase product X, and a minute after, JOE does the same. After 2 minutes that MARK purchased the product X, MARK gets the reminder email, his role is removed but also JOE gets the reminder email, and his role is removed.
It seems as soon something triggers, all do.
As you can see from the exports, I made one rule trigger from x minutes of the commerce order completed, and the other from the role assigned, thinking that relating to 2 different events, I would solve the issue. It didn't work.
Here are the exports of my rules:
Rule "Send a reminder" component:
{ "rules_sends_email_to_pipps_reminder_1_week_prior_expiry" : {
"LABEL" : "Sends Email to PIPPS Reminder 1 week prior expiry",
"PLUGIN" : "rule set",
"OWNER" : "rules",
"REQUIRES" : [ "rules" ],
"USES VARIABLES" : { "user_argument" : { "label" : "User {argument}", "type" : "user" } },
"RULES" : [
{ "RULE" : {
"DO" : [
{ "mail" : {
"to" : "[commerce-order:mail]",
"subject" : "Heads up!",
"message" : "Yo! Heads up!",
"from" : "pipps@siteemail.com",
"language" : [ "site:current-cart-order:state" ]
}
}
],
"LABEL" : "Send email reminder to PIPPS"
}
}
]
} }
Rule "Send a reminder" trigger:
{ "rules_send_reminder_email_to_pipps_role_trigger_rule_" : {
"LABEL" : "Send reminder email to PIPPS Role {trigger rule}",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "commerce_order", "rules", "rules_scheduler", "commerce_checkout" ],
"ON" : { "commerce_checkout_complete" : [] },
"IF" : [
{ "commerce_order_contains_product" : {
"commerce_order" : [ "commerce_order" ],
"product_id" : "PIPPS",
"operator" : "=",
"value" : "1"
}
}
],
"DO" : [
{ "schedule" : {
"component" : "rules_sends_email_to_pipps_reminder_1_week_prior_expiry",
"date" : {
"select" : "site:current-cart-order:created",
"date_offset" : { "value" : 120 }
},
"identifier" : "Reminder email to [account:uid]",
"param_user_argument" : [ "commerce-order:owner" ]
}
}
]
} }
Rule "Role Expire" component:
{ "rules_expire_pipps_role_rule_set_" : {
"LABEL" : "Expire PIPPS Role {rule_set}",
"PLUGIN" : "rule set",
"OWNER" : "rules",
"REQUIRES" : [ "rules" ],
"USES VARIABLES" : { "user_argument" : { "label" : "User {argument}", "type" : "user" } },
"RULES" : [
{ "RULE" : {
"DO" : [
{ "user_remove_role" : {
"account" : [ "user_argument" ],
"roles" : { "value" : { "13" : "13" } }
}
}
],
"LABEL" : "Expire action {rule}"
}
}
]
} }
Rule "Expire Role" trigger:
{ "rules_remove_pipps_role_trigger_rule_" : {
"LABEL" : "Remove PIPPS Role {trigger rule}",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules", "rules_scheduler" ],
"ON" : { "user_update" : [] },
"IF" : [
{ "user_has_role" : { "account" : [ "account" ], "roles" : { "value" : { "13" : "13" } } } }
],
"DO" : [
{ "schedule" : {
"component" : "rules_expire_pipps_role_rule_set_",
"date" : {
"select" : "site:current-cart-order:created",
"date_offset" : { "value" : 240 }
},
"identifier" : "Remove User role [account:uid]",
"param_user_argument" : [ "account" ]
}
}
]
} }
Any suggestion is very appreciated! Thanks.
Your Rules (and Rules Components), seem to "work as implemented" ... You 'issue' appears to be that you should be more patient during your testing ... Read on for more details ...
After a rule is scheduled (using the Rules Scheduler submodule), it will only actually execute next time cron runs.
Example:
timestamp X1
.Y mins after timestamp X1
, then the execution of this 1st Rules Component will only happen then (= at Y mins after timestamp X1
).timestamp X2
.Y mins after timestamp X2
, then the execution of this 2nd Rules Component will only happen then (= at Y mins after timestamp X2
).Because of what is described in the scenario of your question, it seems that timestamp X2
is happening BEFORE Y mins after timestamp X1
. That would also explain why BOTH Rules Components actually execute (more or less) at the same time.
Assuming that your cron jobs are running every hour, a straight forward (minor) fix to your Rules Components that is scheduled after 4 minutes, would be to schedule them after (e.g) 2 hours instead. So that you are sure that both Rules Component are not actually executed during the very same cron job.