Updated checkRegistrationRequest() in regCartSupport.php to better handle removal...
authorChuck Scott <cscott@gaslightmedia.com>
Fri, 20 Oct 2017 14:07:40 +0000 (10:07 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Fri, 20 Oct 2017 14:07:40 +0000 (10:07 -0400)
This would be like classes without rate entires.
Enhanced appearance of links between pages and added more specific user instructions.

classes/regCartSupport.php
models/front/registrations/registration.php
views/front/registrations/registration.html

index 3546578..f466ad0 100644 (file)
@@ -83,6 +83,9 @@ class GlmRegCartSupport
     /*
      * 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
@@ -91,10 +94,17 @@ class GlmRegCartSupport
     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")
             ),
@@ -310,6 +320,7 @@ class GlmRegCartSupport
         $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'])) {
@@ -335,31 +346,21 @@ class GlmRegCartSupport
                     $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) {
@@ -367,6 +368,8 @@ class GlmRegCartSupport
                             $classRegistrants   = 0;
                             $classCharges       = 0;
                             $classDiscounts     = 0;
+                            $removeClass        = false;
+                            $haveRates          = false;
 
                             $this->cart['events'][$eventKey]['classes'][$classKey]['removed'] = false;
 
@@ -374,12 +377,8 @@ class GlmRegCartSupport
                              * 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) {
@@ -388,50 +387,52 @@ class GlmRegCartSupport
                                     $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'];
@@ -444,16 +445,39 @@ class GlmRegCartSupport
                                                     $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;
@@ -466,65 +490,93 @@ class GlmRegCartSupport
                                         $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
 
index 994c2c0..c218d3a 100644 (file)
             'regJSON'           => json_encode( $registrants, JSON_NUMERIC_CHECK ),
             'regUrl'            => GLM_MEMBERS_REGISTRATIONS_SITE_BASE_URL.$this->config['settings']['canonical_reg_page'].'/',
             'loggedIn'          => ( isset( $_SESSION['LoginAccount'] ) ) ? $_SESSION['LoginAccount']: false,
+            'assetUrl'          => GLM_MEMBERS_REGISTRATIONS_PLUGIN_ASSETS_URL
         );
 
         // Return status, any suggested view, and any data to controller
index aa4f73b..d3d766c 100644 (file)
@@ -84,7 +84,9 @@
         </div>
     </div>
     <div class="glm-reg-submit">
-        <input id="glm-reg-cart-continue" type="submit" value="Continue" />
+        <div class="glm-reg-warning">You have not yet submitted your registration! <img src="{/literal}{$assetUrl}{literal}/fingerRightRed.svg" style="height: 2em;">
+            <input id="glm-reg-cart-continue" type="submit" value="Continue" />
+        </div>
     </div>
 </script>
 {/literal}