[SOLVED] Limit availability subscription plan based on active subscriptions

8 years 1 month ago - 8 years 1 month ago #280078 by solferry
Dear,

I believe I did found a topic on it but I can't seem to find it anymore, so sorry if I have a duplicate question.

Case:

We have a subscription plan where we want to limit the amount of users to a maximum of 50.

Question:

Is it possible to make this subscription unavailable after 50 active users have signed in?

Solution:

On the register page I have to set a query to count the number of active subscriptions within the database for plan x.
As I am not really aware of the structure of the files for the plugin, which file do I need to edit to enter this query in? Writing the code isn't an issue.. just the file to place this code in.


From what I see, there is no build-in possibility for this functionality right?

Please Log in to join the conversation.

8 years 1 month ago #280083 by krileon
You can edit your plan and under Pricing tab set "Total number of occurrences of regular validity/price (0=unlimitted)" to 50 which will limit the maximum amount of purchases for the plan in total to 50, but as I understand it you want it to only be limited to 50 active users.

To limit it to 50 active users you'll need a CB Query Field to query the _cbsubs_subscriptions database table and query for the count of active subscribers to that plan. Then under the Workflows of your tab you'll need to setup a condition against the Query field (you'll likely need to use "Constant Value or String (CB substitutions can be used)" and substitute in the query field) to ensure it's less than 50. Example query as follows.

SELECT COUNT(*) FROM `#__cbsubs_subscriptions` WHERE `plan_id` = PLAN_ID_HERE AND `status` = '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.

8 years 1 month ago #280105 by solferry
Thanks, will look into that one!

Please Log in to join the conversation.

8 years 1 month ago #280130 by solferry
i am experiencing a bit with the CB Query... and right now I am trying to do a validation for a dropdown menu within the registration profile.

For some reason the AJAX validation does not work.
There is no message when the user is entering something wheter it is returning a row or not a row.

I turned on "query validation", entered a simpel query SELECT * from '#__users' where username = '[value]'
Further modus intern, validation = empty result
Succes message = OK
Error message = Not OK
Ajax validation = Enabled.


Do I need more to enable this validation on the website or should it work just like this?

Please Log in to join the conversation.

8 years 1 month ago #280150 by krileon
Looks like the table is surrounded by single quotes instead of `. This means you've an invalid query and the query it self is erroring, which is why the validation isn't working. Your query should be as follows.

SELECT `id` FROM `#__users` WHERE `username` = '[value]'


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.

8 years 1 month ago - 8 years 1 month ago #280162 by solferry
Hi Kyle,

Thanks for your reply.
I changed the SQL query to what u mentioned, still no reaction on my register page.

also verified my log (<span>/</span>var<span>/</span>log/apache2/error.log) but no errors regarding issues.

Not sure if it helps, but:

I tried to query in phpmyadmin where it runs fine (I had to reply #__ with the table ofcourse).
I did a debugging on mysql to fetch all queries by setting:

general_log_file = <span>/</span>var<span>/</span>log/mysql/mysql.log
general_log = 1

Did a tail on <span>/</span>var<span>/</span>log/mysql/mysql.log... but no query is send when I enter text in a field where I have CB Query on. I did receive a lot of queries when opening the register page.. so the debugging was working.

Any ideas?

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.220 seconds

Facebook Twitter LinkedIn