[SOLVED] "Bonus" Plan Access

7 years 3 weeks ago - 7 years 1 week ago #292531 by micheleq
[SOLVED] "Bonus" Plan Access was created by micheleq
Hi,

I've been trying different possibilities for this but I can't get it to work as I'd like to, maybe someone can help?

  • I have a community where members pay monthly, semi-annual or annual plans to subscribe to the site.
  • Members come and go, and may be off for several months before coming back in on the same or a different payment plan.
  • I'd like to give those users who have been members for more than two years a "Gold" Status and those more than 5 years a "Platinum" status.
  • The "status" would mean higher access levels, i.e. Registered -> Gold -> Platinum, which would mean extra content available to them and wider forum (Kunena) access.
  • I'm not charging for this extra status, and I can't assign it manually, too many users.
  • Their Payment plan should still rule access to the site, if their payment plan expires, they are out altogether, if they resubscribe to one of the payment plans then they'd have the elevated access automatically.

My idea was to set a new field in CB, that would indicate if they were Registered (0), Gold (1) or Platinum (2). Since calculating the paid time they've been members isn't as straight forward as looking at their registration date, I'm planning on doing a cronjob to run once or twice a month (sum of money paid) to update that field.

I tried setting a new plan for Gold and Platinum, lifetime for free, with the option of it only showing as an upgrade if the cb field condition was met, and one of the other paying plans was active.

The problem I'm having is that when the paying subscription expires, the user still has access, because of the Gold/Platinum plan. Access to the site and User Access levels remain untouched after expiration.

Is there a way to set the plans to accommodate this, or is there another way?

Also I'd rather they didn't have to cancel their current paying plan (many are on annual plans) and subscribe again to get the elevated access.

Thank you,
Tomás

Please Log in to join the conversation.

7 years 3 weeks ago #292559 by krileon
Replied by krileon on topic "Bonus" Plan Access
Using CB Query Field you can query for their subscription start and end date then determine if they've been subscribed for however much time using SQL functions. Then using CB Auto Actions condition against that field on login to automatically give them a usergroup based off the results of your query. Your query should only check for active subscription so lets say it returns 0 if they don't have an active subscription and if it's 0 then remove those 2 special usergroups. This would automate the entire process.

The below query for example will get the number of years they've been subscribed from their subscription date to their expiration date for a specific active plan.

SELECT ( YEAR( `expiry_date` ) - YEAR( `subscription_date` ) ) as years FROM `#__cbsubs_subscriptions` WHERE `user_id` = '[user_id]' AND `plan_id` = PLAN_ID_HERE AND `status` = 'A'

You could have 3 actions with 3 different conditions. If < 2 then remove Gold and Platinum. If >= 2 add Gold. If >= 5 add Platinum.


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 3 weeks ago #292568 by micheleq
Replied by micheleq on topic "Bonus" Plan Access
Hi Kyle,

Thank you, I'm trying to understand CB Auto Actions, which seems very powerful. I think I have the solution from what you mentioned, with some tweaks.

The goal is to reward longevity (of payments) in our community with access to extra forum area and downloads, without it being a separate subscription.

The workflow I've come up with to be as efficient as possible with the lowest load on the server is as follows:
  • I've created an extra CB filed, cb_heritage, as radio buttons with 3 values: 0=Members,1=Gold & 2=Platinum.
  • I've created usergroups Gold and Platinum above Registered for them.
  • I'm creating a SQL Query to determine who has achieved these rights and writing to that CB filed the appropriate value. I decided to do this as an outside cronjob, because I only need it to run at most every 2 weeks and it's not simple since I have to consider the registration date, how much money they've paid so far and if they paid a year in advance, when was that payment. Otherwise I'm not covering all the possibilities of users coming and going with different plans and taking breaks.
  • On the first run of the query I'll assign the new usergroups to those active members who match the settings.
  • Once this is set, it makes it much easier going forward, 2 very simple rules in CB Auto Actions:
    1. When a user logs in, if they don't have an active subscription then usergroups Gold and Platinum are removed. Here I don't need to check if they have the heritage status or not, if they don't have it, it doesn't make a difference.
      Type: Usergroup,
      Trigger: onAfterUserLoginSuccess,
      Condition: would be an existing active subscription (I haven't figured out how to set that condition)
      Action: remove Gold and Platinum Usergroups

    2. When a new subscription is made it should check for heritage status, and if so grant the usergroup that matches.
      a)
      Type: Usergroup,
      Trigger: -on user subscription - is there such a trigger, I couldn't find it..
      Condition: [cb_heritage] = 1
      Action: add Gold Usergroup
      b)
      Type: Usergroup,
      Trigger: -on user subscription - is there such a trigger, I couldn't find it..
      Condition: [cb_heritage] = 2
      Action: add Platinum Usergroup

