/*
* Create a new cart
*
+ * Also checks to see if the user is a logged-in registration user (has account entry).
+ * If so, the user's account is set as the requesting account of the cart.
+ *
* A new cart consists of only one reg_request record
*
* @return array Array of request and all associated information or false
public function createRegistrationCart()
{
+ $account = 0;
+
+ // If there's a logged in registrations user
+ if (isset($_SESSION) && isset($_SESSION['LoginAccount']) && is_array($_SESSION['LoginAccount']) && isset($_SESSION['LoginAccount']['id'])) {
+ $account = ($_SESSION['LoginAccount']['id'] -0);
+ }
+
$res = $this->wpdb->insert(
GLM_MEMBERS_REGISTRATIONS_PLUGIN_DB_PREFIX . 'reg_request',
array(
- 'account' => 0,
+ 'account' => $account,
'validated' => false,
'user_trace_info' => $_SERVER["REMOTE_ADDR"]." - ".date("m/d/Y H:i:s")
),
$totalCharges = 0;
$totalDiscounts = 0;
$grandTotal = 0;
+ $haveEvents = false;
// If we have a cart and a good request array
if ($this->cart && is_array($this->cart['request'])) {
$eventRegistrants = 0;
$eventCharges = 0;
$eventDiscounts = 0;
+ $removeEvent = false;
+ $haveClasses = false;
- // Assume this event is OK
$this->cart['events'][$eventKey]['removed'] = false;
// Update reg_time entries for current availability and get the event data;
$regEvent = $RegEvent->checkEventTimes($event['id']);
- // Check if Event exists in Events add-on and is active in registrations or if doing admin (admin_active)
- $regEvent = $RegEvent->getEntry($event['reg_event']);
- if (!$regEvent) {
- $this->cart['messages'][] = 'Event in cart is not currently available for registration.';
- $this->cart['events'][$eventKey]['removed'] = true;
- $this->cart['blockCheckout'] = true;
- }
/*
* Classes (levels) Processing
*/
// If we don't have classes for this event
- if (!is_array($event['classes']) || count($event['classes']) == 0 ) {
- $this->cart['messages'][] = 'Event '.$event['event_name'].' has no levels.';
- $this->cart['events'][$eventKey]['removed'] = true;
- $this->cart['blockCheckout'] = true;
- } else {
+ if (is_array($event['classes']) && count($event['classes']) > 0 ) {
// Loop through all classes (levels) for this event
foreach ($event['classes'] as $classKey => $class) {
$classRegistrants = 0;
$classCharges = 0;
$classDiscounts = 0;
+ $removeClass = false;
+ $haveRates = false;
$this->cart['events'][$eventKey]['classes'][$classKey]['removed'] = false;
* Rates Processing
*/
- // If we don't have rates for this class
- if (!is_array($class['rates']) || count($class['rates']) == 0 ) {
- $this->cart['messages'][] = 'Class '.$class['class_name'].' has no rates.';
- $this->cart['events'][$eventKey]['classes'][$classKey]['removed'] = true;
- $this->cart['blockCheckout'] = true;
- } else {
+ // If we have rates for this class
+ if (is_array($class['rates']) && count($class['rates']) > 0 ) {
// loop through all rates
foreach ($class['rates'] as $rateKey => $rate) {
$rateBaseCharge = 0;
$rateRegistrantCharges = 0;
$rateDiscounts = 0;
+ $removeRate = false;
+ $haveRegistrants = false;
$this->cart['events'][$eventKey]['classes'][$classKey]['rates'][$rateKey]['removed'] = false;
// Get rate data
$eventRate = $RequestRate->getEntry($rate['id']);
- if (!$eventRate) {
- $this->cart['message'][] = 'Event rate '.$rate['rage_name'].' is no longer listed - Removed registrants for this rate.';
- $this->cart['events'][$eventKey]['classes'][$classKey]['rates'][$rateKey]['removed'] = true;
- } else {
+ if ($eventRate) {
/*
* Registrants Processing
*/
- // If we don't have registrants for this class
- if (!is_array($rate['registrants']) || count($rate['registrants']) == 0 ) {
- $this->cart['messages'][] = 'Rate '.$rate['rate_name'].' has no registrants.';
- $this->cart['blockCheckout'] = true;
- } else {
+ // If we have registrants for this class
+ if (is_array($rate['registrants']) && count($rate['registrants']) > 0 ) {
// loop through all Registrants
foreach ($rate['registrants'] as $registrantKey => $registrant) {
- $registrantCharges = 0;
- $registrantDiscounts = 0;
+ $registrantCharges = 0;
+ $registrantDiscounts = 0;
+ $removeRegistrant = false;
$this->cart['events'][$eventKey]['classes'][$classKey]['rates'][$rateKey]['registrants'][$registrantKey]['removed'] = false;
- // Check the if registrant still has a time slot hold
+ // Check the if registrant still has a time slot hold or can get one
// if () {
// } else {
- // $this->cart['events'][$eventKey]['classes'][$classKey]['rates'][$rateKey]['registrants'][$registrantKey]['removed'] = true;
-
+ // $removeRegistrant = true;
// }
// If this registrant is flagged for removal from cart
- if ($this->cart['events'][$eventKey]['classes'][$classKey]['rates'][$rateKey]['registrants'][$registrantKey]['removed']) {
+ if ($removeRegistrant) {
// *** remove registrant from cart in Database
+ $this->cart['message'][] = 'Registrant '.$registrant['fname'].' '.$registrant['fname'].' was removed from cart due to lack of availabile space.';
+ $this->cart['events'][$eventKey]['classes'][$classKey]['rates'][$rateKey]['registrants'][$registrantKey]['removed'] = true;
+ $this->cart['blockCheckout'] = true;
+
// Otherwise add registrant to totals
} else {
+ $haveRegistrants = true;
+
// Add registrant to totals
if ($rateRegistrants == 0) {
$rateBaseCharge = $rate['base_rate'];
$rateRegistrantCharges += $registrantCharges;
$rateDiscounts += $registrantDiscounts;
- }
+ // Save totals for this registrant
+ $this->cart['events'][$eventKey]['classes'][$classKey]['rates'][$rateKey]['registrants'][$registrantKey]['registrantRate'] = $registrantCharges;
+ $this->cart['events'][$eventKey]['classes'][$classKey]['rates'][$rateKey]['registrants'][$registrantKey]['registrantDiscounts'] = $registrantDiscounts;
- // Save totals for this registrant
- $this->cart['events'][$eventKey]['classes'][$classKey]['rates'][$rateKey]['registrants'][$registrantKey]['registrantRate'] = $registrantCharges;
- $this->cart['events'][$eventKey]['classes'][$classKey]['rates'][$rateKey]['registrants'][$registrantKey]['registrantDiscounts'] = $registrantDiscounts;
+ }
} // Each registrant
} // Have registrants
+ // If we don't have registrants
+ if (!$haveRegistrants) {
+ $this->cart['messages'][] = 'Rate '.$rate['rate_name'].' has no registrants.';
+ $removeRate = true;
+ }
+
+
+ // Dont have rate
+ } else {
+ $removeRate = true;
+ }
+
+ if ($removeRate) {
+
+// Remove rate from cart in database
+ $this->cart['message'][] = 'Rate '.$rate['rate_name'].' was removed from cart.';
+ $this->cart['events'][$eventKey]['classes'][$classKey]['rates'][$rateKey]['removed'] = true;
+ $this->cart['blockCheckout'] = true;
+
+ } else {
+
+ $haveRates = true;
+
// Save totals for this rate
$this->cart['events'][$eventKey]['classes'][$classKey]['rates'][$rateKey]['rateRegistrants'] = $rateRegistrants;
$this->cart['events'][$eventKey]['classes'][$classKey]['rates'][$rateKey]['rateBaseCharge'] = $rateBaseCharge;
$classCharges += ( $rateBaseCharge + $rateRegistrantCharges);
$classDiscounts += $rateDiscounts;
- // If rate has been flagged for removal from cart, delete it in the database
- if ($this->cart['events'][$eventKey]['classes'][$classKey]['rates'][$rateKey]['removed']) {
-// *** remove rate from cart in Database
- }
-
-
- } // Have rate
+ }
} // Each Rate
} // Have rates
- // Save totals for this class (level)
- $this->cart['events'][$eventKey]['classes'][$classKey]['classRegistrants'] = $classRegistrants;
- $this->cart['events'][$eventKey]['classes'][$classKey]['classCharges'] = $classCharges;
- $this->cart['events'][$eventKey]['classes'][$classKey]['classDiscounts'] = $classDiscounts;
-
- // Add totals to event
- $eventRegistrants += $classRegistrants;
- $eventCharges += $classCharges;
- $eventDiscounts += $classDiscounts;
+ // If we don't have rates
+ if (!$haveRates) {
+ $this->cart['messages'][] = 'Class '.$class['class_name'].' has no rates.';
+ $removeClass = true;
+ }
// If class has been flagged for removal from cart, delete it from cart in database
- if ($this->cart['events'][$eventKey]['classes'][$classKey]['removed']) {
+ if ($removeClass) {
+
+ $this->cart['message'][] = 'Class '.$class['class_name'].' was removed from cart.';
+ $this->cart['events'][$eventKey]['classes'][$classKey]['removed'] = true;
+ $this->cart['blockCheckout'] = true;
+
// *** remove class from cart in Database
+
+ } else {
+
+ $haveClasses = true;
+
+ // Save totals for this class (level)
+ $this->cart['events'][$eventKey]['classes'][$classKey]['classRegistrants'] = $classRegistrants;
+ $this->cart['events'][$eventKey]['classes'][$classKey]['classCharges'] = $classCharges;
+ $this->cart['events'][$eventKey]['classes'][$classKey]['classDiscounts'] = $classDiscounts;
+
+ // Add totals to event
+ $eventRegistrants += $classRegistrants;
+ $eventCharges += $classCharges;
+ $eventDiscounts += $classDiscounts;
+
}
} // Each class
} // Have Classes
- // Save totals for this event
- $this->cart['events'][$eventKey]['eventRegistrants'] = $eventRegistrants;
- $this->cart['events'][$eventKey]['eventCharges'] = $eventCharges;
- $this->cart['events'][$eventKey]['eventDiscounts'] = $eventDiscounts;
+ // If we don't have classes
+ if (!$haveClasses) {
+ $this->cart['messages'][] = 'Event '.$event['event_name'].' has no classes.';
+ $removeEvent = true;
+ }
+
+ // If has been flagged for removal from cart, delete it from cart in database
+ if ($removeEvent) {
+
+ $this->cart['message'][] = 'Event '.$event['event_name'].' was removed from cart.';
+ $this->cart['events'][$eventKey]['removed'] = true;
+ $this->cart['blockCheckout'] = true;
+
+// *** remove event from cart in Database
+
+ } else {
+
+ $haveEvents = true;
- // Add totals to request
- $totalRegistrants += $eventRegistrants;
- $totalCharges += $eventCharges;
- $totalDiscounts += $eventDiscounts;
+ // Save totals for this event
+ $this->cart['events'][$eventKey]['eventRegistrants'] = $eventRegistrants;
+ $this->cart['events'][$eventKey]['eventCharges'] = $eventCharges;
+ $this->cart['events'][$eventKey]['eventDiscounts'] = $eventDiscounts;
+
+ // Add totals to request
+ $totalRegistrants += $eventRegistrants;
+ $totalCharges += $eventCharges;
+ $totalDiscounts += $eventDiscounts;
- // If event has been flagged for removal from cart, delete it from cart in database
- if ($this->cart['events'][$eventKey]['removed']) {
-//*** remove event from cart in Database
}
} // Each event
} // Have events
- // Save totals for this request
- $this->cart['totalRegistrants'] = $totalRegistrants;
- $this->cart['totalCharges'] = $totalCharges;
- $this->cart['totalDiscounts'] = $totalDiscounts;
+ } // have request
+
+ $this->cart['haveEvents'] = $haveEvents;
- // Update request last_update timestamp
-// *** update cart last_update time
+ // Save totals for this request
+ $this->cart['totalRegistrants'] = $totalRegistrants;
+ $this->cart['totalCharges'] = $totalCharges;
+ $this->cart['totalDiscounts'] = $totalDiscounts;
- } // have request
+ // Update request last_update timestamp
+// *** update cart last_update time
// Check if Event Time exists in Events add-on