I have 3 rules which make up my "membership".
- Assign role when product X gets purchased (This one works!)
- Send a reminder email after 2 minutes.
- Remove role after 4 minutes.
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.