CB Subs SQL Auto Actions, Unique Event Discount Code, and Auto Discount Code Generation in DT Register

9 years 7 months ago #249477 by jamesmoeller
I'm using CB Subs for my customer membership subscription system and DT Register as my event registration system. I need a way to sell memberships that enable the customer to sign-up (at either a discounted rate or for free) a certain number of events. DT Register has the capability to manage discount codes on event registrations. So what I'd like to do, if this is possible, is use the Auto Actions capability to trigger a script when a customer purchases a membership subscription. That script will then generate a unique customer-specific discount code, and communicate that code to the customer via the "thank-you" email, and finally it will execute an SQL command that will create the new active discount code within DT Register. I'll work with the DTH Development folks on the SQL command that creates the active discount code in there program. But does the rest of this sound like a do-able thing in CB Subs and Auto Actions? If so, any initial advise on how to approach this?

If I'm going about this all wrong or you know of an easier way to accomplish this, feel free to suggest that as well. But, from what I've found, none of the membership subscription systems and event registration systems seem to be all that well integrated to enable what I'd like to do.

Thanks,
Jim

Please Log in to join the conversation.

9 years 7 months ago #249482 by nant

jamesmoeller wrote: I'm using CB Subs for my customer membership subscription system and DT Register as my event registration system. I need a way to sell memberships that enable the customer to sign-up (at either a discounted rate or for free) a certain number of events. DT Register has the capability to manage discount codes on event registrations. So what I'd like to do, if this is possible, is use the Auto Actions capability to trigger a script when a customer purchases a membership subscription. That script will then generate a unique customer-specific discount code, and communicate that code to the customer via the "thank-you" email, and finally it will execute an SQL command that will create the new active discount code within DT Register. I'll work with the DTH Development folks on the SQL command that creates the active discount code in there program. But does the rest of this sound like a do-able thing in CB Subs and Auto Actions? If so, any initial advise on how to approach this?

If I'm going about this all wrong or you know of an easier way to accomplish this, feel free to suggest that as well. But, from what I've found, none of the membership subscription systems and event registration systems seem to be all that well integrated to enable what I'd like to do.

Thanks,
Jim


Sounds doable and I think you have the right concept and approach.

I am not fsmiliar with how DT Register works so I cannot comment on specifics.

You will most likely benefit by looking at the following tutorials:

www.joomlapolis.com/support/tutorials/107-use-cases/18407-purchasing-discount-coupons
www.joomlapolis.com/support/tutorials/107-use-cases/18405-family-plan-membership-part-1

Please Log in to join the conversation.

9 years 6 months ago #249586 by jamesmoeller
O.k. I'm getting much closer on this. I believe I can handle the SQL insert into the DT Register table.

For the unique customer discount code I need to be able to change the text for the email sent out in response to both the initial activation and any manual renewals that's set under the "Presentation" tab of the specific plan, correct?

So what I'd like to do is use a bit of php to pull in the users Joomla userID and combine that with the data & time to create a custom code (which I'll insert into DT Register for the discount code). But then I need do a SQL query to change the text of the emails to include this custom code and communicate it to the customer. Can I insert php in the CBSubs SQL Action? How do I find the table and field names for the emails that need to be modified. Also, I need this SQL Action to trigger before the emails go out. How do I set that timing trigger?

Please Log in to join the conversation.

9 years 6 months ago - 9 years 6 months ago #249637 by jamesmoeller
So just an update here and also another question re triggers for CB Auto Actions.

I've progressed considerably further. To recap what I want to accomplish, I want to have a scrip that executes after someone has signed up for a specific CB Subs subscription membership and in that scrip generate a unique discount code that can be added to the discount code table of the event registration program. Also, to communicate this code to the customer, I want to include the code in the body of the email sent to the subscriber.

First, when I was experimenting with this using the SQL Action available within CB Subs, I found the timing didn’t work. It looks like the activation email, that can be configured within CBSubs under the Plans->Presentation tab, goes out before the CBSubs SQL Activation Action command is executed (that is the SQL command set within SBSubs->Plans->Integrations->SQL Actions, within the “Activation:” SQL command input box under the “SQL Action 1” area). So including an SQL command within that “Activation:” box to change the body of the Activation email will not work because of this timing. The body of the email will be changed by the SQL command, but only after the activation email has gone out. This looks to be true regardless of whether the subscription executes a payment or is free. Even if this technique worked, it wouldn’t be able to execute anything except SQL commands…i.e. no php.

So next what I did was utilize CB Auto Actions to attempt to piece together the full php script and work out the timing (which still isn’t working). I’ve set up a simple Auto Action as Type = code, with the Method (i.e. code execution method) = PHP (eval). To test this I used a simple trigger as “onAfterLogin”, which I know would work. The code below seems to work fine for creating the discount code and for changing the email body text of the for the “Thank You” email. I tried a number of different other triggers to get this to run after a CB Subs subscription has been activated but before the “Thank You” email goes out, but none worked. I’m going to change this so that instead of actually modifying the body of the “Thank You” email, I’m going to modify a custom field that stores the discount code and then use the [cb_anycbfieldname] format to include the field into the reply email. Still I need to be able to update this field after the CB Subs subscription is activated but before the “Thank You” email goes out. How do I set the trigger to get this timing correct?

