Donation Balance

9 years 6 months ago #250871 by hac
Donation Balance was created by hac
Hi,

I have a cb integer field called cb_donationbalance. I want to keep a balance of all donations that the user has made to date.

So, when a user makes a donation, I want to add the new donation amount to the value that is currently in the cb_donationbalance field.

What I need help with is setting up the auto action conditions to do this.

What I have so far is:
Type: Field
Trigger: onCPayUserStateChange
User: Automatic
Access: Everybody
Conditional:
[var3] Equal to 8 <- this is the id of my Donation plan
[var2] Equal A <- not sure if A is the right status for a new donation
Field Action:
Field: cb_donationbalance
Operator: Add
Value: [] <- don't know what to put in here to get the donation amount

Thank you for the help.

Joomla 3.3.6
CB 1.9.1
CB Subs 3.0.0

Please Log in to join the conversation.

9 years 6 months ago #250981 by krileon
Replied by krileon on topic Donation Balance
That trigger is primarily for subscription status change and the basket info is only available through an API call so can't be substituted in. For the usage you're wanting I suggest a CB Query Field with the below query. This should pull all the users donations and display them as a field on their profile dynamically so you don't need to worry about a field being up to date, etc..

SELECT SUM( `amount` )
FROM `#__cbsubs_donations`
WHERE `status` = 'A'
AND `user_id` = '[user_id]'

That'll add together all the donations the user has made (regardless of the donation plan) that are active (paid). You can also filter it down to only add together specific donation plans with the below usage.

SELECT SUM( `amount` )
FROM `#__cbsubs_donations`
WHERE `status` = 'A'
AND `user_id` = '[user_id]'
AND `plan_id` = PLAN_ID_HERE


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.
The following user(s) said Thank You: nant

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.470 seconds