UDT to allow registered FEUsers subscribe to paid content
Posted: Sun Jan 08, 2012 8:35 pm
Hi all,
i've been working on this project where my client desired a free registration with the ability to subscribe to a paid package. This couldn't be done with the SelfReg module so i started tweaking the code to allow it. This worked fine but was a bit buggy and i didn't have time to do extensive testing.
Later i realised the SelfReg module isn't needed for this problem so i created a product using CGeCommerce suite with the paypal-gateway and wrote this UDT. You can add this UDT to your gatewaycomplete template in Orders (working on getting it to work with events but this gives some strange errors at this moment). It has the ability to select multiple groups to subscribe/unsubscribe too although the unsubscribe is optional. The audit string is in dutch but feel free to change that.
I hope this is off some use to people here since i saw a lot of questions regarding this subject.
i've been working on this project where my client desired a free registration with the ability to subscribe to a paid package. This couldn't be done with the SelfReg module so i started tweaking the code to allow it. This worked fine but was a bit buggy and i didn't have time to do extensive testing.
Later i realised the SelfReg module isn't needed for this problem so i created a product using CGeCommerce suite with the paypal-gateway and wrote this UDT. You can add this UDT to your gatewaycomplete template in Orders (working on getting it to work with events but this gives some strange errors at this moment). It has the ability to select multiple groups to subscribe/unsubscribe too although the unsubscribe is optional. The audit string is in dutch but feel free to change that.
I hope this is off some use to people here since i saw a lot of questions regarding this subject.
Code: Select all
/* UDT to link Orders and FEU module allowing users to subscribe to paid packages
This version works by putting {Order_to_FEU} in your gatewaycomplete template in Orders
The commented lines with TODO are for implementation in events
UDT Name: Order_to_FEU
Author: Sjoerd Adema
Version: 08012012 */
// Set groups to subsribe too, seperate them with "," //
$subscribe = "betaald";
// Set groups to unsubscribe too, seperate them with "," (optional) //
$unsubscribe = "niet betaald";
// Create handlers //
$gCms = cmsms();
$feu = cms_utils::get_module('FrontEndUsers');
// TODO => $orders = cms_utils::get_module('Orders');
$smarty = $gCms->GetSmarty();
// Create order object //
// TODO => $order_obj = orders_ops::load_by_id( $params['order_id']);
$order_obj = $smarty->get_template_vars('order_obj');
// Get userid //
$uid = $order_obj->get_feu_user();
// Create the sub/unsub arrays //
$subArray = explode(",", $subscribe);
if($unsubscribe != "") {
$unsubArray = explode(",", $unsubscribe);
}
// Check if the order is paid/succesfull //
if($order_obj->get_status() == "paid" || $order_obj->get_status() == "succes") {
// Loop the groups //
foreach($subArray as $group) {
if($feu->AssignUserToGroup($uid,$feu->GetGroupID($group))) {
// Everything works //
continue;
}
else {
$errorAdd = TRUE;
}
}
// Check if there are groups to unsubscribe from //
if(isset($unsubArray)) {
foreach($unsubArray as $group) {
if($feu->RemoveUserFromGroup($uid,$feu->GetGroupID($group))) {
// Everything works //
continue;
}
else {
$errorRemove = TRUE;
}
}
}
// Audit to admin log //
if($errorAdd == FALSE && $errorRemove == FALSE) {
// No errors //
$feu->Audit($temp_uid, $feu->GetName(), sprintf($feu->GetEmail($uid).' toegevoegd aan betaalde gebruikers in FrontEndUsers'));
}
else {
// Audit to admin log //
$feu->Audit($temp_uid, $feu->GetName(), sprintf($feu->GetEmail($uid).' niet toegevoegd aan betaalde gebruikers in FrontEndUsers maar wel betaald'));
}
}