$user = JFactory::getUser();
$date = JFactory::getDate('now');
//Create the event registration discount code and limit it to 20 characters.
$discountcode = substr($user->username, 0, 9) . '-' . $date->month . $date->day . $date->hour . $date->minute . $date->second;

// Insert php code here that adds the discount code to the event registration program.

//Change Community Builder CB Subs Build reply email text.
$db = JFactory::getDbo();
$query = $db->getQuery(true);
// Fields to update.
$fields = array(
$db->quoteName('thankyouemailbody') . ' = ' . $db->quote('Your coupon code is = ' . $discountcode)
);
// Set the conditions for which records should be updated. “fallbronze” is the alias of one of the plans.
$conditions = array(
$db->quoteName('alias') . ' = ' . $db->quote('fallbronze')
);
$query->update($db->quoteName('#__cbsubs_plans'))->set($fields)->where($conditions);
$db->setQuery($query);
$result = $db->query();

Please Log in to join the conversation.

9 years 6 months ago #249654 by jamesmoeller
So the near-final php code that I’m testing is included below. I’ve changed the previous code to update a custom field, representing the customer’s unique discount code, which then gets included in the customers activation email via [cb_anycbfieldname].

Problem #1: I have had nearly no success in figuring out how to trigger this php code with CB Auto Actions off a CB Sub plan activation so that the custom field can be updated before the “thank-you” email goes out. This code generally works when I trigger it from something like “user login”, but I’d like it to trigger it when a new CB Subs plan is activated. I’ve gone through many forum posts and tried many different settings combinations….with no result. It mostly just doesn’t trigger. How do I trigger this at a point in the workflow where the customer’s environment variables are all accurate and usable by my php code?

Problem #2: I also need to know the specific CB Subs plan (i.e. plan id or alias) that was selected so that I can alter the event registration discount code value and incorporate that into the SQL INSERT to set that table entry in the event registration program. Is there a way that the plan IDs are communicated to the php code executed within CB Auto Actions?

No offense, but IMHO, the entire topic of CB Auto Actions is crying out for some more documentation. CB Auto Actions and CB Subs SQL Actions integrations are very cool and powerful features…just need to be explained a bit better.

Thanks,
Jim


<?php
$user = JFactory::getUser();
$date = JFactory::getDate('now');
//Create the unique event registration discount code and limit it to 20 characters.
$discountcode = substr($user->username, 0, 9) . '-' . $date->month . $date->day . $date->hour. $date->minute . $date->second;

// Include code here that INSERTS a record into the event registration discount code table.

//Change Community Builder custom field that shows the current discount code.
$db = JFactory::getDbo();
$query = $db->getQuery(true);
// Fields to update.
$fields = array(
$db->quoteName('cb_discountcodes') . ' = ' . $db->quote($discountcode)
);
// Conditions for which records should be updated.
$conditions = array(
$db->quoteName('user_id') . ' = ' . $db->quote($user->id)
);
$query->update($db->quoteName('#__comprofiler'))->set($fields)->where($conditions);
$db->setQuery($query);
$result = $db->query();
?>

Please Log in to join the conversation.

9 years 6 months ago #249687 by krileon

Problem #1: I have had nearly no success in figuring out how to trigger this php code with CB Auto Actions off a CB Sub plan activation so that the custom field can be updated before the “thank-you” email goes out. This code generally works when I trigger it from something like “user login”, but I’d like it to trigger it when a new CB Subs plan is activated. I’ve gone through many forum posts and tried many different settings combinations….with no result. It mostly just doesn’t trigger. How do I trigger this at a point in the workflow where the customer’s environment variables are all accurate and usable by my php code?

To act on CBSubs subscription activation/deactivation you can use the below trigger and conditionals.

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

Plan Expired
Triggers: onCPayUserStateChange
User: Automatic
Access: Everybody
Conditional 1: [var3] Equal To PLAN_ID_HERE
Conditional 2: [var2] Equal To X

Problem #2: I also need to know the specific CB Subs plan (i.e. plan id or alias) that was selected so that I can alter the event registration discount code value and incorporate that into the SQL INSERT to set that table entry in the event registration program. Is there a way that the plan IDs are communicated to the php code executed within CB Auto Actions?

If you use the above trigger then [var3] is the Plan ID. What variables are available depend entirely on what trigger is used. You can see a list of triggers and their variables in the below tutorial.

www.joomlapolis.com/support/tutorials/120-api-usage/18358-using-cb-triggers

No offense, but IMHO, the entire topic of CB Auto Actions is crying out for some more documentation. CB Auto Actions and CB Subs SQL Actions integrations are very cool and powerful features…just need to be explained a bit better.

We'll be working on improving documentation after CB 2.0 goes Stable. Currently we've several examples which you can find below in addition to the trigger list above.

www.joomlapolis.com/support/tutorials/107-use-cases

Please understand that even with documentation more complex usages such as yours will likely still not be covered as your usage involves a lot of custom coding using the Code action, which requires existing coding knowledge to fully utilize. Many of the other actions are just a matter of selecting values.


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

Facebook Twitter LinkedIn