The bolded parts are what I need some help with.

Thank you

Tomás

Please Log in to join the conversation.

7 years 3 weeks ago #292579 by krileon
Replied by krileon on topic "Bonus" Plan Access
I think you're making a simple usage into a significantly more complicated one. You can evaluate the number of years, days, months, etc.. the user has been subscribed using a CB Query Field.

Name: cb_queryfield
Code:
SELECT ( YEAR( `expiry_date` ) - YEAR( `subscription_date` ) ) as years FROM `#__cbsubs_subscriptions` WHERE `user_id` = '[user_id]' AND `plan_id` = PLAN_ID_HERE AND `status` = 'A'

Then you'd just condition against it in CB Auto Actions as follows.

Global
Triggers: onAfterLogin
Type: Usergroup
User: Automatic
Access: Everybody
Conditions
1: [cb_queryfield] Greater Than or Equal To 2
Action
Mode: Add Usergroups
Groups: Gold

The above acts on the after login trigger and gives them the Gold usergroup if they've been subscribed for 2 years. The query can be adjusted as needed to fit whatever criteria you need it to fit.

If you still want to use what you've configured then for your first auto action you'd condition against the field that you're setting via CRON so you'd condition against [cb_heritage]. For the second and third auto actions you can act on subscription state changes using the below.

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

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


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 2 weeks ago #292707 by micheleq
Replied by micheleq on topic "Bonus" Plan Access
Hi Kyle,

This has got me almost there.

I've come up with a php file that when run, calculates who's earned Gold or Platinum Status, and updates the appropriate filed in the db. The calculation is not as simple for me as what you've written (wish it was) because most of our members take "breaks" and come back after a few months. Since I "allow gaps" in the renewals and many people switch between monthly, yearly and 6-month plans, looking at their current plan would disqualify most members that do qualify and qualify some who don't. I've resorted to adding up all their payments and prorating annual payments if they were made within the last year (also adjusting for the year plan discount), same for the 6-months plan. I do have a few exceptions to consider manually (free memberships and those paying with checks), but it is working fine, and tests ok.

Now what I realized is that what I effectively want is a Kunena Rank that provides extra access levels. I was originally going to show it as an extra "badge" on their membership, like the "Plan Image" but the Kunena Rank is a better fit for me.

What you wrote for me (thank you), works great against the CB field. I only removed the Plan ID condition since I want it to work for any plan.

Now I want it to work for the Kunena Rank field, which I do have in my CB Field list, but it doesn't work and my guess is because it's a "calculated" field and not an actual CB field in the Comprofiler table.

This is what I have:

Plan Active Gold
Global
Triggers: onCPayUserStateChange
User: Automatic
Access: Everybody
Conditions
1: [var2] Equal To A
2: [cb_forumrank] Equal To 13 (the corresponding rank ID for Gold)
Enable usergroup Gold

Plan Active Platinum
Global
Triggers: onCPayUserStateChange
User: Automatic
Access: Everybody
Conditions
1: [var2] Equal To A
2: [cb_forumrank] Equal To 14 (the corresponding rank ID for Platinum)
Enable usergroup Platinum

Plan Expired
Global
Triggers: onCPayUserStateChange
User: Automatic
Access: Everybody
Conditions
1: [var2] Not Equal To A
Disable usergroups Gold & Platinum

So the question is can I condition against the Forum Rank field somehow, or do I have to use my [cb_heritage] radio button field that I created and tie it externally to the rank?

Thanks,
Tomás

Please Log in to join the conversation.

7 years 2 weeks ago #292741 by krileon
Replied by krileon on topic "Bonus" Plan Access

Now I want it to work for the Kunena Rank field, which I do have in my CB Field list, but it doesn't work and my guess is because it's a "calculated" field and not an actual CB field in the Comprofiler table.

CB Forums output of the Kunena rank is just outputting what Kunenas rank profile field outputs. It has no storage so you won't be able to update it by changing the value. You can replace Kunenas sidebar within CB Forums and it supports substitution and HTML as well. This means you could have an IF substitution against your field and output a custom rank image or something of the sort in the sidebar otherwise just output Kunena rank as normally. Aside from that I guess you could make a new rank in Kunena then assign it to them using a database query on _kunena_users table.

So the question is can I condition against the Forum Rank field somehow, or do I have to use my [cb_heritage] radio button field that I created and tie it externally to the rank?

Don't think you'll be able to condition against the forum rank field, but I suppose you could use a query field to query for their raw rank id then condition against that.


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.274 seconds

Facebook Twitter LinkedIn